MessageHandler.c 827 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknown key
  21. //===============================
  22. static char unknownkey[10][36] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static int gunTotalNumber = 0;
  28. static uint8_t gunType[4] = {0};
  29. //===============================
  30. // Local List Version
  31. //===============================
  32. static int locallistVersion=0;
  33. static char idTagAuthorization[32] = {0};
  34. //===============================
  35. // OCPP sign variable
  36. //===============================
  37. static int server_sign = FALSE;
  38. int server_pending = FALSE;
  39. static int BootNotificationInterval = 0;
  40. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  41. //===============================
  42. // OCPP auth variable
  43. //===============================
  44. static int authorizeRetryTimes = 0; //number of Retry times
  45. //===============================
  46. // OCPP other variables
  47. //===============================
  48. static int HeartBeatWaitTime = 10;
  49. static int FirstHeartBeat = 0;
  50. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  51. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  52. static char CurrentChargingProfileScheduleStr[30] = {0};
  53. //========================================
  54. // OCPP status/previous related variables
  55. //========================================
  56. static int GunStatusInterval = 10;
  57. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  58. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  59. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  60. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  61. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  62. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  63. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  64. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  65. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  66. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  67. static int TransactionMessageAttemptsValue = 0;
  68. static int TransactionMessageRetryIntervalValue = 0;
  69. static int TempMeterValueInterval = 0;
  70. static struct OCPPAuthLocalElemet
  71. {
  72. int listVersionInt;
  73. char idTagstr[21];
  74. char parentIdTag[21];
  75. char expiryDate[36];
  76. char idTagstatus[16];
  77. }idTagQuery;
  78. //=============================================
  79. // OCPP HeartBeat Response Not Receive Counts
  80. //============================================
  81. static int HeartBeatWithNOResponse = 0;
  82. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  83. extern sqlite3 *db;
  84. int TransactionMessageAttemptsGet(void);
  85. int TransactionMessageRetryIntervalGet(void);
  86. int GetOcppConnStatus(void);
  87. void SetOcppConnStatus(uint8_t status);
  88. int setKeyValue(char *key, char *value);
  89. void OCPP_get_TableAuthlocalAllData(void);
  90. void processUnkownKey(void);
  91. struct StructOCPPMeterValue
  92. {
  93. unsigned char TimeStamp[28];
  94. struct StructSampledValue SampledValue[10];
  95. };
  96. struct ClientTime
  97. {
  98. unsigned int Heartbeat;
  99. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  100. unsigned int StartTransaction;
  101. unsigned int StopTransaction;
  102. unsigned int MeterValues[CONNECTOR_QUANTITY];
  103. }clientTime;
  104. typedef union
  105. {
  106. //Operations Initiated by Central System
  107. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  108. struct
  109. {
  110. //CsMsgValue[0]
  111. unsigned char StatusNotificationReq:1; //bit 0,
  112. unsigned char StatusNotificationConf:1; //bit 1,
  113. unsigned char TriggerMeterValue:1; //bit 2,
  114. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  115. unsigned char isOnCharging:1; //bit 4,
  116. unsigned char :3; //bit5~7
  117. }bits[CONNECTOR_QUANTITY];
  118. }CpinitiateMsg;
  119. CpinitiateMsg cpinitateMsg;
  120. //GetConfiguration Array
  121. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  122. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  123. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  124. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  125. #if 0
  126. static char *ChargePointErrorCodeStr[] = {
  127. MACROSTR(ConnectorLockFailure),
  128. MACROSTR(EVCommunicationError),
  129. MACROSTR(GroundFailure),
  130. MACROSTR(HighTemperature),
  131. MACROSTR(InternalError),
  132. MACROSTR(LocalListConflict),
  133. MACROSTR(NoError),
  134. MACROSTR(OtherError),
  135. MACROSTR(OverCurrentFailure),
  136. MACROSTR(OverVoltage),
  137. MACROSTR(PowerMeterFailure),
  138. MACROSTR(PowerSwitchFailure),
  139. MACROSTR(ReaderFailure),
  140. MACROSTR(ResetFailure),
  141. MACROSTR(UnderVoltage),
  142. MACROSTR(WeakSignal)
  143. };
  144. #endif
  145. static char * ChargePointStatusStr[] = {
  146. MACROSTR(Available),
  147. MACROSTR(Preparing),
  148. MACROSTR(Charging),
  149. MACROSTR(SuspendedEVSE),
  150. MACROSTR(SuspendedEV),
  151. MACROSTR(Finishing),
  152. MACROSTR(Reserved),
  153. MACROSTR(Unavailable),
  154. MACROSTR(Faulted)
  155. };
  156. static char *RegistrationStatusStr[] = {
  157. MACROSTR(Accepted),
  158. MACROSTR(Pending),
  159. MACROSTR(Rejected)
  160. };
  161. static char *AvailabilityTypeStr[] = {
  162. MACROSTR(Inoperative),
  163. MACROSTR(Operative)
  164. };
  165. static char *AvailabilityStatusStr[] = {
  166. MACROSTR(Accepted),
  167. MACROSTR(Rejected),
  168. MACROSTR(Scheduled)
  169. };
  170. static char *ConfigurationStatusStr[] = {
  171. MACROSTR(Accepted),
  172. MACROSTR(Rejected),
  173. MACROSTR(RebootRequired),
  174. MACROSTR(NotSupported)
  175. };
  176. static char *ClearCacheStatusStr[] = {
  177. MACROSTR(Accepted),
  178. MACROSTR(Rejected)
  179. };
  180. static char *ChargingProfilePurposeTypeStr[] = {
  181. MACROSTR(ChargePointMaxProfile),
  182. MACROSTR(TxDefaultProfile),
  183. MACROSTR(TxProfile)
  184. };
  185. static char *ChargingProfileStatusStr[] = {
  186. MACROSTR(Accepted),
  187. MACROSTR(Rejected),
  188. MACROSTR(NotSupported)
  189. };
  190. static char *ClearChargingProfileStatusStr[] = {
  191. MACROSTR(Accepted),
  192. MACROSTR(Unknown)
  193. };
  194. static char *GetCompositeScheduleStatusStr[] = {
  195. MACROSTR(Accepted),
  196. MACROSTR(Rejected)
  197. };
  198. static char *UpdateTypeStr[] = {
  199. MACROSTR(Differential),
  200. MACROSTR(Full)
  201. };
  202. static char *UpdateStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Failed),
  205. MACROSTR(NotSupported),
  206. MACROSTR(VersionMismatch)
  207. };
  208. static char *RemoteStartStopStatusStr[] = {
  209. MACROSTR(Accepted),
  210. MACROSTR(Rejected)
  211. };
  212. static char *ReservationStatusStr[] = {
  213. MACROSTR(Accepted),
  214. MACROSTR(Faulted),
  215. MACROSTR(Occupied),
  216. MACROSTR(Rejected),
  217. MACROSTR(Unavailable)
  218. };
  219. static char *ResetTypeStr[] = {
  220. MACROSTR(Hard),
  221. MACROSTR(Soft)
  222. };
  223. static char *ResetStatusStr[] = {
  224. MACROSTR(Accepted),
  225. MACROSTR(Rejected)
  226. };
  227. static char * DiagnosticsStatusStr[] = {
  228. MACROSTR(Idle),
  229. MACROSTR(Uploaded),
  230. MACROSTR(UploadFailed),
  231. MACROSTR(Uploading)
  232. };
  233. static char * FirmwareStatusStr[] = {
  234. MACROSTR(Downloaded),
  235. MACROSTR(DownloadFailed),
  236. MACROSTR(Downloading),
  237. MACROSTR(Idle),
  238. MACROSTR(InstallationFailed),
  239. MACROSTR(Installing),
  240. MACROSTR(Installed)
  241. };
  242. static char * MessageTriggerStr[] = {
  243. MACROSTR(BootNotification),
  244. MACROSTR(DiagnosticsStatusNotification),
  245. MACROSTR(FirmwareStatusNotification),
  246. MACROSTR(Heartbeat),
  247. MACROSTR(MeterValues),
  248. MACROSTR(StatusNotification)
  249. };
  250. static char * TriggerMessageStatusStr[] = {
  251. MACROSTR(Accepted),
  252. MACROSTR(Rejected),
  253. MACROSTR(NotImplemented)
  254. };
  255. static char * UnlockStatusStr[] = {
  256. MACROSTR(Unlocked),
  257. MACROSTR(UnlockFailed),
  258. MACROSTR(NotSupported)
  259. };
  260. #if 0
  261. static char * StopTransactionReasonStr[] = {
  262. MACROSTR(EmergencyStop),
  263. MACROSTR(EVDisconnected),
  264. MACROSTR(HardReset),
  265. MACROSTR(Local),
  266. MACROSTR(Other),
  267. MACROSTR(PowerLoss),
  268. MACROSTR(Reboot),
  269. MACROSTR(Remote),
  270. MACROSTR(SoftReset),
  271. MACROSTR(UnlockCommand),
  272. MACROSTR(DeAuthorized)
  273. };
  274. #endif
  275. static char * CancelReservationStatusStr[] = {
  276. MACROSTR(Accepted),
  277. MACROSTR(Rejected)
  278. };
  279. static char * ReadingContextStr[] = {
  280. MACROSTR(Interruption.Begin),
  281. MACROSTR(Interruption.End),
  282. MACROSTR(Other),
  283. MACROSTR(Sample.Clock),
  284. MACROSTR(Sample.Periodic),
  285. MACROSTR(Transaction.Begin),
  286. MACROSTR(Transaction.End),
  287. MACROSTR(Trigger)
  288. };
  289. static char * ValueFormatStr[] = {
  290. MACROSTR(Raw),
  291. MACROSTR(SignedData)
  292. };
  293. static char * MeasurandStr[] = {
  294. MACROSTR(Current.Export),
  295. MACROSTR(Current.Import),
  296. MACROSTR(Current.Offered),
  297. MACROSTR(Energy.Active.Export.Register),
  298. MACROSTR(Energy.Active.Import.Register),
  299. MACROSTR(Energy.Reactive.Export.Register),
  300. MACROSTR(Energy.Reactive.Import.Register),
  301. MACROSTR(Energy.Active.Export.Interval),
  302. MACROSTR(Energy.Active.Import.Interval),
  303. MACROSTR(Energy.Reactive.Export.Interval),
  304. MACROSTR(Energy.Reactive.Import.Interval),
  305. MACROSTR(Frequency),
  306. MACROSTR(Power.Active.Export),
  307. MACROSTR(Power.Active.Import),
  308. MACROSTR(Power.Factor),
  309. MACROSTR(Power.Offered),
  310. MACROSTR(Power.Reactive.ExportMACROSTR),
  311. MACROSTR(Power.Reactive.Import),
  312. MACROSTR(RPM),
  313. MACROSTR(SoC),
  314. MACROSTR(Temperature),
  315. MACROSTR(Voltage)
  316. };
  317. static char * LocationStr[] = {
  318. MACROSTR(Body),
  319. MACROSTR(Cable),
  320. MACROSTR(EV),
  321. MACROSTR(Inlet),
  322. MACROSTR(Outlet)
  323. };
  324. static char * PhaseStr[] = {
  325. MACROSTR(L1),
  326. MACROSTR(L2),
  327. MACROSTR(L3),
  328. MACROSTR(N),
  329. MACROSTR(L1-N),
  330. MACROSTR(L2-N),
  331. MACROSTR(L3-N),
  332. MACROSTR(L1-L2),
  333. MACROSTR(L2-L3),
  334. MACROSTR(L3-L1)
  335. };
  336. static char * UnitOfMeasureStr[] = {
  337. MACROSTR(Wh),
  338. MACROSTR(kWh),
  339. MACROSTR(varh),
  340. MACROSTR(kvarh),
  341. MACROSTR(W),
  342. MACROSTR(kW),
  343. MACROSTR(VA),
  344. MACROSTR(kVA),
  345. MACROSTR(var),
  346. MACROSTR(kvar),
  347. MACROSTR(A),
  348. MACROSTR(V),
  349. MACROSTR(Celsius),
  350. MACROSTR(Fahrenheit),
  351. MACROSTR(K),
  352. MACROSTR(Percent)
  353. };
  354. //=========================================
  355. // Save configuration
  356. //=========================================
  357. int runShellCmd(const char*cmd)
  358. {
  359. int result = FAIL;
  360. char buf[256];
  361. FILE *fp;
  362. fp = popen(cmd, "r");
  363. if(fp != NULL)
  364. {
  365. while(fgets(buf, sizeof(buf), fp) != NULL)
  366. {
  367. DEBUG_INFO("%s\n", buf);
  368. }
  369. result = PASS;
  370. }
  371. pclose(fp);
  372. return result;
  373. }
  374. int StoreUsrConfigData(struct SysConfigData *UsrData)
  375. {
  376. int result = PASS;
  377. int fd,wrd;
  378. unsigned int i,Chk;
  379. unsigned char *ptr, *BufTmp;
  380. int MtdBlockSize = 0x300000;
  381. Chk=0;
  382. ptr=(unsigned char *)UsrData;
  383. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  384. {
  385. memset(BufTmp,0,MtdBlockSize);
  386. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  387. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  388. Chk+=*(BufTmp+i);
  389. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  390. // Output configuration to file.
  391. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  392. if (fd < 0)
  393. {
  394. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  395. free(BufTmp);
  396. return 0;
  397. }
  398. wrd=write(fd, BufTmp, MtdBlockSize);
  399. close(fd);
  400. if(wrd<MtdBlockSize)
  401. {
  402. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  403. free(BufTmp);
  404. return 0;
  405. }
  406. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  407. DEBUG_INFO("Erase /dev/mtd10.\n");
  408. runShellCmd("flash_erase /dev/mtd10 0 0");
  409. DEBUG_INFO("Write /dev/mtd10.\n");
  410. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  411. DEBUG_INFO("Erase /dev/mtd11.\n");
  412. runShellCmd("flash_erase /dev/mtd11 0 0");
  413. DEBUG_INFO("Write /dev/mtd11.\n");
  414. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  415. system("rm -f /mnt/EvseConfig.bin");
  416. DEBUG_INFO("EvseConfig write to flash OK\n");
  417. }
  418. else
  419. {
  420. DEBUG_ERROR("alloc BlockSize NG\r\n");
  421. result = FAIL;
  422. }
  423. if(BufTmp!=NULL)
  424. free(BufTmp);
  425. return result;
  426. }
  427. //=========================================
  428. // Sqlite3 related function
  429. //=========================================
  430. static int selectSqlCount = 0;
  431. static int callback(void *data, int argc, char **argv, char **azColName){
  432. int i;
  433. //printf("%s: ", (const char*)data);
  434. selectSqlCount = argc;
  435. for(i = 0; i<argc; i++){
  436. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  437. }
  438. //printf("\n");
  439. return 0;
  440. }
  441. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  442. //int i;
  443. //printf("%s:\n", (const char*)data);
  444. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  445. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  446. return 0;
  447. }
  448. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  449. //printf("%s:\n", (const char*)data);
  450. //idTag
  451. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  452. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  453. //parentIdTag
  454. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  455. //expir_date
  456. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  457. //status
  458. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  459. //version
  460. if(columenCount > 5)
  461. idTagQuery.listVersionInt = atoi(columnValue[5]);
  462. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  463. return 0;
  464. }
  465. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  466. {
  467. // localversion = argv[5] ? atoi(argv[5]) : 0;
  468. // printf("localversion=%d\n", localversion);
  469. return 0;
  470. }
  471. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  472. {
  473. for (int i = 0; i < n_columns; i++)
  474. {
  475. DEBUG_INFO("%s\t", col_values[i]);
  476. }
  477. DEBUG_INFO("\n");
  478. return 0;
  479. }
  480. int OCPP_cleanLocalCache()
  481. {
  482. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  483. char *errMsg = 0;
  484. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  485. if (SQLITE_OK != rc)
  486. {
  487. DEBUG_INFO("SQL error: %s\n",errMsg);
  488. return FALSE;
  489. }
  490. return TRUE;
  491. }
  492. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  493. {
  494. int isSuccess = TRUE;
  495. int ret = 0;
  496. //const char* data = "Callback function called";
  497. char sql[300];
  498. char zErrMsg[200];
  499. memset(sql, 0, 300);
  500. memset(zErrMsg, 0, 200);
  501. 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);
  502. //* Execute SQL statement */
  503. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  504. if( ret != SQLITE_OK )
  505. {
  506. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  507. isSuccess = FALSE;
  508. }
  509. return isSuccess;
  510. }
  511. void OCPP_getIdTagFromLocalCache(char idTag[])
  512. {
  513. int rc = 0;
  514. char sql[100];
  515. char zErrMsg[100];
  516. memset(sql, 0, 100);
  517. memset(zErrMsg, 0, 100);
  518. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  519. memset(&idTagQuery, 0, sizeof(idTagQuery));
  520. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  521. /* Execute SQL statement */
  522. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  523. if( rc != SQLITE_OK )
  524. {
  525. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  526. }
  527. }
  528. void OCPP_getListVerion()
  529. {
  530. int rc = 0;
  531. // const char* data = "Callback function called";
  532. char sql[100];
  533. char zErrMsg[100];
  534. memset(sql, 0, 100);
  535. memset(zErrMsg, 0, 100);
  536. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  537. /* Execute SQL statement */
  538. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  539. if( rc != SQLITE_OK )
  540. {
  541. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  542. }
  543. }
  544. void OCPP_get_TableAuthlocalAllData(void)
  545. {
  546. int rc = 0;
  547. char sql[100];
  548. char zErrMsg[100];
  549. memset(sql, 0, 100);
  550. memset(zErrMsg, 0, 100);
  551. sprintf(sql,"select * from ocpp_auth_local ");
  552. /* Execute SQL statement */
  553. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  554. if( rc != SQLITE_OK )
  555. {
  556. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  557. }
  558. //return ver;
  559. }
  560. int OCPP_cleanLocalList()
  561. {
  562. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  563. char *errMsg = 0;
  564. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  565. if (SQLITE_OK != rc)
  566. {
  567. DEBUG_INFO("%s\n",errMsg);
  568. return FALSE;
  569. }
  570. return TRUE;
  571. }
  572. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  573. {
  574. int isSuccess = FALSE;
  575. int ret = 0;
  576. //const char* data = "Callback function called";
  577. char sql[300];
  578. char zErrMsg[200];
  579. memset(sql, 0, 300);
  580. memset(zErrMsg, 0, 200);
  581. 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);
  582. //* Execute SQL statement */
  583. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  584. if( ret != SQLITE_OK )
  585. {
  586. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  587. return isSuccess;
  588. }
  589. memset(sql, 0, 300);
  590. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  591. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  592. if( ret != SQLITE_OK )
  593. {
  594. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  595. return isSuccess;
  596. }
  597. isSuccess = TRUE;
  598. return isSuccess;
  599. }
  600. void OCPP_getIdTagFromLocalList(char idTag[])
  601. {
  602. int rc = 0;
  603. // const char* data = "Callback function called";
  604. char sql[100];
  605. char zErrMsg[100];
  606. memset(sql, 0, 100);
  607. memset(zErrMsg, 0, 100);
  608. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  609. memset(&idTagQuery, 0, sizeof(idTagQuery));
  610. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  611. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  612. /* Execute SQL statement */
  613. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  614. if( rc != SQLITE_OK )
  615. {
  616. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  617. }
  618. //return ver;
  619. }
  620. void OCPP_deleteIdTagFromLocalList(char idTag[])
  621. {
  622. //int ver = 0;
  623. //int isSuccess = FALSE;
  624. int rc = 0;
  625. char sql[100];
  626. char zErrMsg[100];
  627. memset(sql, 0, 100);
  628. memset(zErrMsg, 0, 100);
  629. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  630. //* Execute SQL statement */
  631. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  632. if( rc != SQLITE_OK )
  633. {
  634. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  635. }
  636. }
  637. int getCurrentYear()
  638. {
  639. int result = 0;
  640. time_t CurrentTime;
  641. struct tm *tm;
  642. CurrentTime = time(NULL);
  643. tm=localtime(&CurrentTime);
  644. result = (tm->tm_year + 1900);
  645. return result;
  646. }
  647. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  648. {
  649. int result = PASS;
  650. char* errMsg = NULL;
  651. char sqlStr[8192];
  652. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  653. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  654. {
  655. result = FAIL;
  656. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  657. }
  658. 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));
  659. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  660. {
  661. result = FAIL;
  662. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  663. }
  664. return result;
  665. }
  666. //==========================================
  667. // Check time passed since today
  668. //==========================================
  669. long long DiffTimebWithNow(struct timeb ST)
  670. {
  671. //return milli-second
  672. struct timeb ET;
  673. long long StartTime,StopTime;
  674. ftime(&ET);
  675. StartTime=(long long)ST.time;
  676. StopTime=(long long)ET.time;
  677. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  678. }
  679. int getTimePassSinceToday(uint8_t gun_index)
  680. {
  681. int result = -1;
  682. static time_t lastTime[4];
  683. time_t t;
  684. struct tm *tmStartToday;
  685. struct timeb tbStartToday;
  686. t=time(NULL);
  687. if(difftime(t, lastTime[gun_index])>0)
  688. {
  689. tmStartToday=localtime(&t);
  690. tmStartToday->tm_hour = 0;
  691. tmStartToday->tm_min = 0;
  692. tmStartToday->tm_sec = 0;
  693. tbStartToday.time = mktime(tmStartToday);
  694. tbStartToday.millitm = 0;
  695. result = DiffTimebWithNow(tbStartToday)/1000;
  696. lastTime[gun_index] = t;
  697. }
  698. return result;
  699. }
  700. void getNowDatetime(uint8_t *data)
  701. {
  702. time_t t = time(NULL);
  703. struct tm tm = *localtime(&t);
  704. 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);
  705. }
  706. int syncDateTimeRTC(uint8_t *data)
  707. {
  708. struct ParsingResult
  709. {
  710. int result;
  711. int scanedElement;
  712. int year;
  713. int month;
  714. int mday;
  715. int hour;
  716. int min;
  717. int sec;
  718. int tz_hour;
  719. int tz_min;
  720. float minSec;
  721. }result;
  722. struct tm tmOrg;
  723. struct tm *tmTarget;
  724. struct timeb tbTarget;
  725. char buf[128];
  726. memset(&result, 0x00, sizeof(struct ParsingResult));
  727. result.result = PASS;
  728. if(strstr((char*)data, ".") != NULL)
  729. {
  730. // Original data with mini second
  731. if(strstr((char*)data, "Z") != NULL)
  732. {
  733. // Original data with Z
  734. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  735. &result.year,
  736. &result.month,
  737. &result.mday,
  738. &result.hour,
  739. &result.min,
  740. &result.sec,
  741. &result.minSec);
  742. }
  743. else
  744. {
  745. // Original data without Z
  746. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  747. &result.year,
  748. &result.month,
  749. &result.mday,
  750. &result.hour,
  751. &result.min,
  752. &result.sec,
  753. &result.minSec,
  754. &result.tz_hour,
  755. &result.tz_min);
  756. }
  757. }
  758. else
  759. {
  760. // Original data without mini second
  761. if(strstr((char*)data, "Z") != NULL)
  762. {
  763. // Original data with Z
  764. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  765. &result.year,
  766. &result.month,
  767. &result.mday,
  768. &result.hour,
  769. &result.min,
  770. &result.sec);
  771. }
  772. else
  773. {
  774. // Original data without Z
  775. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  776. &result.year,
  777. &result.month,
  778. &result.mday,
  779. &result.hour,
  780. &result.min,
  781. &result.sec,
  782. &result.tz_hour,
  783. &result.tz_min);
  784. }
  785. }
  786. tmOrg.tm_year = result.year - 1900;
  787. tmOrg.tm_mon = result.month - 1;
  788. tmOrg.tm_mday = result.mday;
  789. tmOrg.tm_hour = result.hour;
  790. tmOrg.tm_min = result.min;
  791. tmOrg.tm_sec = result.sec;
  792. tmOrg.tm_gmtoff = 0;
  793. tbTarget.time = mktime(&tmOrg);
  794. tbTarget.timezone = 0;
  795. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  796. tmTarget = gmtime(&tbTarget.time);
  797. 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);
  798. //DEBUG_INFO(" org date time: %s\n", data);
  799. //DEBUG_INFO("parse date time: %s\n", buf);
  800. system(buf);
  801. system("/sbin/hwclock -w --systohc");
  802. if(result.scanedElement < 6)
  803. result.result = FAIL;
  804. return result.result;
  805. }
  806. //==========================================
  807. // GetCompositeSchedule logic related function
  808. //==========================================
  809. int DiffTimebSec(struct timeb ST, struct timeb ET)
  810. {
  811. //return milli-second
  812. unsigned int StartTime,StopTime;
  813. StartTime=(unsigned int)ST.time;
  814. StopTime=(unsigned int)ET.time;
  815. return (StopTime-StartTime);
  816. }
  817. int DiffTimebWithNowSec(struct timeb ST)
  818. {
  819. //return milli-second
  820. struct timeb ET;
  821. unsigned int StartTime,StopTime;
  822. ftime(&ET);
  823. StartTime=(unsigned int)ST.time;
  824. StopTime=(unsigned int)ET.time;
  825. return (StopTime-StartTime);
  826. }
  827. int getStartStop(uint8_t *start, uint8_t *stop)
  828. {
  829. int result = -1;
  830. struct tm tmStart;
  831. struct timeb tbStart;
  832. struct tm tmStop;
  833. struct timeb tbStop;
  834. 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) &&
  835. (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))
  836. {
  837. //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);
  838. //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);
  839. tmStart.tm_year -= 1900;
  840. tmStart.tm_mon -= 1;
  841. tbStart.time = mktime(&tmStart);
  842. tbStart.millitm = 0;
  843. tmStop.tm_year -= 1900;
  844. tmStop.tm_mon -= 1;
  845. tbStop.time = mktime(&tmStop);
  846. tbStop.millitm = 0;
  847. result = DiffTimebSec(tbStart, tbStop);
  848. //DEBUG_INFO("getStartStop(): %d\n", result);
  849. }
  850. else
  851. {
  852. DEBUG_WARN("Start or stop date parsing error.\r\n");
  853. }
  854. return result;
  855. }
  856. int isOvertNow(uint8_t *start)
  857. {
  858. int result = NO;
  859. struct tm tmStart;
  860. struct timeb tbStart;
  861. 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))
  862. {
  863. //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);
  864. tmStart.tm_year -= 1900;
  865. tmStart.tm_mon -= 1;
  866. tbStart.time = mktime(&tmStart);
  867. tbStart.millitm = 0;
  868. if(DiffTimebWithNowSec(tbStart) <= 0)
  869. result = NO;
  870. else
  871. result = YES;
  872. }
  873. else
  874. {
  875. DEBUG_WARN("Start date parsing error.\n");
  876. }
  877. return result;
  878. }
  879. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  880. {
  881. int result = -1;
  882. struct tm tmStart;
  883. struct timeb tbStart;
  884. struct tm tmStop;
  885. struct timeb tbStop;
  886. 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) &&
  887. (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))
  888. {
  889. tmStart.tm_year -= 1900;
  890. tmStart.tm_mon -= 1;
  891. tbStart.time = mktime(&tmStart);
  892. tbStart.millitm = 0;
  893. tmStop.tm_year -= 1900;
  894. tmStop.tm_mon -= 1;
  895. tbStop.time = mktime(&tmStop);
  896. tbStop.millitm = 0;
  897. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  898. }
  899. return result;
  900. }
  901. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  902. {
  903. FILE *fp;
  904. char profileFileName[128];
  905. char *line = NULL;
  906. size_t len = 0;
  907. time_t CurrentTime;
  908. struct tm *tmComposite;
  909. struct StructChargingProfile maxProfile;
  910. uint8_t limitMax=0;
  911. int compositePeriodIdx = 0;
  912. CurrentTime = time(NULL);
  913. tmComposite=localtime(&CurrentTime);
  914. 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);
  915. if(isUnitA)
  916. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  917. else
  918. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  919. compositeProfile->ChargingSchedule.Duration = durationReq;
  920. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  921. {
  922. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  923. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  924. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  925. }
  926. compositeProfile->ChargingProfileId = 0;
  927. compositeProfile->StackLevel = 99 ;
  928. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  929. maxProfile.ChargingProfileId = -1;
  930. maxProfile.ChargingSchedule.Duration = -1;
  931. system("rm -f /tmp/*.json");
  932. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  933. // Search max profile
  934. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  935. if((access(profileFileName, F_OK))!=-1)
  936. {
  937. fp = fopen(profileFileName, "r");
  938. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  939. {
  940. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  941. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  942. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  943. }
  944. maxProfile.ChargingProfileId = -1;
  945. maxProfile.StackLevel = -1;
  946. while(getline(&line, &len, fp) != -1)
  947. {
  948. json_object *obj = NULL;
  949. obj = json_tokener_parse(line);
  950. if(is_error(obj))
  951. {
  952. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  953. }
  954. else
  955. {
  956. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  957. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  958. )
  959. {
  960. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  961. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  962. )
  963. {
  964. struct tm tmFrom, tmTo;
  965. struct timeb tbFrom, tbTo;
  966. 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) &&
  967. (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))
  968. {
  969. tmFrom.tm_year -= 1900;
  970. tmFrom.tm_mon -= 1;
  971. tbFrom.time = mktime(&tmFrom);
  972. tmTo.tm_year -= 1900;
  973. tmTo.tm_mon -= 1;
  974. tbTo.time = mktime(&tmTo);
  975. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  976. {
  977. if(maxProfile.ChargingProfileId == -1)
  978. DEBUG_INFO("MaxProfile found.\n");
  979. else
  980. DEBUG_INFO("MaxProfile updated.\n");
  981. // Required item
  982. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  983. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  984. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  985. if(isUnitA)
  986. {
  987. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  988. 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++)
  989. {
  990. 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"));
  991. 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?
  992. 3:
  993. 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")));
  994. 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")));
  995. }
  996. }
  997. else
  998. {
  999. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  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. 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"));
  1003. 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?
  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. 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));
  1007. }
  1008. }
  1009. // Optional item
  1010. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1011. {
  1012. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1013. }
  1014. else
  1015. {
  1016. sprintf((char*)maxProfile.ValidFrom, " ");
  1017. }
  1018. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1019. {
  1020. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1021. }
  1022. else
  1023. {
  1024. sprintf((char*)maxProfile.ValidTo, " ");
  1025. }
  1026. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1027. {
  1028. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1029. }
  1030. else
  1031. {
  1032. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1033. }
  1034. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1035. {
  1036. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1037. }
  1038. else
  1039. {
  1040. maxProfile.TransactionId = -1;
  1041. }
  1042. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1043. {
  1044. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1045. }
  1046. else
  1047. {
  1048. maxProfile.ChargingSchedule.Duration = 86400;
  1049. }
  1050. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1051. {
  1052. 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")));
  1053. }
  1054. else
  1055. {
  1056. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1057. }
  1058. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1059. {
  1060. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1061. }
  1062. else
  1063. {
  1064. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1065. }
  1066. }
  1067. }
  1068. }
  1069. else
  1070. {
  1071. if(maxProfile.ChargingProfileId == -1)
  1072. DEBUG_INFO("MaxProfile found.\n");
  1073. else
  1074. DEBUG_INFO("MaxProfile updated.\n");
  1075. // Required item
  1076. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1077. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1078. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1079. if(isUnitA)
  1080. {
  1081. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1082. 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++)
  1083. {
  1084. 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"));
  1085. 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?
  1086. 3:
  1087. 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")));
  1088. 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")));
  1089. }
  1090. }
  1091. else
  1092. {
  1093. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  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. 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"));
  1097. 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?
  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. 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));
  1101. }
  1102. }
  1103. // Optional item
  1104. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1105. {
  1106. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1107. }
  1108. else
  1109. {
  1110. sprintf((char*)maxProfile.ValidFrom, " ");
  1111. }
  1112. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1113. {
  1114. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1115. }
  1116. else
  1117. {
  1118. sprintf((char*)maxProfile.ValidTo, " ");
  1119. }
  1120. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1121. {
  1122. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1123. }
  1124. else
  1125. {
  1126. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1127. }
  1128. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1129. {
  1130. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1131. }
  1132. else
  1133. {
  1134. maxProfile.TransactionId = -1;
  1135. }
  1136. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1137. {
  1138. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1139. }
  1140. else
  1141. {
  1142. maxProfile.ChargingSchedule.Duration = 86400;
  1143. }
  1144. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1145. {
  1146. 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")));
  1147. }
  1148. else
  1149. {
  1150. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1151. }
  1152. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1153. {
  1154. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1155. }
  1156. else
  1157. {
  1158. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1159. }
  1160. }
  1161. }
  1162. }
  1163. json_object_put(obj);
  1164. }
  1165. fclose(fp);
  1166. /*
  1167. if(maxProfile.ChargingProfileId !=-1)
  1168. {
  1169. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1170. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1171. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1172. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1173. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1174. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1175. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1176. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1177. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1178. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1179. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1180. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1181. {
  1182. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1183. {
  1184. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1185. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1186. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1187. }
  1188. }
  1189. }
  1190. else
  1191. DEBUG_INFO("MaxProfile not found.\n");
  1192. DEBUG_INFO("------------------------------------\n");*/
  1193. }
  1194. if(maxProfile.ChargingProfileId != -1)
  1195. {
  1196. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1197. {
  1198. if(maxProfile.ChargingSchedule.Duration != -1)
  1199. {
  1200. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1201. 0:
  1202. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1203. }
  1204. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1205. {
  1206. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1207. {
  1208. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1209. 0:
  1210. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1211. if(idxPeriod > 0)
  1212. {
  1213. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1214. {
  1215. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1216. }
  1217. }
  1218. }
  1219. }
  1220. }
  1221. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1222. {
  1223. if(maxProfile.ChargingSchedule.Duration != -1)
  1224. {
  1225. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1226. }
  1227. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1228. {
  1229. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1230. {
  1231. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1232. if(idxPeriod > 0)
  1233. {
  1234. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1235. {
  1236. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1237. }
  1238. }
  1239. }
  1240. }
  1241. }
  1242. else
  1243. {
  1244. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1245. {
  1246. if(maxProfile.ChargingSchedule.Duration != -1)
  1247. {
  1248. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1249. 0:
  1250. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1251. }
  1252. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1253. {
  1254. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1255. {
  1256. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1257. 0:
  1258. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1259. if(idxPeriod > 0)
  1260. {
  1261. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1262. {
  1263. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1264. }
  1265. }
  1266. }
  1267. }
  1268. }
  1269. else
  1270. {
  1271. if(maxProfile.ChargingSchedule.Duration != -1)
  1272. {
  1273. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1274. 0:
  1275. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1276. }
  1277. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1278. {
  1279. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1280. {
  1281. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1282. 0:
  1283. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1284. if(idxPeriod > 0)
  1285. {
  1286. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1287. {
  1288. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1289. }
  1290. }
  1291. }
  1292. }
  1293. }
  1294. }
  1295. /*
  1296. DEBUG_INFO("MaxProfile after align.\n");
  1297. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1298. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1299. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1300. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1301. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1302. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1303. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1304. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1305. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1306. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1307. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1308. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1309. {
  1310. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1311. {
  1312. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1313. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1314. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1315. }
  1316. }
  1317. DEBUG_INFO("------------------------------------\n");*/
  1318. }
  1319. // Find each profile period quantity
  1320. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1321. {
  1322. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1323. limitMax = idx+1;
  1324. }
  1325. if(maxProfile.ChargingProfileId != -1)
  1326. {
  1327. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1328. {
  1329. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1330. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1331. (maxProfile.ChargingSchedule.Duration > 0))
  1332. {
  1333. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1334. {
  1335. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1336. compositePeriodIdx++;
  1337. }
  1338. else
  1339. {
  1340. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1341. }
  1342. }
  1343. }
  1344. }
  1345. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1346. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1347. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1348. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1349. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1350. {
  1351. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1352. {
  1353. compositeProfile->ChargingProfileId = 1;
  1354. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1355. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1356. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1357. }
  1358. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1359. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1360. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1361. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1362. }
  1363. if(line)
  1364. free(line);
  1365. }
  1366. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1367. {
  1368. FILE *fp;
  1369. char profileFileName[128];
  1370. char *line = NULL;
  1371. size_t len = 0;
  1372. time_t CurrentTime;
  1373. struct tm *tmComposite;
  1374. struct StructChargingProfile maxProfile;
  1375. struct StructChargingProfile defaultTxProfile;
  1376. struct StructChargingProfile txProfile;
  1377. struct StructChargingSchedulePeriod tmpPeriod;
  1378. uint8_t limitMax=0;
  1379. uint8_t limitDef=0;
  1380. uint8_t limitTx=0;
  1381. int compositePeriodIdx = 0;
  1382. CurrentTime = time(NULL);
  1383. tmComposite=localtime(&CurrentTime);
  1384. 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);
  1385. if(isUnitA)
  1386. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1387. else
  1388. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1389. compositeProfile->ChargingSchedule.Duration = durationReq;
  1390. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1391. {
  1392. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1393. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1394. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1395. }
  1396. compositeProfile->ChargingProfileId = 0;
  1397. compositeProfile->StackLevel = 99 ;
  1398. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1399. maxProfile.ChargingProfileId = -1;
  1400. defaultTxProfile.ChargingProfileId = -1;
  1401. txProfile.ChargingProfileId = -1;
  1402. maxProfile.ChargingSchedule.Duration = -1;
  1403. defaultTxProfile.ChargingSchedule.Duration = -1;
  1404. txProfile.ChargingSchedule.Duration = -1;
  1405. system("rm -f /tmp/*.json");
  1406. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1407. /*
  1408. * Search valid charging profile
  1409. */
  1410. //DEBUG_INFO("====================================\n");
  1411. // Search tx profile
  1412. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1413. if((access(profileFileName, F_OK))!=-1)
  1414. {
  1415. fp = fopen(profileFileName, "r");
  1416. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1417. {
  1418. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1419. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1420. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1421. }
  1422. txProfile.ChargingProfileId = -1;
  1423. txProfile.StackLevel = -1;
  1424. while(getline(&line, &len, fp) != -1)
  1425. {
  1426. json_object *obj = NULL;
  1427. obj = json_tokener_parse(line);
  1428. if(is_error(obj))
  1429. {
  1430. DEBUG_ERROR("Parse txProfile from file error.\n");
  1431. }
  1432. else
  1433. {
  1434. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  1435. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1436. )
  1437. {
  1438. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1439. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1440. )
  1441. {
  1442. struct tm tmFrom, tmTo;
  1443. struct timeb tbFrom, tbTo;
  1444. 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) &&
  1445. (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))
  1446. {
  1447. tmFrom.tm_year -= 1900;
  1448. tmFrom.tm_mon -= 1;
  1449. tbFrom.time = mktime(&tmFrom);
  1450. tmTo.tm_year -= 1900;
  1451. tmTo.tm_mon -= 1;
  1452. tbTo.time = mktime(&tmTo);
  1453. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1454. {
  1455. if(txProfile.ChargingProfileId == -1)
  1456. DEBUG_INFO("TxProfile found.\n");
  1457. else
  1458. DEBUG_INFO("TxProfile updated.\n");
  1459. // Required item
  1460. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1461. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1462. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1463. if(isUnitA)
  1464. {
  1465. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1466. 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++)
  1467. {
  1468. 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"));
  1469. 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?
  1470. 3:
  1471. 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")));
  1472. 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")));
  1473. }
  1474. }
  1475. else
  1476. {
  1477. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1478. 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++)
  1479. {
  1480. 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"));
  1481. 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?
  1482. 3:
  1483. 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")));
  1484. 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));
  1485. }
  1486. }
  1487. // Optional item
  1488. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1489. {
  1490. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1491. }
  1492. else
  1493. {
  1494. sprintf((char*)txProfile.ValidFrom, " ");
  1495. }
  1496. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1497. {
  1498. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1499. }
  1500. else
  1501. {
  1502. sprintf((char*)txProfile.ValidTo, " ");
  1503. }
  1504. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1505. {
  1506. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1507. }
  1508. else
  1509. {
  1510. sprintf((char*)txProfile.RecurrencyKind, " ");
  1511. }
  1512. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1513. {
  1514. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1515. }
  1516. else
  1517. {
  1518. txProfile.TransactionId = -1;
  1519. }
  1520. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1521. {
  1522. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1523. }
  1524. else
  1525. {
  1526. txProfile.ChargingSchedule.Duration = 86400;
  1527. }
  1528. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1529. {
  1530. 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")));
  1531. }
  1532. else
  1533. {
  1534. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1535. }
  1536. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1537. {
  1538. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1539. }
  1540. else
  1541. {
  1542. txProfile.ChargingSchedule.MinChargingRate = -1;
  1543. }
  1544. }
  1545. }
  1546. }
  1547. else
  1548. {
  1549. if(txProfile.ChargingProfileId == -1)
  1550. DEBUG_INFO("TxProfile found.\n");
  1551. else
  1552. DEBUG_INFO("TxProfile updated.\n");
  1553. // Required item
  1554. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1555. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1556. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1557. if(isUnitA)
  1558. {
  1559. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1560. 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++)
  1561. {
  1562. 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"));
  1563. 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?
  1564. 3:
  1565. 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")));
  1566. 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")));
  1567. }
  1568. }
  1569. else
  1570. {
  1571. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1572. 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++)
  1573. {
  1574. 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"));
  1575. 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?
  1576. 3:
  1577. 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")));
  1578. 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));
  1579. }
  1580. }
  1581. // Optional item
  1582. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1583. {
  1584. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1585. }
  1586. else
  1587. {
  1588. sprintf((char*)txProfile.ValidFrom, " ");
  1589. }
  1590. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1591. {
  1592. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1593. }
  1594. else
  1595. {
  1596. sprintf((char*)txProfile.ValidTo, " ");
  1597. }
  1598. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1599. {
  1600. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1601. }
  1602. else
  1603. {
  1604. sprintf((char*)txProfile.RecurrencyKind, " ");
  1605. }
  1606. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1607. {
  1608. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1609. }
  1610. else
  1611. {
  1612. txProfile.TransactionId = -1;
  1613. }
  1614. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1615. {
  1616. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1617. }
  1618. else
  1619. {
  1620. txProfile.ChargingSchedule.Duration = 86400;
  1621. }
  1622. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1623. {
  1624. 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")));
  1625. }
  1626. else
  1627. {
  1628. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1629. }
  1630. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1631. {
  1632. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1633. }
  1634. else
  1635. {
  1636. txProfile.ChargingSchedule.MinChargingRate = -1;
  1637. }
  1638. }
  1639. }
  1640. }
  1641. json_object_put(obj);
  1642. }
  1643. fclose(fp);
  1644. /*
  1645. if(txProfile.ChargingProfileId != -1)
  1646. {
  1647. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1648. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1649. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1650. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1651. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1652. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1653. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1654. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1655. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1656. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1657. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1658. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1659. {
  1660. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1661. {
  1662. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1663. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1664. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1665. }
  1666. }
  1667. }
  1668. else
  1669. DEBUG_INFO("TxProfile not found.\n");*/
  1670. }
  1671. // Search default tx profile
  1672. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1673. if((access(profileFileName, F_OK))==-1)
  1674. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1675. if((access(profileFileName, F_OK))!=-1)
  1676. {
  1677. fp = fopen(profileFileName, "r");
  1678. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1679. {
  1680. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1681. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1682. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1683. }
  1684. defaultTxProfile.ChargingProfileId = -1;
  1685. defaultTxProfile.StackLevel = -1;
  1686. while(getline(&line, &len, fp) != -1)
  1687. {
  1688. json_object *obj = NULL;
  1689. obj = json_tokener_parse(line);
  1690. if(is_error(obj))
  1691. {
  1692. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1693. }
  1694. else
  1695. {
  1696. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1697. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1698. )
  1699. {
  1700. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1701. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1702. )
  1703. {
  1704. struct tm tmFrom, tmTo;
  1705. struct timeb tbFrom, tbTo;
  1706. 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) &&
  1707. (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))
  1708. {
  1709. tmFrom.tm_year -= 1900;
  1710. tmFrom.tm_mon -= 1;
  1711. tbFrom.time = mktime(&tmFrom);
  1712. tmTo.tm_year -= 1900;
  1713. tmTo.tm_mon -= 1;
  1714. tbTo.time = mktime(&tmTo);
  1715. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1716. {
  1717. if(defaultTxProfile.ChargingProfileId == -1)
  1718. DEBUG_INFO("TxDefaultProfile found.\n");
  1719. else
  1720. DEBUG_INFO("TxDefaultProfile updated.\n");
  1721. // Required item
  1722. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1723. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1724. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1725. if(isUnitA)
  1726. {
  1727. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1728. 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++)
  1729. {
  1730. 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"));
  1731. 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?
  1732. 3:
  1733. 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")));
  1734. 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")));
  1735. }
  1736. }
  1737. else
  1738. {
  1739. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1740. 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++)
  1741. {
  1742. 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"));
  1743. 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?
  1744. 3:
  1745. 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")));
  1746. 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));
  1747. }
  1748. }
  1749. // Optional item
  1750. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1751. {
  1752. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1753. }
  1754. else
  1755. {
  1756. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1757. }
  1758. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1759. {
  1760. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1761. }
  1762. else
  1763. {
  1764. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1765. }
  1766. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1767. {
  1768. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1769. }
  1770. else
  1771. {
  1772. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1773. }
  1774. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1775. {
  1776. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1777. }
  1778. else
  1779. {
  1780. defaultTxProfile.TransactionId = -1;
  1781. }
  1782. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1783. {
  1784. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1785. }
  1786. else
  1787. {
  1788. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1789. }
  1790. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1791. {
  1792. 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")));
  1793. }
  1794. else
  1795. {
  1796. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1797. }
  1798. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1799. {
  1800. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1801. }
  1802. else
  1803. {
  1804. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1805. }
  1806. }
  1807. }
  1808. }
  1809. else
  1810. {
  1811. if(defaultTxProfile.ChargingProfileId == -1)
  1812. DEBUG_INFO("TxDefaultProfile found.\n");
  1813. else
  1814. DEBUG_INFO("TxDefaultProfile updated.\n");
  1815. // Required item
  1816. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1817. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1818. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1819. if(isUnitA)
  1820. {
  1821. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1822. 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++)
  1823. {
  1824. 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"));
  1825. 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?
  1826. 3:
  1827. 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")));
  1828. 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")));
  1829. }
  1830. }
  1831. else
  1832. {
  1833. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1834. 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++)
  1835. {
  1836. 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"));
  1837. 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?
  1838. 3:
  1839. 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")));
  1840. 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));
  1841. }
  1842. }
  1843. // Optional item
  1844. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1845. {
  1846. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1847. }
  1848. else
  1849. {
  1850. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1851. }
  1852. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1853. {
  1854. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1855. }
  1856. else
  1857. {
  1858. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1859. }
  1860. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1861. {
  1862. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1863. }
  1864. else
  1865. {
  1866. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1867. }
  1868. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1869. {
  1870. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1871. }
  1872. else
  1873. {
  1874. defaultTxProfile.TransactionId = -1;
  1875. }
  1876. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1877. {
  1878. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1879. }
  1880. else
  1881. {
  1882. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1883. }
  1884. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1885. {
  1886. 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")));
  1887. }
  1888. else
  1889. {
  1890. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1891. }
  1892. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1893. {
  1894. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1895. }
  1896. else
  1897. {
  1898. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1899. }
  1900. }
  1901. }
  1902. }
  1903. json_object_put(obj);
  1904. }
  1905. fclose(fp);
  1906. /*
  1907. if(defaultTxProfile.ChargingProfileId != -1)
  1908. {
  1909. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1910. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1911. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1912. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1913. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1914. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1915. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1916. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  1917. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1918. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1919. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1920. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1921. {
  1922. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1923. {
  1924. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1925. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1926. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1927. }
  1928. }
  1929. }
  1930. else
  1931. DEBUG_INFO("TxDefaultProfile not found.\n");
  1932. DEBUG_INFO("------------------------------------\n");*/
  1933. }
  1934. // Search max profile
  1935. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1936. if((access(profileFileName, F_OK))!=-1)
  1937. {
  1938. fp = fopen(profileFileName, "r");
  1939. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1940. {
  1941. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1942. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1943. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1944. }
  1945. maxProfile.ChargingProfileId = -1;
  1946. maxProfile.StackLevel = -1;
  1947. while(getline(&line, &len, fp) != -1)
  1948. {
  1949. json_object *obj = NULL;
  1950. obj = json_tokener_parse(line);
  1951. if(is_error(obj))
  1952. {
  1953. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1954. }
  1955. else
  1956. {
  1957. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1958. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1959. )
  1960. {
  1961. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1962. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1963. )
  1964. {
  1965. struct tm tmFrom, tmTo;
  1966. struct timeb tbFrom, tbTo;
  1967. 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) &&
  1968. (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))
  1969. {
  1970. tmFrom.tm_year -= 1900;
  1971. tmFrom.tm_mon -= 1;
  1972. tbFrom.time = mktime(&tmFrom);
  1973. tmTo.tm_year -= 1900;
  1974. tmTo.tm_mon -= 1;
  1975. tbTo.time = mktime(&tmTo);
  1976. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1977. {
  1978. if(maxProfile.ChargingProfileId == -1)
  1979. DEBUG_INFO("MaxProfile found.\n");
  1980. else
  1981. DEBUG_INFO("MaxProfile updated.\n");
  1982. // Required item
  1983. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1984. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1985. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1986. if(isUnitA)
  1987. {
  1988. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1989. 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++)
  1990. {
  1991. 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"));
  1992. 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?
  1993. 3:
  1994. 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")));
  1995. 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")));
  1996. }
  1997. }
  1998. else
  1999. {
  2000. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2001. 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++)
  2002. {
  2003. 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"));
  2004. 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?
  2005. 3:
  2006. 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")));
  2007. 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));
  2008. }
  2009. }
  2010. // Optional item
  2011. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2012. {
  2013. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2014. }
  2015. else
  2016. {
  2017. sprintf((char*)maxProfile.ValidFrom, " ");
  2018. }
  2019. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2020. {
  2021. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2022. }
  2023. else
  2024. {
  2025. sprintf((char*)maxProfile.ValidTo, " ");
  2026. }
  2027. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2028. {
  2029. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2030. }
  2031. else
  2032. {
  2033. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2034. }
  2035. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2036. {
  2037. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2038. }
  2039. else
  2040. {
  2041. maxProfile.TransactionId = -1;
  2042. }
  2043. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2044. {
  2045. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2046. }
  2047. else
  2048. {
  2049. maxProfile.ChargingSchedule.Duration = 86400;
  2050. }
  2051. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2052. {
  2053. 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")));
  2054. }
  2055. else
  2056. {
  2057. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2058. }
  2059. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2060. {
  2061. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2062. }
  2063. else
  2064. {
  2065. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2066. }
  2067. }
  2068. }
  2069. }
  2070. else
  2071. {
  2072. if(maxProfile.ChargingProfileId == -1)
  2073. DEBUG_INFO("MaxProfile found.\n");
  2074. else
  2075. DEBUG_INFO("MaxProfile updated.\n");
  2076. // Required item
  2077. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2078. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2079. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2080. if(isUnitA)
  2081. {
  2082. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2083. 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++)
  2084. {
  2085. 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"));
  2086. 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?
  2087. 3:
  2088. 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")));
  2089. 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")));
  2090. }
  2091. }
  2092. else
  2093. {
  2094. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2095. 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++)
  2096. {
  2097. 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"));
  2098. 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?
  2099. 3:
  2100. 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")));
  2101. 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));
  2102. }
  2103. }
  2104. // Optional item
  2105. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2106. {
  2107. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2108. }
  2109. else
  2110. {
  2111. sprintf((char*)maxProfile.ValidFrom, " ");
  2112. }
  2113. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2114. {
  2115. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2116. }
  2117. else
  2118. {
  2119. sprintf((char*)maxProfile.ValidTo, " ");
  2120. }
  2121. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2122. {
  2123. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2124. }
  2125. else
  2126. {
  2127. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2128. }
  2129. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2130. {
  2131. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2132. }
  2133. else
  2134. {
  2135. maxProfile.TransactionId = -1;
  2136. }
  2137. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2138. {
  2139. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2140. }
  2141. else
  2142. {
  2143. maxProfile.ChargingSchedule.Duration = 86400;
  2144. }
  2145. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2146. {
  2147. 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")));
  2148. }
  2149. else
  2150. {
  2151. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2152. }
  2153. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2154. {
  2155. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2156. }
  2157. else
  2158. {
  2159. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2160. }
  2161. }
  2162. }
  2163. }
  2164. json_object_put(obj);
  2165. }
  2166. fclose(fp);
  2167. /*
  2168. if(maxProfile.ChargingProfileId !=-1)
  2169. {
  2170. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2171. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2172. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2173. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2174. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2175. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2176. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2177. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2178. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2179. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2180. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2181. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2182. {
  2183. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2184. {
  2185. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2186. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2187. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2188. }
  2189. }
  2190. }
  2191. else
  2192. DEBUG_INFO("MaxProfile not found.\n");
  2193. DEBUG_INFO("------------------------------------\n");*/
  2194. }
  2195. /*
  2196. * Align found profile start schedule & periods
  2197. */
  2198. //DEBUG_INFO("====================================\n");
  2199. /*
  2200. // For local test usage, force modify found profile start schedule info
  2201. 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);
  2202. 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);
  2203. 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);
  2204. */
  2205. if(txProfile.ChargingProfileId != -1)
  2206. {
  2207. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2208. {
  2209. if(txProfile.ChargingSchedule.Duration != -1)
  2210. {
  2211. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2212. 0:
  2213. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2214. }
  2215. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2216. {
  2217. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2218. {
  2219. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2220. 0:
  2221. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2222. if(idxPeriod > 0)
  2223. {
  2224. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2225. {
  2226. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2227. }
  2228. }
  2229. }
  2230. }
  2231. }
  2232. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2233. {
  2234. if(txProfile.ChargingSchedule.Duration != -1)
  2235. {
  2236. txProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2237. 0:
  2238. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2239. }
  2240. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2241. {
  2242. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2243. {
  2244. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2245. 0:
  2246. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2247. if(idxPeriod > 0)
  2248. {
  2249. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2250. {
  2251. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2252. }
  2253. }
  2254. }
  2255. }
  2256. }
  2257. else
  2258. {
  2259. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2260. {
  2261. if(txProfile.ChargingSchedule.Duration != -1)
  2262. {
  2263. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2264. 0:
  2265. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2266. }
  2267. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2268. {
  2269. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2270. {
  2271. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2272. 0:
  2273. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2274. if(idxPeriod > 0)
  2275. {
  2276. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2277. {
  2278. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2279. }
  2280. }
  2281. }
  2282. }
  2283. }
  2284. else
  2285. {
  2286. if(txProfile.ChargingSchedule.Duration != -1)
  2287. {
  2288. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2289. 0:
  2290. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2291. }
  2292. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2293. {
  2294. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2295. {
  2296. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2297. 0:
  2298. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2299. if(idxPeriod > 0)
  2300. {
  2301. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2302. {
  2303. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2304. }
  2305. }
  2306. }
  2307. }
  2308. }
  2309. }
  2310. /*
  2311. DEBUG_INFO("txProfile after align.\n");
  2312. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2313. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2314. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2315. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2316. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2317. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2318. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  2319. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2320. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2321. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2322. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2323. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2324. {
  2325. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2326. {
  2327. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2328. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2329. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2330. }
  2331. }*/
  2332. }
  2333. if(defaultTxProfile.ChargingProfileId != -1)
  2334. {
  2335. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2336. {
  2337. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2338. {
  2339. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2340. 0:
  2341. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2342. }
  2343. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2344. {
  2345. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2346. {
  2347. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2348. 0:
  2349. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2350. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2351. {
  2352. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2353. }
  2354. if(idxPeriod > 0)
  2355. {
  2356. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2357. {
  2358. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2359. }
  2360. }
  2361. }
  2362. }
  2363. }
  2364. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2365. {
  2366. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2367. {
  2368. defaultTxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2369. 0:
  2370. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2371. }
  2372. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2373. {
  2374. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2375. {
  2376. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2377. 0:
  2378. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2379. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2380. {
  2381. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2382. }
  2383. if(idxPeriod > 0)
  2384. {
  2385. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2386. {
  2387. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2388. }
  2389. }
  2390. }
  2391. }
  2392. }
  2393. else
  2394. {
  2395. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2396. {
  2397. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2398. {
  2399. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2400. 0:
  2401. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2402. }
  2403. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2404. {
  2405. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2406. {
  2407. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2408. 0:
  2409. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2410. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2411. {
  2412. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2413. }
  2414. if(idxPeriod > 0)
  2415. {
  2416. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2417. {
  2418. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2419. }
  2420. }
  2421. }
  2422. }
  2423. }
  2424. else
  2425. {
  2426. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2427. {
  2428. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2429. 0:
  2430. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2431. }
  2432. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2433. {
  2434. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2435. {
  2436. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2437. 0:
  2438. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2439. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2440. {
  2441. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2442. }
  2443. if(idxPeriod > 0)
  2444. {
  2445. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2446. {
  2447. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2448. }
  2449. }
  2450. }
  2451. }
  2452. }
  2453. }
  2454. /*
  2455. DEBUG_INFO("defaultTxProfile after align.\n");
  2456. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2457. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2458. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2459. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2460. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2461. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2462. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2463. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2464. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2465. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2466. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2467. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2468. {
  2469. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2470. {
  2471. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2472. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2473. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2474. }
  2475. }
  2476. DEBUG_INFO("------------------------------------\n");*/
  2477. }
  2478. if(maxProfile.ChargingProfileId != -1)
  2479. {
  2480. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2481. {
  2482. if(maxProfile.ChargingSchedule.Duration != -1)
  2483. {
  2484. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2485. 0:
  2486. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2487. }
  2488. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2489. {
  2490. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2491. {
  2492. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2493. 0:
  2494. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2495. if(idxPeriod > 0)
  2496. {
  2497. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2498. {
  2499. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2500. }
  2501. }
  2502. }
  2503. }
  2504. }
  2505. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2506. {
  2507. if(maxProfile.ChargingSchedule.Duration != -1)
  2508. {
  2509. maxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2510. 0:
  2511. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2512. }
  2513. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2514. {
  2515. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2516. {
  2517. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2518. 0:
  2519. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2520. if(idxPeriod > 0)
  2521. {
  2522. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2523. {
  2524. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2525. }
  2526. }
  2527. }
  2528. }
  2529. }
  2530. else
  2531. {
  2532. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2533. {
  2534. if(maxProfile.ChargingSchedule.Duration != -1)
  2535. {
  2536. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2537. 0:
  2538. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2539. }
  2540. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2541. {
  2542. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2543. {
  2544. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2545. 0:
  2546. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2547. if(idxPeriod > 0)
  2548. {
  2549. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2550. {
  2551. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2552. }
  2553. }
  2554. }
  2555. }
  2556. }
  2557. else
  2558. {
  2559. if(maxProfile.ChargingSchedule.Duration != -1)
  2560. {
  2561. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2562. 0:
  2563. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2564. }
  2565. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2566. {
  2567. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2568. {
  2569. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2570. 0:
  2571. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2572. if(idxPeriod > 0)
  2573. {
  2574. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2575. {
  2576. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2577. }
  2578. }
  2579. }
  2580. }
  2581. }
  2582. }
  2583. /*
  2584. DEBUG_INFO("MaxProfile after align.\n");
  2585. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2586. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2587. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2588. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2589. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2590. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2591. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2592. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2593. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2594. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2595. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2596. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2597. {
  2598. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2599. {
  2600. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2601. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2602. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2603. }
  2604. }
  2605. DEBUG_INFO("------------------------------------\n");*/
  2606. }
  2607. /*
  2608. * Merge to conposite schedule
  2609. */
  2610. //DEBUG_INFO("====================================\n");
  2611. // Find each profile period quantity
  2612. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2613. {
  2614. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2615. limitMax = idx+1;
  2616. }
  2617. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2618. {
  2619. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2620. limitDef = idx+1;
  2621. }
  2622. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2623. {
  2624. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2625. limitTx = idx+1;
  2626. }
  2627. // TxProfile found, composite schedule based on it
  2628. if(txProfile.ChargingProfileId != -1)
  2629. {
  2630. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2631. {
  2632. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2633. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2634. (txProfile.ChargingSchedule.Duration > 0))
  2635. {
  2636. if(maxProfile.ChargingProfileId != -1)
  2637. {
  2638. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2639. {
  2640. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2641. {
  2642. if((maxProfile.ChargingSchedule.Duration > 0))
  2643. {
  2644. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2645. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2646. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2647. }
  2648. else
  2649. {
  2650. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2651. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2652. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2653. }
  2654. }
  2655. if(idxMaxPeriod == (limitMax-1))
  2656. {
  2657. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2658. {
  2659. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2660. {
  2661. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2662. compositePeriodIdx++;
  2663. }
  2664. else
  2665. {
  2666. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2667. }
  2668. }
  2669. }
  2670. }
  2671. }
  2672. else
  2673. {
  2674. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2675. {
  2676. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2677. compositePeriodIdx++;
  2678. }
  2679. else
  2680. {
  2681. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2682. }
  2683. }
  2684. }
  2685. if(idxTxPeriod == (limitTx-1))
  2686. {
  2687. if(defaultTxProfile.ChargingProfileId != -1)
  2688. {
  2689. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2690. {
  2691. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2692. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2693. (defaultTxProfile.ChargingSchedule.Duration>0))
  2694. {
  2695. if(maxProfile.ChargingProfileId != -1)
  2696. {
  2697. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2698. {
  2699. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2700. {
  2701. if((maxProfile.ChargingSchedule.Duration > 0))
  2702. {
  2703. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2704. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2705. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2706. }
  2707. else
  2708. {
  2709. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2710. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2711. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2712. }
  2713. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2714. {
  2715. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2716. {
  2717. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2718. compositePeriodIdx++;
  2719. }
  2720. else
  2721. {
  2722. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2723. }
  2724. }
  2725. // Delete duplicate period
  2726. if(compositePeriodIdx > 1)
  2727. {
  2728. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2729. {
  2730. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2731. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2732. compositePeriodIdx -= 1;
  2733. }
  2734. }
  2735. }
  2736. else
  2737. break;
  2738. }
  2739. }
  2740. else
  2741. {
  2742. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2743. {
  2744. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2745. compositePeriodIdx++;
  2746. }
  2747. else
  2748. {
  2749. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2750. }
  2751. }
  2752. }
  2753. }
  2754. }
  2755. }
  2756. }
  2757. }
  2758. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2759. else if(defaultTxProfile.ChargingProfileId != -1)
  2760. {
  2761. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2762. {
  2763. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2764. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2765. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2766. {
  2767. if(maxProfile.ChargingProfileId != -1)
  2768. {
  2769. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2770. {
  2771. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2772. {
  2773. if((maxProfile.ChargingSchedule.Duration > 0))
  2774. {
  2775. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2776. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2777. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2778. }
  2779. else
  2780. {
  2781. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2782. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2783. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2784. }
  2785. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2786. {
  2787. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2788. {
  2789. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2790. compositePeriodIdx++;
  2791. }
  2792. else
  2793. {
  2794. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2795. }
  2796. }
  2797. // Delete duplicate period
  2798. if(compositePeriodIdx > 1)
  2799. {
  2800. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2801. {
  2802. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2803. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2804. compositePeriodIdx -= 1;
  2805. }
  2806. }
  2807. }
  2808. else
  2809. break;
  2810. }
  2811. }
  2812. else
  2813. {
  2814. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2815. {
  2816. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2817. compositePeriodIdx++;
  2818. }
  2819. else
  2820. {
  2821. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2822. }
  2823. }
  2824. }
  2825. }
  2826. }
  2827. // Fill other period by MaxProfile
  2828. if(maxProfile.ChargingProfileId != -1)
  2829. {
  2830. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2831. {
  2832. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2833. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2834. (maxProfile.ChargingSchedule.Duration > 0))
  2835. {
  2836. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  2837. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2838. {
  2839. tmpPeriod.StartPeriod = (compositePeriodIdx==0)?0:compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  2840. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  2841. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2842. }
  2843. if((compositePeriodIdx > 0 ) && (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2844. {
  2845. tmpPeriod.StartPeriod = (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod>compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod:compositeProfile->ChargingSchedule.Duration;
  2846. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  2847. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2848. }
  2849. if(tmpPeriod.Limit != -1)
  2850. {
  2851. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2852. {
  2853. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2854. {
  2855. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2856. compositePeriodIdx++;
  2857. }
  2858. else
  2859. {
  2860. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2861. }
  2862. }
  2863. // Delete duplicate period
  2864. if(compositePeriodIdx > 1)
  2865. {
  2866. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2867. {
  2868. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2869. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2870. compositePeriodIdx -= 1;
  2871. }
  2872. }
  2873. }
  2874. }
  2875. }
  2876. }
  2877. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  2878. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2879. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  2880. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  2881. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2882. {
  2883. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2884. {
  2885. compositeProfile->ChargingProfileId = 1;
  2886. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2887. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2888. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2889. }
  2890. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2891. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2892. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2893. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2894. }
  2895. if(line)
  2896. free(line);
  2897. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  2898. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  2899. }
  2900. //==========================================
  2901. // Init all share memory
  2902. //==========================================
  2903. int InitShareMemory()
  2904. {
  2905. int result = PASS;
  2906. int MeterSMId;
  2907. //creat ShmSysConfigAndInfo
  2908. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  2909. {
  2910. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  2911. result = FAIL;
  2912. }
  2913. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2914. {
  2915. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  2916. result = FAIL;
  2917. }
  2918. else
  2919. {}
  2920. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  2921. {
  2922. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  2923. result = FAIL;
  2924. }
  2925. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2926. {
  2927. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  2928. result = FAIL;
  2929. }
  2930. else
  2931. {}
  2932. //creat ShmPsuData
  2933. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  2934. {
  2935. DEBUG_ERROR("shmget ShmPsuData NG\n");
  2936. result = FAIL;
  2937. }
  2938. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2939. {
  2940. DEBUG_ERROR("shmat ShmPsuData NG\n");
  2941. result = FAIL;
  2942. }
  2943. else
  2944. {}
  2945. //creat ShmOCPP16Data
  2946. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  2947. {
  2948. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  2949. result = FAIL;
  2950. }
  2951. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2952. {
  2953. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  2954. result = FAIL;
  2955. }
  2956. else
  2957. {}
  2958. /****************************** For Initial Settings************************************************/
  2959. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  2960. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  2961. // allocate Configuration memory address
  2962. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  2963. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  2964. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  2965. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  2966. //offline MeterValue Interval
  2967. TempMeterValueInterval = 0;
  2968. return result;
  2969. }
  2970. int ProcessShareMemory()
  2971. {
  2972. if(InitShareMemory() == FAIL)
  2973. {
  2974. DEBUG_ERROR("InitShareMemory NG\n");
  2975. if(ShmStatusCodeData!=NULL)
  2976. {
  2977. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2978. }
  2979. sleep(5);
  2980. return FAIL;
  2981. }
  2982. return PASS;
  2983. }
  2984. void CheckSystemValue(void)
  2985. {
  2986. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  2987. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  2988. char filenmae[100]={0};
  2989. char str[100]={0};
  2990. int tempIndex = 0;
  2991. //===============================
  2992. // send Heartbeat
  2993. //===============================
  2994. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2995. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2996. {
  2997. clientTime.Heartbeat=time((time_t*)NULL);
  2998. if(server_sign == TRUE)
  2999. {
  3000. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  3001. }
  3002. else
  3003. {
  3004. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  3005. }
  3006. }
  3007. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3008. {
  3009. //parameter for test
  3010. sendHeartbeatRequest(0);
  3011. //==============================================
  3012. // Reset Waiting Time
  3013. //==============================================
  3014. HeartBeatWithNOResponse += 1;
  3015. }
  3016. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3017. {
  3018. //==========================================
  3019. // csu trigger DataTransferReq
  3020. //==========================================
  3021. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  3022. {
  3023. sendDataTransferRequest(gun_index);
  3024. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  3025. }
  3026. //===============================
  3027. // CSU Trigger Authorize Request
  3028. //===============================
  3029. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3030. {
  3031. sendAuthorizeRequest(0);
  3032. authorizeRetryTimes = authorizeRetryTimes + 1;
  3033. if(authorizeRetryTimes < 3)
  3034. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3035. }
  3036. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3037. {
  3038. authorizeRetryTimes = 0;
  3039. SetOcppConnStatus(FALSE);
  3040. server_sign = FALSE;
  3041. }
  3042. 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))
  3043. {
  3044. sendAuthorizeRequest(0);
  3045. }
  3046. //==============================================
  3047. // Charger start transaction
  3048. //==============================================
  3049. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3050. {
  3051. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3052. sendStartTransactionRequest(gun_index);
  3053. clientTime.StartTransaction = time((time_t*)NULL);
  3054. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3055. storeTempStopTransaction(gun_index);
  3056. }
  3057. //==============================================
  3058. // Charger stop transaction
  3059. //==============================================
  3060. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3061. {
  3062. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3063. sendStopTransactionRequest(gun_index);
  3064. clientTime.StopTransaction = time((time_t*)NULL);
  3065. }
  3066. //==============================================
  3067. // Charger status report
  3068. //==============================================
  3069. //--- Check Mode Change ---//
  3070. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3071. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3072. {
  3073. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3074. {
  3075. tempIndex = ((gun_index==2) ? 1: 0);
  3076. }
  3077. else
  3078. {
  3079. tempIndex = gun_index;
  3080. }
  3081. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3082. {
  3083. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3084. {
  3085. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3086. {
  3087. // Sent unplug message for California pricing logic
  3088. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3089. {
  3090. uint8_t ts[20];
  3091. getNowDatetime(ts);
  3092. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3093. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3094. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3095. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3096. }
  3097. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3098. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3099. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3100. }
  3101. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3102. {
  3103. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3104. if((access(filenmae,F_OK))!=-1)
  3105. {
  3106. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3107. sprintf(str,"rm -f %s",filenmae);
  3108. system(str);
  3109. }
  3110. }
  3111. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3112. #if 1 // for TempStopTransaction
  3113. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3114. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3115. {
  3116. checkTempStopTransaction(gun_index);
  3117. }
  3118. #endif
  3119. }
  3120. }
  3121. }
  3122. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3123. {
  3124. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3125. {
  3126. tempIndex = ((gun_index==2) ? 1: 0);
  3127. }
  3128. else
  3129. {
  3130. tempIndex = gun_index;
  3131. }
  3132. for (int index = 0; index < CCS_QUANTITY; index++)
  3133. {
  3134. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3135. {
  3136. 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]*/ )
  3137. {
  3138. // Sent unplug message for California pricing logic
  3139. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3140. {
  3141. uint8_t ts[20];
  3142. getNowDatetime(ts);
  3143. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3144. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3145. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3146. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3147. }
  3148. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3149. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3150. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3151. }
  3152. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3153. {
  3154. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3155. if((access(filenmae,F_OK))!=-1)
  3156. {
  3157. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3158. sprintf(str,"rm -f %s",filenmae);
  3159. system(str);
  3160. }
  3161. }
  3162. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3163. #if 1 // for TempStopTransaction
  3164. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3165. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3166. {
  3167. checkTempStopTransaction(gun_index);
  3168. }
  3169. #endif
  3170. }
  3171. }
  3172. }
  3173. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3174. {
  3175. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3176. {
  3177. tempIndex = ((gun_index==2) ? 1: 0);
  3178. }
  3179. else
  3180. {
  3181. tempIndex = gun_index;
  3182. }
  3183. for (int index = 0; index < GB_QUANTITY; index++)
  3184. {
  3185. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3186. {
  3187. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3188. {
  3189. // Sent unplug message for California pricing logic
  3190. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3191. {
  3192. uint8_t ts[20];
  3193. getNowDatetime(ts);
  3194. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3195. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3196. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3197. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3198. }
  3199. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3200. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3201. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3202. }
  3203. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3204. {
  3205. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3206. if((access(filenmae,F_OK))!=-1)
  3207. {
  3208. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3209. sprintf(str,"rm -f %s",filenmae);
  3210. system(str);
  3211. }
  3212. }
  3213. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3214. #if 1 // for TempStopTransaction
  3215. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3216. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3217. {
  3218. checkTempStopTransaction(gun_index);
  3219. }
  3220. #endif
  3221. }
  3222. }
  3223. }
  3224. else if(gunType[gun_index] == GUN_TYPE_DO)
  3225. {
  3226. tempIndex = gun_index;
  3227. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3228. {
  3229. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3230. {
  3231. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3232. {
  3233. // Sent unplug message for California pricing logic
  3234. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3235. {
  3236. uint8_t ts[20];
  3237. getNowDatetime(ts);
  3238. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3239. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3240. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3241. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3242. }
  3243. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3244. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3245. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3246. }
  3247. 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
  3248. {
  3249. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3250. if((access(filenmae,F_OK))!=-1)
  3251. {
  3252. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3253. sprintf(str,"rm -f %s",filenmae);
  3254. system(str);
  3255. }
  3256. }
  3257. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3258. #if 1 // for TempStopTransaction
  3259. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3260. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3261. {
  3262. checkTempStopTransaction(gun_index);
  3263. }
  3264. #endif
  3265. }
  3266. }
  3267. }
  3268. else
  3269. {
  3270. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3271. {
  3272. tempIndex = 2;
  3273. }
  3274. else
  3275. {
  3276. tempIndex = gun_index;
  3277. }
  3278. for (int index = 0; index < AC_QUANTITY; index++)
  3279. {
  3280. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3281. {
  3282. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3283. {
  3284. // Sent unplug message for California pricing logic
  3285. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  3286. {
  3287. uint8_t ts[20];
  3288. getNowDatetime(ts);
  3289. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3290. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3291. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3292. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3293. }
  3294. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3295. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3296. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3297. }
  3298. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3299. {
  3300. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3301. if((access(filenmae,F_OK))!=-1)
  3302. {
  3303. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3304. sprintf(str,"rm -f %s",filenmae);
  3305. system(str);
  3306. }
  3307. }
  3308. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3309. #if 1 // for TempStopTransaction
  3310. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3311. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3312. {
  3313. checkTempStopTransaction(gun_index);
  3314. }
  3315. #endif
  3316. }
  3317. }// END
  3318. }
  3319. if(isWebsocketSendable && (server_sign == TRUE) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5) &&
  3320. (
  3321. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  3322. )
  3323. )
  3324. {
  3325. if(SystemInitial > 0)
  3326. SystemInitial -= 1;
  3327. sendStatusNotificationRequest(gun_index);
  3328. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  3329. }
  3330. //==============================================
  3331. // CSU Trigger Smart Charging Profilw
  3332. //==============================================
  3333. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  3334. {
  3335. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  3336. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  3337. }
  3338. //==============================================
  3339. // Meter report
  3340. //==============================================
  3341. // Trigger MeterValue
  3342. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  3343. {
  3344. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  3345. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  3346. }
  3347. // ClockAlign MeterValue
  3348. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3349. {
  3350. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3351. {
  3352. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3353. {
  3354. tempIndex = ((gun_index==2) ? 1: 0);
  3355. }
  3356. else
  3357. {
  3358. tempIndex = gun_index;
  3359. }
  3360. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3361. {
  3362. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3363. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3364. {
  3365. reqClockAlignMeter[gun_index] = 1;
  3366. }
  3367. }// End for CHAdeMO
  3368. }
  3369. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3370. {
  3371. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3372. {
  3373. tempIndex = ((gun_index==2) ? 1: 0);
  3374. }
  3375. else
  3376. {
  3377. tempIndex = gun_index;
  3378. }
  3379. for (int index = 0; index < CCS_QUANTITY; index++)
  3380. {
  3381. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3382. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3383. {
  3384. reqClockAlignMeter[gun_index] = 1;
  3385. }
  3386. } // End for CCS
  3387. }
  3388. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3389. {
  3390. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3391. {
  3392. tempIndex = ((gun_index==2) ? 1: 0);
  3393. }
  3394. else
  3395. {
  3396. tempIndex = gun_index;
  3397. }
  3398. for (int index = 0; index < GB_QUANTITY; index++)
  3399. {
  3400. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3401. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3402. {
  3403. reqClockAlignMeter[gun_index] = 1;
  3404. }
  3405. }// End for GB
  3406. }
  3407. else if(gunType[gun_index] == GUN_TYPE_DO)
  3408. {
  3409. tempIndex = gun_index;
  3410. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3411. {
  3412. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3413. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3414. {
  3415. reqClockAlignMeter[gun_index] = 1;
  3416. }
  3417. }
  3418. }
  3419. else
  3420. {
  3421. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3422. {
  3423. tempIndex = 2;
  3424. }
  3425. else
  3426. {
  3427. tempIndex = gun_index;
  3428. }
  3429. for (int index = 0; index < AC_QUANTITY; index++)
  3430. {
  3431. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3432. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3433. {
  3434. reqClockAlignMeter[gun_index] = 1;
  3435. }
  3436. }//End for AC
  3437. }
  3438. if(reqClockAlignMeter[gun_index] == 1)
  3439. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  3440. }
  3441. // Sample period MeterValue
  3442. 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))))
  3443. {
  3444. //check Transaction active
  3445. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3446. {
  3447. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3448. {
  3449. tempIndex = ((gun_index==2) ? 1: 0);
  3450. }
  3451. else
  3452. {
  3453. tempIndex = gun_index;
  3454. }
  3455. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3456. {
  3457. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3458. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3459. {
  3460. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3461. {
  3462. reqSampleMeter[gun_index] = 1;
  3463. }
  3464. }
  3465. }// End for CHAdeMO
  3466. }
  3467. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3468. {
  3469. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3470. {
  3471. tempIndex = ((gun_index==2) ? 1: 0);
  3472. }
  3473. else
  3474. {
  3475. tempIndex = gun_index;
  3476. }
  3477. for (int index = 0; index < CCS_QUANTITY; index++)
  3478. {
  3479. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3480. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3481. {
  3482. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3483. {
  3484. reqSampleMeter[gun_index] = 1;
  3485. }
  3486. }
  3487. } // End for CCS
  3488. }
  3489. else if(gunType[gun_index] == GUN_TYPE_GBT)
  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 < GB_QUANTITY; index++)
  3500. {
  3501. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3502. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3503. {
  3504. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3505. {
  3506. reqSampleMeter[gun_index] = 1;
  3507. }
  3508. }
  3509. }// End for GB
  3510. }
  3511. else if(gunType[gun_index] == GUN_TYPE_DO)
  3512. {
  3513. tempIndex = gun_index;
  3514. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3515. {
  3516. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3517. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3518. {
  3519. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  3520. {
  3521. reqSampleMeter[gun_index] = 1;
  3522. }
  3523. }
  3524. }
  3525. }
  3526. else
  3527. {
  3528. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3529. {
  3530. tempIndex = 2;
  3531. }
  3532. else
  3533. {
  3534. tempIndex = gun_index;
  3535. }
  3536. for (int index = 0; index < AC_QUANTITY; index++)
  3537. {
  3538. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3539. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3540. {
  3541. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  3542. {
  3543. reqSampleMeter[gun_index] = 1;
  3544. }
  3545. }
  3546. }//End for AC
  3547. }
  3548. if(reqSampleMeter[gun_index] == 1)
  3549. {
  3550. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  3551. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  3552. storeTempStopTransaction(gun_index);
  3553. }
  3554. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3555. }
  3556. //==============================================
  3557. // Check Connector reserved
  3558. //==============================================
  3559. //===============================
  3560. // Check if Reserve is expired
  3561. //===============================
  3562. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3563. {
  3564. double diff_t;
  3565. struct tm tp;
  3566. // current time
  3567. time_t t = time(NULL);
  3568. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3569. tp.tm_isdst = -1;
  3570. time_t utc = mktime(&tp);
  3571. diff_t = difftime(utc, t);
  3572. if(diff_t <= 0)
  3573. {
  3574. DEBUG_INFO("reserve expired.\n");
  3575. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  3576. }
  3577. }//END OF Check if Reserve is expired
  3578. //==========================================
  3579. // csu trigger FirmwareStatusNotificationReq
  3580. //==========================================
  3581. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3582. {
  3583. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  3584. }
  3585. //==========================================
  3586. // csu trigger DiagnosticsStatusNotificationReq
  3587. //==========================================
  3588. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3589. {
  3590. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  3591. }
  3592. //==========================================
  3593. // csu trigger CancelReservationConf
  3594. //==========================================
  3595. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3596. {
  3597. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  3598. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  3599. }
  3600. //==========================================
  3601. // csu trigger ChangeAvailabilityConf
  3602. //==========================================
  3603. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3604. {
  3605. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  3606. }
  3607. //==========================================
  3608. // csu trigger UnlockConnectorConf
  3609. //==========================================
  3610. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3611. {
  3612. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  3613. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3614. }
  3615. //==========================================
  3616. // csu trigger ReserveNowConf
  3617. //==========================================
  3618. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3619. {
  3620. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  3621. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3622. }
  3623. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  3624. {
  3625. sendSignCertificateRequest();
  3626. }
  3627. }
  3628. }
  3629. //==========================================
  3630. // send request routine
  3631. //==========================================
  3632. int sendAuthorizeRequest(int gun_index)
  3633. {
  3634. mtrace();
  3635. int result = FAIL;
  3636. char message[100]={0};
  3637. char guid[37];
  3638. char tempdata[65]={0};
  3639. DEBUG_INFO("sendAuthorizeRequest...\n");
  3640. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3641. //Local Authorize
  3642. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  3643. {
  3644. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  3645. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3646. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3647. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3648. result = PASS;
  3649. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3650. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3651. authorizeRetryTimes = 0;
  3652. return result;
  3653. }
  3654. 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))||
  3655. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3656. {
  3657. // Query from cache
  3658. DEBUG_INFO("Authorize from cache.\n");
  3659. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3660. // Query from list
  3661. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3662. {
  3663. DEBUG_INFO("Authorize from list.\n");
  3664. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3665. }
  3666. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3667. {
  3668. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3669. {
  3670. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  3671. }
  3672. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3673. {
  3674. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  3675. }
  3676. if(!GetOcppConnStatus())
  3677. {
  3678. DEBUG_INFO("off-line Local Authorization Fail.\n");
  3679. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3680. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3681. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3682. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3683. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3684. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3685. authorizeRetryTimes = 0;
  3686. return result;
  3687. }
  3688. }
  3689. else
  3690. {
  3691. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  3692. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3693. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3694. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  3695. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  3696. else
  3697. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  3698. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3699. result = PASS;
  3700. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3701. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3702. authorizeRetryTimes = 0;
  3703. return result;
  3704. }
  3705. }
  3706. //initialize struct Authorize
  3707. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  3708. //get data from shared memory
  3709. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3710. random_uuid(guid);
  3711. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  3712. LWS_Send(message);
  3713. sprintf(tempdata, "Authorize,%d", gun_index);
  3714. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3715. {
  3716. result = PASS;
  3717. DEBUG_INFO("Authorize mapItem pass\n");
  3718. }
  3719. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3720. return result;
  3721. }
  3722. int sendBootNotificationRequest(void)
  3723. {
  3724. mtrace();
  3725. int result = FAIL;
  3726. char message[500]={0}, payload[700]={0};
  3727. char guid[37]={0};
  3728. char tempdata[65]={0};
  3729. // Fill BootNotification fields
  3730. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  3731. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  3732. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3733. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3734. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  3735. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  3736. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  3737. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  3738. ShmOCPP16Data->ChargeBoxId
  3739. ,ShmSysConfigAndInfo->SysConfig.ModelName
  3740. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  3741. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  3742. ,ShmOCPP16Data->BootNotification.CpFwVersion
  3743. ,ShmOCPP16Data->BootNotification.CpIccid
  3744. ,ShmOCPP16Data->BootNotification.CpImsi);
  3745. random_uuid(guid);
  3746. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  3747. LWS_Send(message);
  3748. sprintf(tempdata, "BootNotification,0");
  3749. 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*/)
  3750. {
  3751. result = PASS;
  3752. }
  3753. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3754. strcpy(queuedata,message);
  3755. return result;
  3756. }
  3757. int sendDataTransferRequest(int gun_index)
  3758. {
  3759. mtrace();
  3760. char message[1000]={0};
  3761. char guid[37]={0};
  3762. char tempdata[65]={0};
  3763. int result = FAIL;
  3764. random_uuid(guid);
  3765. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  3766. MESSAGE_TYPE_CALL,
  3767. guid,
  3768. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  3769. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  3770. ShmOCPP16Data->DataTransfer[gun_index].Data);
  3771. LWS_Send(message);
  3772. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  3773. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3774. {
  3775. result = PASS;
  3776. DEBUG_INFO("DataTransfer mapItem pass\n");
  3777. }
  3778. return result;
  3779. }
  3780. int sendDiagnosticsStatusNotificationRequest(char *status)
  3781. {
  3782. mtrace();
  3783. int result = FAIL;
  3784. char message[110]={0};
  3785. char guid[37]={0};
  3786. char tempdata[65]={0};
  3787. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  3788. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  3789. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  3790. random_uuid(guid);
  3791. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  3792. LWS_SendNow(message);
  3793. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  3794. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3795. {
  3796. result = PASS;
  3797. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  3798. }
  3799. //#ifdef SystemLogMessage
  3800. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  3801. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3802. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  3803. //#endif
  3804. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  3805. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  3806. //record status
  3807. if(strcmp(status,"Idle")==0)
  3808. {
  3809. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  3810. }
  3811. else if(strcmp(status,"Uploaded")==0)
  3812. {
  3813. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  3814. }
  3815. else if(strcmp(status,"UploadFailed")==0)
  3816. {
  3817. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  3818. }
  3819. else if(strcmp(status,"Uploading")==0)
  3820. {
  3821. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  3822. }
  3823. return result;
  3824. }
  3825. int sendFirmwareStatusNotificationRequest(char *status)
  3826. {
  3827. mtrace();
  3828. int result = FAIL;
  3829. char message[110]={0};
  3830. char guid[37]={0};
  3831. char tempdata[65]={0};
  3832. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  3833. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  3834. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  3835. random_uuid(guid);
  3836. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  3837. LWS_SendNow(message);
  3838. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  3839. 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*/)
  3840. {
  3841. result = PASS;
  3842. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  3843. }
  3844. //#ifdef SystemLogMessage
  3845. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  3846. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3847. //#endif
  3848. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  3849. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  3850. //record status
  3851. if(strcmp(status,"Downloaded")==0)
  3852. {
  3853. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  3854. }
  3855. else if(strcmp(status,"DownloadFailed")==0)
  3856. {
  3857. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  3858. }
  3859. else if(strcmp(status,"Downloading")==0)
  3860. {
  3861. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  3862. }
  3863. else if(strcmp(status,"Idle")==0)
  3864. {
  3865. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  3866. }
  3867. else if(strcmp(status,"InstallationFailed")==0)
  3868. {
  3869. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  3870. }
  3871. else if(strcmp(status,"Installing")==0)
  3872. {
  3873. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  3874. }
  3875. else if(strcmp(status,"Installed")==0)
  3876. {
  3877. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  3878. }
  3879. return result;
  3880. }
  3881. int sendHeartbeatRequest(int gun_index)
  3882. {
  3883. mtrace();
  3884. int result = FAIL;
  3885. char message[80]={0};
  3886. char guid[37]={0};
  3887. char tempdata[65]={0};
  3888. random_uuid(guid);
  3889. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  3890. , MESSAGE_TYPE_CALL
  3891. , guid );
  3892. LWS_Send(message);
  3893. sprintf(tempdata, "Heartbeat,%d", 0);
  3894. 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*/)
  3895. {
  3896. result = PASS;
  3897. }
  3898. return result;
  3899. }
  3900. int sendStartTransactionRequest(int gun_index)
  3901. {
  3902. mtrace();
  3903. int result = FAIL;
  3904. char message[250]={0};
  3905. char guid[37]={0};
  3906. struct timeval tmnow;
  3907. struct tm *tm;
  3908. char buf[28];//, usec_buf[6];
  3909. char tempdata[65]={0};
  3910. int tempIndex = 0;
  3911. DEBUG_INFO("sendStartTransactionRequest...\n");
  3912. gettimeofday(&tmnow, NULL);
  3913. time_t t;
  3914. t = time(NULL);
  3915. /*UTC time and date*/
  3916. tm = gmtime(&t);
  3917. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3918. #if 0 // remove temporally
  3919. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3920. strcat(buf,".");
  3921. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3922. strcat(buf,usec_buf);
  3923. #endif
  3924. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  3925. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  3926. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3927. // clear StartTransaction Response
  3928. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  3929. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  3930. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  3931. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  3932. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3933. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3934. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3935. {
  3936. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3937. {
  3938. tempIndex = ((gun_index==2) ? 1: 0);
  3939. }
  3940. else
  3941. {
  3942. tempIndex = gun_index;
  3943. }
  3944. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3945. {
  3946. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3947. {
  3948. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3949. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  3950. }
  3951. }
  3952. }
  3953. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3954. {
  3955. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3956. {
  3957. tempIndex = ((gun_index==2) ? 1: 0);
  3958. }
  3959. else
  3960. {
  3961. tempIndex = gun_index;
  3962. }
  3963. for (int index = 0; index < CCS_QUANTITY; index++)
  3964. {
  3965. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3966. {
  3967. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3968. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  3969. }
  3970. }
  3971. }
  3972. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3973. {
  3974. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3975. {
  3976. tempIndex = ((gun_index==2) ? 1: 0);
  3977. }
  3978. else
  3979. {
  3980. tempIndex = gun_index;
  3981. }
  3982. for (int index = 0; index < GB_QUANTITY; index++)
  3983. {
  3984. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3985. {
  3986. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3987. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3988. }
  3989. }
  3990. }
  3991. else if(gunType[gun_index] == GUN_TYPE_DO)
  3992. {
  3993. tempIndex = gun_index;
  3994. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3995. {
  3996. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3997. {
  3998. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3999. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4000. }
  4001. }
  4002. }
  4003. else
  4004. {
  4005. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4006. {
  4007. tempIndex = 2;
  4008. }
  4009. else
  4010. {
  4011. tempIndex = gun_index;
  4012. }
  4013. for (int index = 0; index < AC_QUANTITY; index++)
  4014. {
  4015. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4016. {
  4017. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4018. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4019. }
  4020. }
  4021. }
  4022. random_uuid(guid);
  4023. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4024. {
  4025. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4026. , gun_index +1
  4027. , MESSAGE_TYPE_CALL
  4028. , guid
  4029. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4030. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4031. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4032. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4033. }
  4034. else
  4035. {
  4036. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4037. , gun_index +1
  4038. , MESSAGE_TYPE_CALL
  4039. , guid
  4040. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4041. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4042. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4043. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  4044. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4045. }
  4046. #if 1
  4047. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4048. 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*/)
  4049. {
  4050. result = PASS;
  4051. }
  4052. #endif
  4053. strcpy(queuedata, message);
  4054. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4055. OCPP_insert_transaction_msg(YES, queuedata);
  4056. return result;
  4057. }
  4058. int sendStatusNotificationRequest(int gun_index)
  4059. {
  4060. mtrace();
  4061. int result = FAIL;
  4062. char message[600]={0};
  4063. char guid[37];
  4064. int currentStatus = 0;
  4065. struct timeval tmnow;
  4066. struct tm *tm;
  4067. char buf[28];//, usec_buf[6];
  4068. char tempdata[65]={0};
  4069. int tempIndex = 0;
  4070. uint8_t isStateChanged = TRUE;
  4071. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4072. gettimeofday(&tmnow, NULL);
  4073. time_t t;
  4074. t = time(NULL);
  4075. /*UTC time and date*/
  4076. tm = gmtime(&t);
  4077. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4078. #if 0 // remove temporally
  4079. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4080. strcat(buf,".");
  4081. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4082. strcat(buf,usec_buf);
  4083. #endif
  4084. //printf("%s",buf);
  4085. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4086. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4087. // it's option
  4088. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  4089. /*
  4090. enum _SYSTEM_STATUS
  4091. {
  4092. S_BOOTING = 0,
  4093. S_IDLE, = 1
  4094. S_AUTHORIZING, =2
  4095. S_REASSIGN_CHECK, =3
  4096. S_REASSIGN, =4
  4097. S_PRECHARGE, =5
  4098. S_PREPARING_FOR_EV, =6
  4099. S_PREPARING_FOR_EVSE, =7
  4100. S_CHARGING, =8
  4101. S_TERMINATING, =9
  4102. S_COMPLETE, =10
  4103. S_ALARM, =11
  4104. S_FAULT =12
  4105. }
  4106. */
  4107. //check Transaction active
  4108. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4109. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4110. {
  4111. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4112. {
  4113. tempIndex = ((gun_index==2) ? 1: 0);
  4114. }
  4115. else
  4116. {
  4117. tempIndex = gun_index;
  4118. }
  4119. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4120. {
  4121. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4122. {
  4123. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4124. {
  4125. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4126. {
  4127. currentStatus = Preparing; //OCPP Status: Preparing
  4128. }
  4129. else
  4130. {
  4131. currentStatus = Available; //OCPP Status: Available
  4132. }
  4133. }
  4134. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4135. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4136. ) //S_PRECHARGE
  4137. {
  4138. currentStatus = Preparing; //OCPP Status: Preparing
  4139. }
  4140. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4141. {
  4142. currentStatus = Charging; //OCPP Status: Charging
  4143. }
  4144. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4145. {
  4146. currentStatus = Finishing; //OCPP Status: Finishing
  4147. }
  4148. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4149. {
  4150. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4151. }
  4152. 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
  4153. {
  4154. currentStatus = Unavailable; //OCPP Status: Unavailable
  4155. }
  4156. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4157. {
  4158. currentStatus = Faulted; //OCPP Status: Faulted
  4159. }
  4160. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4161. {
  4162. currentStatus = Reserved; //OCPP Status: Reserved
  4163. }
  4164. } //end of the same index
  4165. }//end of for CHAdeMO_QUANTITY
  4166. }
  4167. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4168. {
  4169. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4170. {
  4171. tempIndex = ((gun_index==2) ? 1: 0);
  4172. }
  4173. else
  4174. {
  4175. tempIndex = gun_index;
  4176. }
  4177. for (int index = 0; index < CCS_QUANTITY; index++)
  4178. {
  4179. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4180. {
  4181. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4182. {
  4183. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4184. {
  4185. currentStatus = Preparing; //OCPP Status: Preparing
  4186. }
  4187. else
  4188. {
  4189. currentStatus = Available; //OCPP Status: Available
  4190. }
  4191. }
  4192. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4193. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4194. ) //S_PRECHARGE
  4195. {
  4196. currentStatus = Preparing; //OCPP Status: Preparing
  4197. }
  4198. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4199. {
  4200. currentStatus = Charging; //OCPP Status: Charging
  4201. }
  4202. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4203. {
  4204. currentStatus = Finishing; //OCPP Status: Finishing
  4205. }
  4206. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4207. {
  4208. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4209. }
  4210. 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
  4211. {
  4212. currentStatus = Unavailable; //OCPP Status : Unavailable
  4213. }
  4214. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4215. {
  4216. currentStatus = Faulted; //OCPP Status: Faulted
  4217. }
  4218. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4219. {
  4220. currentStatus = Reserved; //OCPP Status: Reserved
  4221. }
  4222. } //end of the same index
  4223. } // end of for CCS_QUANTITY
  4224. }
  4225. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4226. {
  4227. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4228. {
  4229. tempIndex = ((gun_index==2) ? 1: 0);
  4230. }
  4231. else
  4232. {
  4233. tempIndex = gun_index;
  4234. }
  4235. for (int index = 0; index < GB_QUANTITY; index++)
  4236. {
  4237. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4238. {
  4239. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4240. {
  4241. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4242. {
  4243. currentStatus = Preparing; //OCPP Status: Preparing
  4244. }
  4245. else
  4246. {
  4247. currentStatus = Available; //OCPP Status: Available
  4248. }
  4249. }
  4250. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4251. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4252. ) //S_PRECHARGE
  4253. {
  4254. currentStatus = Preparing; //OCPP Status: Preparing
  4255. }
  4256. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4257. {
  4258. currentStatus = Charging; //OCPP Status: Charging
  4259. }
  4260. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4261. {
  4262. currentStatus = Finishing; //OCPP Status: Finishing
  4263. }
  4264. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4265. {
  4266. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4267. }
  4268. 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
  4269. {
  4270. currentStatus = Unavailable; //OCPP Status: Unavailable
  4271. }
  4272. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4273. {
  4274. currentStatus = Faulted; //OCPP Status: Faulted
  4275. }
  4276. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4277. {
  4278. currentStatus = Reserved; //OCPP Status: Reserved
  4279. }
  4280. } //end of the same index
  4281. } // end of for GB_QUANTITY
  4282. }
  4283. else if(gunType[gun_index] == GUN_TYPE_DO)
  4284. {
  4285. tempIndex = gun_index;
  4286. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4287. {
  4288. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4289. {
  4290. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4291. {
  4292. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4293. {
  4294. currentStatus = Preparing; //OCPP Status: Preparing
  4295. }
  4296. else
  4297. {
  4298. currentStatus = Available; //OCPP Status: Available
  4299. }
  4300. }
  4301. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4302. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4303. ) //S_PRECHARGE
  4304. {
  4305. currentStatus = Preparing; //OCPP Status: Preparing
  4306. }
  4307. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4308. {
  4309. currentStatus = Charging; //OCPP Status: Charging
  4310. }
  4311. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4312. {
  4313. currentStatus = Finishing; //OCPP Status: Finishing
  4314. }
  4315. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4316. {
  4317. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4318. }
  4319. 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
  4320. {
  4321. currentStatus = Unavailable; //OCPP Status: Unavailable
  4322. }
  4323. 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
  4324. {
  4325. currentStatus = Faulted; //OCPP Status: Faulted
  4326. }
  4327. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4328. {
  4329. currentStatus = Reserved; //OCPP Status: Reserved
  4330. }
  4331. } //end of the same index
  4332. }
  4333. }
  4334. else
  4335. {
  4336. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4337. {
  4338. tempIndex = 2;
  4339. }
  4340. else
  4341. {
  4342. tempIndex = gun_index;
  4343. }
  4344. for (int index = 0; index < AC_QUANTITY; index++)
  4345. {
  4346. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4347. {
  4348. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4349. {
  4350. 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))
  4351. {
  4352. currentStatus = Preparing; //OCPP Status: Preparing
  4353. }
  4354. else
  4355. {
  4356. currentStatus = Available; //OCPP Status: Available
  4357. }
  4358. }
  4359. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4360. {
  4361. currentStatus = Preparing; //OCPP Status: Preparing
  4362. }
  4363. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4364. {
  4365. currentStatus = Charging; //OCPP Status: Charging
  4366. }
  4367. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4368. {
  4369. currentStatus = Finishing; //OCPP Status: Finishing
  4370. }
  4371. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4372. {
  4373. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4374. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4375. else
  4376. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4377. }
  4378. 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
  4379. {
  4380. currentStatus = Unavailable; //OCPP Status: Unavailable
  4381. }
  4382. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4383. {
  4384. currentStatus = Faulted; //OCPP Status: Faulted
  4385. }
  4386. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4387. {
  4388. currentStatus = Reserved; //OCPP Status: Reserved
  4389. }
  4390. }//end of the same index
  4391. }//end of for AC_QUANTITY
  4392. }
  4393. //it's option
  4394. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4395. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  4396. {
  4397. isStateChanged = FALSE;
  4398. }
  4399. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4400. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  4401. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4402. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  4403. random_uuid(guid);
  4404. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  4405. , MESSAGE_TYPE_CALL
  4406. , guid
  4407. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  4408. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  4409. , ShmOCPP16Data->StatusNotification[gun_index].Info
  4410. , ShmOCPP16Data->StatusNotification[gun_index].Status
  4411. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  4412. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  4413. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  4414. if((server_sign == TRUE) && isStateChanged)
  4415. {
  4416. LWS_Send(message);
  4417. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  4418. 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*/)
  4419. {
  4420. //DEBUG_ERROR("statusNotification mapitem pass");
  4421. result = PASS;
  4422. }
  4423. }
  4424. else
  4425. {
  4426. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  4427. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4428. result = PASS;
  4429. }
  4430. return result;
  4431. }
  4432. int sendStopTransactionRequest(int gun_index)
  4433. {
  4434. mtrace();
  4435. int result = FAIL;
  4436. //char message[1500]={0};
  4437. char guid[37]={0};
  4438. char tempdata[65]={0};
  4439. int tempIndex = 0;
  4440. char TempStopTransaction[256];
  4441. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  4442. //int idx_sample=0;
  4443. DEBUG_INFO("sendStopTransactionRequest \n");
  4444. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4445. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  4446. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  4447. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4448. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4449. {
  4450. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4451. {
  4452. tempIndex = ((gun_index==2) ? 1: 0);
  4453. }
  4454. else
  4455. {
  4456. tempIndex = gun_index;
  4457. }
  4458. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4459. {
  4460. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4461. {
  4462. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4463. }
  4464. }// END OF CHAdeMO_QUANTITY
  4465. }
  4466. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4467. {
  4468. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4469. {
  4470. tempIndex = ((gun_index==2) ? 1: 0);
  4471. }
  4472. else
  4473. {
  4474. tempIndex = gun_index;
  4475. }
  4476. for (int index = 0; index < CCS_QUANTITY; index++)
  4477. {
  4478. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4479. {
  4480. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4481. }
  4482. }// END OF CCS_QUANTITY
  4483. }
  4484. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4485. {
  4486. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4487. {
  4488. tempIndex = ((gun_index==2) ? 1: 0);
  4489. }
  4490. else
  4491. {
  4492. tempIndex = gun_index;
  4493. }
  4494. for (int index = 0; index < GB_QUANTITY; index++)
  4495. {
  4496. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4497. {
  4498. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4499. }
  4500. }// END OF GB_QUANTITY
  4501. }
  4502. else if(gunType[gun_index] == GUN_TYPE_DO)
  4503. {
  4504. tempIndex = gun_index;
  4505. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4506. {
  4507. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4508. {
  4509. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4510. }
  4511. }// END OF GB_QUANTITY
  4512. }
  4513. else
  4514. {
  4515. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4516. {
  4517. tempIndex = 2;
  4518. }
  4519. else
  4520. {
  4521. tempIndex = gun_index;
  4522. }
  4523. for (int index = 0; index < AC_QUANTITY; index++)
  4524. {
  4525. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4526. {
  4527. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4528. }
  4529. }// END OF AC_QUANTITY
  4530. }
  4531. //====================================== Stop Transaction Time =====================================================
  4532. struct timeval tmnow;
  4533. struct tm *tm;
  4534. char buf[28];//, usec_buf[6];
  4535. gettimeofday(&tmnow, NULL);
  4536. time_t t;
  4537. t = time(NULL);
  4538. /*UTC time and date*/
  4539. tm = gmtime(&t);
  4540. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4541. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  4542. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  4543. random_uuid(guid);
  4544. /***********************************transactionData******************************************************/
  4545. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  4546. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  4547. //=================================
  4548. // Transaction_Begin
  4549. //=================================
  4550. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4551. {
  4552. //============================================ Energy.Active.Import.Interval ================================
  4553. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  4554. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4555. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  4556. 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*/]);
  4557. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4558. 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))
  4559. {
  4560. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  4561. }
  4562. else
  4563. {
  4564. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4565. }
  4566. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4567. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4568. }
  4569. //=================================
  4570. // Transaction_End
  4571. //=================================
  4572. // ================================= Current.Import L1 ===============================================
  4573. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4574. {
  4575. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4576. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4577. {
  4578. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4579. {
  4580. tempIndex = ((gun_index==2) ? 1: 0);
  4581. }
  4582. else
  4583. {
  4584. tempIndex = gun_index;
  4585. }
  4586. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4587. {
  4588. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4589. {
  4590. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4591. }
  4592. }// End of for CHAdeMO_QUANTITY
  4593. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4594. }
  4595. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4596. {
  4597. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4598. {
  4599. tempIndex = ((gun_index==2) ? 1: 0);
  4600. }
  4601. else
  4602. {
  4603. tempIndex = gun_index;
  4604. }
  4605. for (int index = 0; index < CCS_QUANTITY; index++)
  4606. {
  4607. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4608. {
  4609. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4610. }
  4611. }// End of for CCS_QUANTITY
  4612. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4613. }
  4614. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4615. {
  4616. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4617. {
  4618. tempIndex = ((gun_index==2) ? 1: 0);
  4619. }
  4620. else
  4621. {
  4622. tempIndex = gun_index;
  4623. }
  4624. for (int index = 0; index < GB_QUANTITY; index++)
  4625. {
  4626. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4627. {
  4628. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4629. }
  4630. }// End of for GB_QUANTITY
  4631. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4632. }
  4633. else if(gunType[gun_index] == GUN_TYPE_DO)
  4634. {
  4635. tempIndex = gun_index;
  4636. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4637. {
  4638. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4639. {
  4640. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4641. }
  4642. }
  4643. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4644. }
  4645. else
  4646. {
  4647. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4648. {
  4649. tempIndex = 2;
  4650. }
  4651. else
  4652. {
  4653. tempIndex = gun_index;
  4654. }
  4655. for (int index = 0; index < AC_QUANTITY; index++)
  4656. {
  4657. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4658. {
  4659. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4660. }
  4661. }// End of for AC_QUANTITY
  4662. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4663. }
  4664. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4665. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4666. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4667. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4668. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4669. }
  4670. // ================================= Energy.Active.Import.Interval ==============================================
  4671. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4672. {
  4673. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4674. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4675. {
  4676. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4677. {
  4678. tempIndex = ((gun_index==2) ? 1: 0);
  4679. }
  4680. else
  4681. {
  4682. tempIndex = gun_index;
  4683. }
  4684. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4685. {
  4686. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4687. {
  4688. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4689. }
  4690. }// END OF CHAdeMO_QUANTITY
  4691. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4692. }
  4693. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4694. {
  4695. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4696. {
  4697. tempIndex = ((gun_index==2) ? 1: 0);
  4698. }
  4699. else
  4700. {
  4701. tempIndex = gun_index;
  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[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4708. }
  4709. }// END OF CCS_QUANTITY
  4710. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4711. }
  4712. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4713. {
  4714. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4715. {
  4716. tempIndex = ((gun_index==2) ? 1: 0);
  4717. }
  4718. else
  4719. {
  4720. tempIndex = gun_index;
  4721. }
  4722. for (int index = 0; index < GB_QUANTITY; index++)
  4723. {
  4724. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4725. {
  4726. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4727. }
  4728. }// END OF GB_QUANTITY
  4729. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4730. }
  4731. else if(gunType[gun_index] == GUN_TYPE_DO)
  4732. {
  4733. tempIndex = gun_index;
  4734. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4735. {
  4736. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4737. {
  4738. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4739. }
  4740. }
  4741. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4742. }
  4743. else
  4744. {
  4745. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4746. {
  4747. tempIndex = 2;
  4748. }
  4749. else
  4750. {
  4751. tempIndex = gun_index;
  4752. }
  4753. for (int index = 0; index < AC_QUANTITY; index++)
  4754. {
  4755. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4756. {
  4757. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4758. }
  4759. }// END OF AC_QUANTITY
  4760. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  4761. }
  4762. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4763. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  4764. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  4765. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  4766. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4767. }
  4768. //=================================== Power.Active.Import ==================================================
  4769. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  4770. {
  4771. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4772. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4773. {
  4774. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4775. {
  4776. tempIndex = ((gun_index==2) ? 1: 0);
  4777. }
  4778. else
  4779. {
  4780. tempIndex = gun_index;
  4781. }
  4782. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4783. {
  4784. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4785. {
  4786. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4787. }
  4788. } // End for CHAdeMO_QUANTITY
  4789. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4790. }
  4791. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4792. {
  4793. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4794. {
  4795. tempIndex = ((gun_index==2) ? 1: 0);
  4796. }
  4797. else
  4798. {
  4799. tempIndex = gun_index;
  4800. }
  4801. for (int index = 0; index < CCS_QUANTITY; index++)
  4802. {
  4803. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4804. {
  4805. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4806. }
  4807. } // END for CCS_QUANTITY
  4808. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4809. }
  4810. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4811. {
  4812. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4813. {
  4814. tempIndex = ((gun_index==2) ? 1: 0);
  4815. }
  4816. else
  4817. {
  4818. tempIndex = gun_index;
  4819. }
  4820. for (int index = 0; index < GB_QUANTITY; index++)
  4821. {
  4822. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4823. {
  4824. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4825. }
  4826. }// END for GB_QUANTITY
  4827. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4828. }
  4829. else if(gunType[gun_index] == GUN_TYPE_DO)
  4830. {
  4831. tempIndex = gun_index;
  4832. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4833. {
  4834. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4835. {
  4836. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4837. }
  4838. }
  4839. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4840. }
  4841. else
  4842. {
  4843. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4844. {
  4845. tempIndex = 2;
  4846. }
  4847. else
  4848. {
  4849. tempIndex = gun_index;
  4850. }
  4851. for (int index = 0; index < AC_QUANTITY; index++)
  4852. {
  4853. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4854. {
  4855. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4856. }
  4857. } // END for AC_QUANTITY
  4858. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  4859. }
  4860. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4861. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  4862. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  4863. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  4864. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  4865. }
  4866. //============================ Voltage L1 ====================================
  4867. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4868. {
  4869. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4870. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4871. {
  4872. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4873. {
  4874. tempIndex = ((gun_index==2) ? 1: 0);
  4875. }
  4876. else
  4877. {
  4878. tempIndex = gun_index;
  4879. }
  4880. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4881. {
  4882. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4883. {
  4884. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4885. }
  4886. } // END OF FOR CHAdeMO_QUANTITY
  4887. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4888. }
  4889. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4890. {
  4891. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4892. {
  4893. tempIndex = ((gun_index==2) ? 1: 0);
  4894. }
  4895. else
  4896. {
  4897. tempIndex = gun_index;
  4898. }
  4899. for (int index = 0; index < CCS_QUANTITY; index++)
  4900. {
  4901. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4902. {
  4903. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4904. }
  4905. } // END OF FOR CCS_QUANTITY
  4906. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4907. }
  4908. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4909. {
  4910. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4911. {
  4912. tempIndex = ((gun_index==2) ? 1: 0);
  4913. }
  4914. else
  4915. {
  4916. tempIndex = gun_index;
  4917. }
  4918. for (int index = 0; index < GB_QUANTITY; index++)
  4919. {
  4920. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4921. {
  4922. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4923. }
  4924. } // END OF FOR GB_QUANTITY
  4925. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4926. }
  4927. else if(gunType[gun_index] == GUN_TYPE_DO)
  4928. {
  4929. tempIndex = gun_index;
  4930. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4931. {
  4932. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4933. {
  4934. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4935. }
  4936. }
  4937. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4938. }
  4939. else
  4940. {
  4941. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4942. {
  4943. tempIndex = 2;
  4944. }
  4945. else
  4946. {
  4947. tempIndex = gun_index;
  4948. }
  4949. for (int index = 0; index < AC_QUANTITY; index++)
  4950. {
  4951. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4952. {
  4953. 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
  4954. }
  4955. } // END OF FOR AC_QUANTITY
  4956. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  4957. }
  4958. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4959. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  4960. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  4961. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  4962. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4963. }
  4964. //====================== End SoC ================================
  4965. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4966. {
  4967. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4968. 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))
  4969. {
  4970. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4971. {
  4972. tempIndex = ((gun_index==2) ? 1: 0);
  4973. }
  4974. else
  4975. {
  4976. tempIndex = gun_index;
  4977. }
  4978. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4979. {
  4980. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4981. {
  4982. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4983. {
  4984. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  4985. }
  4986. }
  4987. }
  4988. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4989. {
  4990. for (int index = 0; index < CCS_QUANTITY; index++)
  4991. {
  4992. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4993. {
  4994. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  4995. }
  4996. }
  4997. }
  4998. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4999. {
  5000. for (int index = 0; index < GB_QUANTITY; index++)
  5001. {
  5002. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5003. {
  5004. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5005. }
  5006. }
  5007. }
  5008. else if(gunType[gun_index] == GUN_TYPE_DO)
  5009. {
  5010. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5011. {
  5012. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5013. {
  5014. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5015. }
  5016. }
  5017. }
  5018. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5019. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5020. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5021. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5022. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5023. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5024. } // END FOR DC CASE
  5025. }
  5026. // ================================= Current.Import L2 ===============================================
  5027. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5028. {
  5029. // AC 3 phse L2 current
  5030. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5031. {
  5032. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5033. {
  5034. tempIndex = 2;
  5035. }
  5036. else
  5037. {
  5038. tempIndex = gun_index;
  5039. }
  5040. for (int index = 0; index < AC_QUANTITY; index++)
  5041. {
  5042. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5043. {
  5044. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5045. }
  5046. }// End of for AC_QUANTITY
  5047. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5048. }
  5049. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5050. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5051. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5052. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5053. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5054. }
  5055. // ================================= Current.Import L3 ===============================================
  5056. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5057. {
  5058. // AC 3 phse L3 current
  5059. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5060. {
  5061. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5062. {
  5063. tempIndex = 2;
  5064. }
  5065. else
  5066. {
  5067. tempIndex = gun_index;
  5068. }
  5069. for (int index = 0; index < AC_QUANTITY; index++)
  5070. {
  5071. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5072. {
  5073. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5074. }
  5075. }// End of for AC_QUANTITY
  5076. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5077. }
  5078. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5079. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5081. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5082. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5083. }
  5084. //============================ Voltage L2 ====================================
  5085. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5086. {
  5087. // AC 3 phse L2 voltage
  5088. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5089. {
  5090. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5091. {
  5092. tempIndex = 2;
  5093. }
  5094. else
  5095. {
  5096. tempIndex = gun_index;
  5097. }
  5098. for (int index = 0; index < AC_QUANTITY; index++)
  5099. {
  5100. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5101. {
  5102. 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
  5103. }
  5104. } // END OF FOR AC_QUANTITY
  5105. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5106. }
  5107. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5108. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5109. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5110. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5111. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5112. }
  5113. //============================ Voltage L3 ====================================
  5114. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5115. {
  5116. // AC 3 phse L3 voltage
  5117. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5118. {
  5119. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5120. {
  5121. tempIndex = 2;
  5122. }
  5123. else
  5124. {
  5125. tempIndex = gun_index;
  5126. }
  5127. for (int index = 0; index < AC_QUANTITY; index++)
  5128. {
  5129. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5130. {
  5131. 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
  5132. }
  5133. } // END OF FOR AC_QUANTITY
  5134. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5135. }
  5136. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5137. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5138. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5139. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5140. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5141. }
  5142. //====================== Start SoC ================================
  5143. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  5144. {
  5145. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5146. 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))
  5147. {
  5148. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5149. {
  5150. tempIndex = ((gun_index==2) ? 1: 0);
  5151. }
  5152. else
  5153. {
  5154. tempIndex = gun_index;
  5155. }
  5156. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5157. {
  5158. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5159. {
  5160. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5161. {
  5162. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5163. }
  5164. }
  5165. }
  5166. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5167. {
  5168. for (int index = 0; index < CCS_QUANTITY; index++)
  5169. {
  5170. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5171. {
  5172. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5173. }
  5174. }
  5175. }
  5176. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5177. {
  5178. for (int index = 0; index < GB_QUANTITY; index++)
  5179. {
  5180. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5181. {
  5182. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5183. }
  5184. }
  5185. }
  5186. else if(gunType[gun_index] == GUN_TYPE_DO)
  5187. {
  5188. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5189. {
  5190. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5191. {
  5192. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5193. }
  5194. }
  5195. }
  5196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5198. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5202. } // END FOR DC CASE
  5203. }
  5204. //================================================ Message create ====================================================
  5205. json_object *StopTransaction = json_object_new_object();
  5206. json_object *transactionDatas = json_object_new_array();
  5207. json_object *sampledValues = json_object_new_array();
  5208. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  5209. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  5210. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  5211. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  5212. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  5213. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  5214. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  5215. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  5216. {
  5217. json_object *transactionData = json_object_new_object();
  5218. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5219. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5220. {
  5221. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5222. {
  5223. json_object *sampledValue = json_object_new_object();
  5224. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5225. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5226. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5227. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5228. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5229. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5230. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5231. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5232. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5233. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5234. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5235. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5236. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5237. json_object_array_add(sampledValues, sampledValue);
  5238. }
  5239. }
  5240. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5241. json_object_array_add(transactionDatas, transactionData);
  5242. }
  5243. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5244. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5245. ,MESSAGE_TYPE_CALL
  5246. ,guid
  5247. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5248. json_object_put(StopTransaction);
  5249. #if 1 // for TempStopTransaction
  5250. //Delete TempStopTransaction
  5251. if((access(TempStopTransaction,F_OK))!=-1)
  5252. {
  5253. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5254. }
  5255. #endif
  5256. #if 1
  5257. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5258. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5259. {
  5260. result = PASS;
  5261. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5262. }
  5263. #endif
  5264. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5265. OCPP_insert_transaction_msg(NO, queuedata);
  5266. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5267. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  5268. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  5269. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5270. {
  5271. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  5272. }
  5273. //for test
  5274. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5275. return result;
  5276. }
  5277. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5278. {
  5279. mtrace();
  5280. int result = FAIL;
  5281. char guid[37]={0};
  5282. char tempdata[65]={0};
  5283. int tempIndex = 0;
  5284. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5285. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5286. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5287. //set value
  5288. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5289. 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) )?
  5290. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  5291. -1);
  5292. random_uuid(guid);
  5293. //UTC Date time
  5294. struct timeval tmnow;
  5295. struct tm *tm;
  5296. char buf[28];//, usec_buf[6];
  5297. gettimeofday(&tmnow, NULL);
  5298. time_t t;
  5299. t = time(NULL);
  5300. /*UTC time and date*/
  5301. tm = gmtime(&t);
  5302. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5303. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5304. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5305. //********************************(1)Current.Import L1************************************************/
  5306. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5307. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5308. (dataType == ReadingContext_Trigger))
  5309. {
  5310. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5311. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5312. {
  5313. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5314. {
  5315. tempIndex = ((gun_index==2) ? 1: 0);
  5316. }
  5317. else
  5318. {
  5319. tempIndex = gun_index;
  5320. }
  5321. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5322. {
  5323. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5324. {
  5325. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5326. }
  5327. }
  5328. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5329. }
  5330. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5331. {
  5332. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5333. {
  5334. tempIndex = ((gun_index==2) ? 1: 0);
  5335. }
  5336. else
  5337. {
  5338. tempIndex = gun_index;
  5339. }
  5340. for (int index = 0; index < CCS_QUANTITY; index++)
  5341. {
  5342. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5343. {
  5344. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5345. }
  5346. }
  5347. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5348. }
  5349. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5350. {
  5351. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5352. {
  5353. tempIndex = ((gun_index==2) ? 1: 0);
  5354. }
  5355. else
  5356. {
  5357. tempIndex = gun_index;
  5358. }
  5359. for (int index = 0; index < GB_QUANTITY; index++)
  5360. {
  5361. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5362. {
  5363. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5364. }
  5365. }
  5366. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5367. }
  5368. else if(gunType[gun_index] == GUN_TYPE_DO)
  5369. {
  5370. tempIndex = gun_index;
  5371. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5372. {
  5373. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5374. {
  5375. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5376. }
  5377. }
  5378. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5379. }
  5380. else
  5381. {
  5382. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5383. {
  5384. tempIndex = 2;
  5385. }
  5386. else
  5387. {
  5388. tempIndex = gun_index;
  5389. }
  5390. for (int index = 0; index < AC_QUANTITY; index++)
  5391. {
  5392. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5393. {
  5394. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  5395. }
  5396. }
  5397. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  5398. }
  5399. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  5400. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  5401. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  5402. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  5403. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5404. }
  5405. //********************************(2)Energy.Active.Import.Register ************************************************/
  5406. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  5407. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  5408. (dataType == ReadingContext_Trigger))
  5409. {
  5410. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5411. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5412. {
  5413. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5414. {
  5415. tempIndex = ((gun_index==2) ? 1: 0);
  5416. }
  5417. else
  5418. {
  5419. tempIndex = gun_index;
  5420. }
  5421. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5422. {
  5423. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5424. {
  5425. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  5426. }
  5427. }
  5428. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5429. }
  5430. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5431. {
  5432. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5433. {
  5434. tempIndex = ((gun_index==2) ? 1: 0);
  5435. }
  5436. else
  5437. {
  5438. tempIndex = gun_index;
  5439. }
  5440. for (int index = 0; index < CCS_QUANTITY; index++)
  5441. {
  5442. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5443. {
  5444. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  5445. }
  5446. }
  5447. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5448. }
  5449. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5450. {
  5451. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5452. {
  5453. tempIndex = ((gun_index==2) ? 1: 0);
  5454. }
  5455. else
  5456. {
  5457. tempIndex = gun_index;
  5458. }
  5459. for (int index = 0; index < GB_QUANTITY; index++)
  5460. {
  5461. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5462. {
  5463. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5464. }
  5465. }
  5466. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5467. }
  5468. else if(gunType[gun_index] == GUN_TYPE_DO)
  5469. {
  5470. tempIndex = gun_index;
  5471. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5472. {
  5473. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5474. {
  5475. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5476. }
  5477. }
  5478. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5479. }
  5480. else
  5481. {
  5482. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5483. {
  5484. tempIndex = 2;
  5485. }
  5486. else
  5487. {
  5488. tempIndex = gun_index;
  5489. }
  5490. for (int index = 0; index < AC_QUANTITY; index++)
  5491. {
  5492. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5493. {
  5494. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  5495. }
  5496. }
  5497. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  5498. }
  5499. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  5500. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  5501. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  5502. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  5503. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5504. }
  5505. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5506. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5507. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5508. (dataType == ReadingContext_Trigger))
  5509. {
  5510. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5511. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5512. {
  5513. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5514. {
  5515. tempIndex = ((gun_index==2) ? 1: 0);
  5516. }
  5517. else
  5518. {
  5519. tempIndex = gun_index;
  5520. }
  5521. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5522. {
  5523. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5524. {
  5525. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  5526. }
  5527. } // END OF FOR CHAdeMO_QUANTITY
  5528. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5529. }
  5530. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5531. {
  5532. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5533. {
  5534. tempIndex = ((gun_index==2) ? 1: 0);
  5535. }
  5536. else
  5537. {
  5538. tempIndex = gun_index;
  5539. }
  5540. for (int index = 0; index < CCS_QUANTITY; index++)
  5541. {
  5542. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5543. {
  5544. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  5545. }
  5546. } // END OF CCS_QUANTITY
  5547. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5548. }
  5549. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5550. {
  5551. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5552. {
  5553. tempIndex = ((gun_index==2) ? 1: 0);
  5554. }
  5555. else
  5556. {
  5557. tempIndex = gun_index;
  5558. }
  5559. for (int index = 0; index < GB_QUANTITY; index++)
  5560. {
  5561. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5562. {
  5563. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5564. }
  5565. } // END OF GB_QUANTITY
  5566. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5567. }
  5568. else if(gunType[gun_index] == GUN_TYPE_DO)
  5569. {
  5570. tempIndex = gun_index;
  5571. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5572. {
  5573. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5574. {
  5575. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5576. }
  5577. }
  5578. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5579. }
  5580. else
  5581. {
  5582. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5583. {
  5584. tempIndex = 2;
  5585. }
  5586. else
  5587. {
  5588. tempIndex = gun_index;
  5589. }
  5590. for (int index = 0; index < AC_QUANTITY; index++)
  5591. {
  5592. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5593. {
  5594. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5595. }
  5596. }
  5597. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5598. }
  5599. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5600. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5601. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5602. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5603. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5604. }
  5605. //********************************(4)Power.Active.Import************************************************/
  5606. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Power.Active.Import") != NULL)) ||
  5607. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Power.Active.Import") != NULL)) ||
  5608. (dataType == ReadingContext_Trigger))
  5609. {
  5610. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5611. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5612. {
  5613. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5614. {
  5615. tempIndex = ((gun_index==2) ? 1: 0);
  5616. }
  5617. else
  5618. {
  5619. tempIndex = gun_index;
  5620. }
  5621. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5622. {
  5623. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5624. {
  5625. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5626. }
  5627. } // END OF FOR
  5628. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5629. }
  5630. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5631. {
  5632. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5633. {
  5634. tempIndex = ((gun_index==2) ? 1: 0);
  5635. }
  5636. else
  5637. {
  5638. tempIndex = gun_index;
  5639. }
  5640. for (int index = 0; index < CCS_QUANTITY; index++)
  5641. {
  5642. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5643. {
  5644. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5645. }
  5646. }
  5647. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5648. }
  5649. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5650. {
  5651. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5652. {
  5653. tempIndex = ((gun_index==2) ? 1: 0);
  5654. }
  5655. else
  5656. {
  5657. tempIndex = gun_index;
  5658. }
  5659. for (int index = 0; index < GB_QUANTITY; index++)
  5660. {
  5661. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5662. {
  5663. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5664. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5665. }
  5666. }
  5667. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5668. }
  5669. else if(gunType[gun_index] == GUN_TYPE_DO)
  5670. {
  5671. tempIndex = gun_index;
  5672. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5673. {
  5674. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5675. {
  5676. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5677. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5678. }
  5679. }
  5680. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5681. }
  5682. else
  5683. {
  5684. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5685. {
  5686. tempIndex = 2;
  5687. }
  5688. else
  5689. {
  5690. tempIndex = gun_index;
  5691. }
  5692. for (int index = 0; index < AC_QUANTITY; index++)
  5693. {
  5694. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5695. {
  5696. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5697. }
  5698. }
  5699. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5700. }
  5701. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5702. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5703. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5704. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5705. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5706. }
  5707. //***********************************************(5)VOLTAGE L1******************************************************/
  5708. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5709. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5710. (dataType == ReadingContext_Trigger))
  5711. {
  5712. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5713. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5714. {
  5715. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5716. {
  5717. tempIndex = ((gun_index==2) ? 1: 0);
  5718. }
  5719. else
  5720. {
  5721. tempIndex = gun_index;
  5722. }
  5723. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5724. {
  5725. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5726. {
  5727. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5728. }
  5729. }
  5730. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5731. }
  5732. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5733. {
  5734. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5735. {
  5736. tempIndex = ((gun_index==2) ? 1: 0);
  5737. }
  5738. else
  5739. {
  5740. tempIndex = gun_index;
  5741. }
  5742. for (int index = 0; index < CCS_QUANTITY; index++)
  5743. {
  5744. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5745. {
  5746. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  5747. }
  5748. }
  5749. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5750. }
  5751. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5752. {
  5753. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5754. {
  5755. tempIndex = ((gun_index==2) ? 1: 0);
  5756. }
  5757. else
  5758. {
  5759. tempIndex = gun_index;
  5760. }
  5761. for (int index = 0; index < GB_QUANTITY; index++)
  5762. {
  5763. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5764. {
  5765. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  5766. }
  5767. }
  5768. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5769. }
  5770. else if(gunType[gun_index] == GUN_TYPE_DO)
  5771. {
  5772. tempIndex = gun_index;
  5773. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5774. {
  5775. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5776. {
  5777. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  5778. }
  5779. }
  5780. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5781. }
  5782. else
  5783. {
  5784. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5785. {
  5786. tempIndex = 2;
  5787. }
  5788. else
  5789. {
  5790. tempIndex = gun_index;
  5791. }
  5792. for (int index = 0; index < AC_QUANTITY; index++)
  5793. {
  5794. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5795. {
  5796. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  5797. }
  5798. }
  5799. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  5800. }
  5801. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  5802. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  5803. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  5804. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  5805. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5806. }
  5807. //***********************************************(6)SOC******************************************************/
  5808. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "SOC") != NULL)) ||
  5809. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "SOC") != NULL)) ||
  5810. (dataType == ReadingContext_Trigger))
  5811. {
  5812. 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))
  5813. {
  5814. //idx_sample=5;
  5815. //sampledValue = NULL;
  5816. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5817. {
  5818. tempIndex = ((gun_index==2) ? 1: 0);
  5819. }
  5820. else
  5821. {
  5822. tempIndex = gun_index;
  5823. }
  5824. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5825. {
  5826. //tempIndex = ((gun_index==2) ? 1: 0);
  5827. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5828. {
  5829. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5830. {
  5831. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  5832. }
  5833. }
  5834. }
  5835. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5836. {
  5837. //tempIndex = ((gun_index==2) ? 1: 0);
  5838. for (int index = 0; index < CCS_QUANTITY; index++)
  5839. {
  5840. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5841. {
  5842. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  5843. }
  5844. }
  5845. }
  5846. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5847. {
  5848. //tempIndex = ((gun_index==2) ? 1: 0);
  5849. for (int index = 0; index < GB_QUANTITY; index++)
  5850. {
  5851. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5852. {
  5853. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  5854. }
  5855. }
  5856. }
  5857. else if(gunType[gun_index] == GUN_TYPE_DO)
  5858. {
  5859. //tempIndex = ((gun_index==2) ? 1: 0);
  5860. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5861. {
  5862. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5863. {
  5864. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  5865. }
  5866. }
  5867. }
  5868. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  5869. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  5870. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  5871. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  5872. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  5873. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  5874. }
  5875. }
  5876. //********************************(7)Current.Import L2************************************************/
  5877. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5878. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5879. (dataType == ReadingContext_Trigger))
  5880. {
  5881. // Only for AC 3 phase
  5882. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5883. {
  5884. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5885. {
  5886. tempIndex = 2;
  5887. }
  5888. else
  5889. {
  5890. tempIndex = gun_index;
  5891. }
  5892. for (int index = 0; index < AC_QUANTITY; index++)
  5893. {
  5894. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5895. {
  5896. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  5897. }
  5898. }
  5899. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  5900. }
  5901. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  5902. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  5903. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  5904. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  5905. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5906. }
  5907. //********************************(8)Current.Import L3************************************************/
  5908. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5909. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5910. (dataType == ReadingContext_Trigger))
  5911. {
  5912. // Only for AC 3 phase
  5913. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5914. {
  5915. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5916. {
  5917. tempIndex = 2;
  5918. }
  5919. else
  5920. {
  5921. tempIndex = gun_index;
  5922. }
  5923. for (int index = 0; index < AC_QUANTITY; index++)
  5924. {
  5925. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5926. {
  5927. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  5928. }
  5929. }
  5930. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  5931. }
  5932. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  5933. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  5934. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  5935. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  5936. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5937. }
  5938. //***********************************************(9)VOLTAGE L2******************************************************/
  5939. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5940. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5941. (dataType == ReadingContext_Trigger))
  5942. {
  5943. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5944. {
  5945. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5946. {
  5947. tempIndex = 2;
  5948. }
  5949. else
  5950. {
  5951. tempIndex = gun_index;
  5952. }
  5953. for (int index = 0; index < AC_QUANTITY; index++)
  5954. {
  5955. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5956. {
  5957. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  5958. }
  5959. }
  5960. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  5961. }
  5962. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  5963. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  5964. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  5965. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  5966. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5967. }
  5968. //***********************************************(10)VOLTAGE L3******************************************************/
  5969. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5970. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5971. (dataType == ReadingContext_Trigger))
  5972. {
  5973. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5974. {
  5975. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5976. {
  5977. tempIndex = 2;
  5978. }
  5979. else
  5980. {
  5981. tempIndex = gun_index;
  5982. }
  5983. for (int index = 0; index < AC_QUANTITY; index++)
  5984. {
  5985. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5986. {
  5987. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  5988. }
  5989. }
  5990. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  5991. }
  5992. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  5993. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  5994. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  5995. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  5996. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5997. }
  5998. // Message create ====================================================================================================
  5999. if(TRUE)
  6000. {
  6001. json_object *MeterValueReq = json_object_new_object();
  6002. json_object *MeterValues = json_object_new_array();
  6003. json_object *sampledValues = json_object_new_array();
  6004. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  6005. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  6006. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  6007. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  6008. {
  6009. json_object *MeterValue = json_object_new_object();
  6010. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6011. {
  6012. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6013. {
  6014. json_object *sampledValue = json_object_new_object();
  6015. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6016. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6017. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6018. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6019. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6020. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6021. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6022. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6023. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6024. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6025. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6026. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6027. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6028. json_object_array_add(sampledValues, sampledValue);
  6029. }
  6030. }
  6031. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6032. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6033. json_object_array_add(MeterValues, MeterValue);
  6034. }
  6035. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6036. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6037. ,gun_index + 1
  6038. ,MESSAGE_TYPE_CALL
  6039. ,guid
  6040. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6041. json_object_put(MeterValueReq);
  6042. }
  6043. // Put request guid to hash map
  6044. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6045. 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*/)
  6046. {
  6047. result = PASS;
  6048. //DEBUG_INFO("MeterValues mapitem pass\n");
  6049. }
  6050. if((dataType != ReadingContext_Trigger) &&
  6051. (dataType != ReadingContext_Sample_Clock) &&
  6052. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  6053. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6054. else
  6055. {
  6056. if(FirstHeartBeat)
  6057. LWS_Send(queuedata +2);
  6058. }
  6059. return result;
  6060. }
  6061. int sendLogStatusNotificationRequest(char *status)
  6062. {
  6063. mtrace();
  6064. int result = PASS;
  6065. char message[4096]={0};
  6066. char guid[37]={0};
  6067. char tempdata[128]={0};
  6068. json_object *LogStatusNotification = json_object_new_object();
  6069. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6070. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  6071. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  6072. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  6073. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  6074. random_uuid(guid);
  6075. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6076. json_object_put(LogStatusNotification);
  6077. LWS_Send(message);
  6078. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6079. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6080. {
  6081. result = PASS;
  6082. }
  6083. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  6084. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  6085. return result;
  6086. }
  6087. int sendSecurityEventNotificationRequest()
  6088. {
  6089. mtrace();
  6090. int result = PASS;
  6091. char message[4096]={0};
  6092. char guid[37]={0};
  6093. char tempdata[128]={0};
  6094. json_object *SecurityEventNotification = json_object_new_object();
  6095. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6096. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  6097. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  6098. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  6099. random_uuid(guid);
  6100. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6101. json_object_put(SecurityEventNotification);
  6102. LWS_Send(message);
  6103. sprintf(tempdata, "SecurityEventNotification,0");
  6104. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6105. {
  6106. result = PASS;
  6107. }
  6108. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  6109. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  6110. return result;
  6111. }
  6112. int sendSignCertificateRequest()
  6113. {
  6114. mtrace();
  6115. int result = PASS;
  6116. char message[4096]={0};
  6117. char guid[37]={0};
  6118. char tempdata[128]={0};
  6119. json_object *SignCertificate = json_object_new_object();
  6120. DEBUG_INFO("sendSignCertificateRequest...\n");
  6121. // Read csr file content
  6122. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  6123. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  6124. char *line = NULL;
  6125. size_t len = 0;
  6126. while(getline(&line, &len, fp) != -1)
  6127. {
  6128. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6129. {
  6130. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  6131. }
  6132. }
  6133. fclose(fp);
  6134. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  6135. random_uuid(guid);
  6136. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6137. json_object_put(SignCertificate);
  6138. LWS_Send(message);
  6139. sprintf(tempdata, "SignCertificate,0");
  6140. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6141. {
  6142. result = PASS;
  6143. }
  6144. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  6145. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  6146. return result;
  6147. }
  6148. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6149. {
  6150. mtrace();
  6151. int result = PASS;
  6152. char message[110]={0};
  6153. char guid[37]={0};
  6154. char tempdata[65]={0};
  6155. json_object *FirmwareStatusNotification = json_object_new_object();
  6156. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6157. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6158. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  6159. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  6160. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  6161. random_uuid(guid);
  6162. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6163. json_object_put(FirmwareStatusNotification);
  6164. LWS_Send(message);
  6165. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6166. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6167. {
  6168. result = PASS;
  6169. }
  6170. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6171. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6172. return result;
  6173. }
  6174. //==========================================
  6175. // send confirm routine
  6176. //==========================================
  6177. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6178. {
  6179. mtrace();
  6180. int result = FAIL;
  6181. char message[100]={0};
  6182. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6183. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6184. LWS_Send(message);
  6185. result = TRUE;
  6186. return result;
  6187. }
  6188. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6189. {
  6190. mtrace();
  6191. int result = FAIL;
  6192. char message[100]={0};
  6193. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6194. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6195. LWS_Send(message);
  6196. result = TRUE;
  6197. return result;
  6198. }
  6199. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6200. {
  6201. mtrace();
  6202. int result = FAIL;
  6203. char message[100]={0};
  6204. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6205. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6206. LWS_Send(message);
  6207. result = TRUE;
  6208. return result;
  6209. }
  6210. int sendClearCacheConfirmation(char *uuid,char *payload)
  6211. {
  6212. mtrace();
  6213. int result = FAIL;
  6214. char message[500]={0};
  6215. DEBUG_INFO("sendClearCacheConfirmation...\n");
  6216. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6217. LWS_Send(message);
  6218. return result;
  6219. }
  6220. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  6221. {
  6222. mtrace();
  6223. int result = FAIL;
  6224. char message[500]={0};
  6225. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  6226. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6227. LWS_Send(message);
  6228. return result;
  6229. }
  6230. int sendDataTransferConfirmation(char *uuid,char *payload)
  6231. {
  6232. mtrace();
  6233. char statusStr[20]={0};
  6234. char dataStr[10]={0};
  6235. char sstr[20]={0};
  6236. int c = 0;
  6237. char *loc;
  6238. int result = FAIL;
  6239. DEBUG_INFO("sendDataTransferConfirmation...\n");
  6240. /**********************status**************************/
  6241. loc = strstr(payload, "status");
  6242. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6243. c = 0;
  6244. while (loc[3+strlen("status")+c] != '\"')
  6245. {
  6246. sstr[c] = loc[3+strlen("status")+c];
  6247. c++;
  6248. }
  6249. sstr[c] = '\0';
  6250. strcpy(statusStr, sstr);
  6251. /**********************data**************************/
  6252. loc = strstr(payload, "data");
  6253. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6254. c = 0;
  6255. while (loc[3+strlen("data")+c] != '\"')
  6256. {
  6257. sstr[c] = loc[3+strlen("data")+c];
  6258. c++;
  6259. }
  6260. sstr[c] = '\0';
  6261. strcpy(dataStr, sstr);
  6262. return result;
  6263. }
  6264. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  6265. {
  6266. mtrace();
  6267. int result = FAIL;
  6268. char message[1000]={0};
  6269. int CompositeScheduleIndex = 0;
  6270. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  6271. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  6272. if(nPeriod == 0)
  6273. {
  6274. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  6275. {
  6276. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  6277. ,MESSAGE_TYPE_CALLRESULT
  6278. ,uuid
  6279. ,payload
  6280. ,connectorIdInt);
  6281. }
  6282. else
  6283. {
  6284. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  6285. ,MESSAGE_TYPE_CALLRESULT
  6286. ,uuid
  6287. ,payload
  6288. ,connectorIdInt
  6289. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6290. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6291. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6292. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  6293. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  6294. }
  6295. }
  6296. else
  6297. {
  6298. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  6299. ,MESSAGE_TYPE_CALLRESULT
  6300. ,uuid
  6301. ,payload
  6302. ,connectorIdInt
  6303. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6304. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6305. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6306. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  6307. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  6308. {
  6309. if (idx_sample == 0)
  6310. {
  6311. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6312. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6313. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6314. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6315. }
  6316. else
  6317. {
  6318. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6319. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6320. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6321. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6322. }
  6323. }
  6324. sprintf(message + strlen(message), "]}}]");
  6325. }
  6326. LWS_Send(message);
  6327. result = TRUE;
  6328. return result;
  6329. }
  6330. int sendGetConfigurationConfirmation(char *uuid)
  6331. {
  6332. mtrace();
  6333. int result = FAIL;
  6334. int MaxKeySupported = 0;
  6335. int sentConfigurationNumber= 0;
  6336. int sentunConfigurationNumber= 0;
  6337. char message[4000]={0};
  6338. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  6339. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  6340. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  6341. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  6342. ,MESSAGE_TYPE_CALLRESULT
  6343. ,uuid );
  6344. //configuration key
  6345. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  6346. {
  6347. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  6348. {
  6349. if (sentConfigurationNumber == 0)
  6350. {
  6351. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6352. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6353. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6354. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6355. }
  6356. else
  6357. {
  6358. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6359. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6360. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6361. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6362. }
  6363. sentConfigurationNumber = sentConfigurationNumber + 1;
  6364. }
  6365. }
  6366. sprintf(message + strlen(message), "]");
  6367. if(UnknownKeynum != 0)
  6368. {
  6369. sprintf(message + strlen(message), ",\"unknownKey\":[");
  6370. //unkown key
  6371. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  6372. {
  6373. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  6374. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  6375. if(sentunConfigurationNumber == 0)
  6376. {
  6377. sprintf(message + strlen(message), "\"%s\""
  6378. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6379. }
  6380. else
  6381. {
  6382. sprintf(message + strlen(message), ",\"%s\""
  6383. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6384. }
  6385. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  6386. }
  6387. sprintf(message + strlen(message), "]");
  6388. }
  6389. sprintf(message + strlen(message), "}]");
  6390. LWS_Send(message);
  6391. return result;
  6392. }
  6393. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  6394. {
  6395. mtrace();
  6396. int result = FAIL;
  6397. char message[400]={0};
  6398. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  6399. if(strcmp(payload,"")==0)
  6400. {
  6401. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6402. }
  6403. else
  6404. {
  6405. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6406. }
  6407. LWS_Send(message);
  6408. result = TRUE;
  6409. return result;
  6410. }
  6411. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  6412. {
  6413. mtrace();
  6414. int result = FAIL;
  6415. char message[80]={0};
  6416. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  6417. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  6418. LWS_Send(message);
  6419. result = TRUE;
  6420. return result;
  6421. }
  6422. int sendRemoteStartConfirmation(char *uuid,char *payload)
  6423. {
  6424. mtrace();
  6425. int result = FAIL;
  6426. char message[80]={0};
  6427. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  6428. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6429. LWS_Send(message);
  6430. result = TRUE;
  6431. return result;
  6432. }
  6433. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  6434. {
  6435. mtrace();
  6436. int result = FAIL;
  6437. char message[80]={0};
  6438. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  6439. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6440. LWS_Send(message);
  6441. result = TRUE;
  6442. return result;
  6443. }
  6444. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  6445. {
  6446. mtrace();
  6447. int result = FAIL;
  6448. char message[80]={0};
  6449. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  6450. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  6451. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6452. LWS_Send(message);
  6453. result = TRUE;
  6454. return result;
  6455. }
  6456. int sendResetConfirmation(char *uuid,char *payload)
  6457. {
  6458. mtrace();
  6459. int result = FAIL;
  6460. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  6461. char message[80]={0};
  6462. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  6463. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6464. LWS_Send(message);
  6465. result = TRUE;
  6466. return result;
  6467. }
  6468. int sendSendLocalListConfirmation(char *uuid,char *payload)
  6469. {
  6470. mtrace();
  6471. int result = FAIL;
  6472. char message[500]={0};
  6473. // [ 3, "1571284266109", { "status": "Accepted" } ]
  6474. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6475. LWS_Send(message);
  6476. result = TRUE;
  6477. return result;
  6478. }
  6479. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  6480. {
  6481. mtrace();
  6482. int result = FAIL;
  6483. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  6484. char message[80]={0};
  6485. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  6486. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6487. LWS_Send(message);
  6488. result = TRUE;
  6489. return result;
  6490. }
  6491. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  6492. {
  6493. mtrace();
  6494. int result = FAIL;
  6495. char message[80]={0};
  6496. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  6497. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6498. LWS_Send(message);
  6499. result = TRUE;
  6500. return result;
  6501. }
  6502. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  6503. {
  6504. mtrace();
  6505. int result = FAIL;
  6506. char message[80]={0};
  6507. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6508. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  6509. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6510. LWS_Send(message);
  6511. result = TRUE;
  6512. return result;
  6513. }
  6514. int sendUpdateFirmwareConfirmation(char *uuid)
  6515. {
  6516. mtrace();
  6517. int result = FAIL;
  6518. char message[60]={0};
  6519. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6520. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  6521. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6522. LWS_Send(message);
  6523. result = TRUE;
  6524. return result;
  6525. }
  6526. int sendCertificateSignedConfirmation(char *uuid)
  6527. {
  6528. mtrace();
  6529. int result = PASS;
  6530. char message[4096]={0};
  6531. json_object *CertificateSigned = json_object_new_object();
  6532. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  6533. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  6534. sprintf(message,"[%d,\"%s\",%s]"
  6535. ,MESSAGE_TYPE_CALLRESULT
  6536. ,uuid
  6537. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  6538. json_object_put(CertificateSigned);
  6539. LWS_Send(message);
  6540. return result;
  6541. }
  6542. int sendDeleteCertificateConfirmation(char *uuid)
  6543. {
  6544. mtrace();
  6545. int result = PASS;
  6546. char message[4096]={0};
  6547. json_object *DeleteCertificate = json_object_new_object();
  6548. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  6549. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  6550. sprintf(message,"[%d,\"%s\",%s]"
  6551. ,MESSAGE_TYPE_CALLRESULT
  6552. ,uuid
  6553. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  6554. json_object_put(DeleteCertificate);
  6555. LWS_Send(message);
  6556. return result;
  6557. }
  6558. int sendExtendedTriggerMessageConfirmation(char *uuid)
  6559. {
  6560. mtrace();
  6561. int result = PASS;
  6562. char message[4096]={0};
  6563. json_object *ExtendedTriggerMessage = json_object_new_object();
  6564. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  6565. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  6566. sprintf(message,"[%d,\"%s\",%s]"
  6567. ,MESSAGE_TYPE_CALLRESULT
  6568. ,uuid
  6569. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  6570. json_object_put(ExtendedTriggerMessage);
  6571. LWS_Send(message);
  6572. return result;
  6573. }
  6574. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  6575. {
  6576. mtrace();
  6577. int result = PASS;
  6578. char message[4096]={0};
  6579. json_object *GetInstalledCertificateIds = json_object_new_object();
  6580. json_object *certificateHashDataDatas = json_object_new_array();
  6581. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  6582. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  6583. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  6584. {
  6585. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  6586. {
  6587. json_object *certificateHashData = json_object_new_object();
  6588. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  6589. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  6590. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  6591. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  6592. json_object_array_add(certificateHashDataDatas, certificateHashData);
  6593. }
  6594. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  6595. }
  6596. else
  6597. {
  6598. json_object_put(certificateHashDataDatas);
  6599. }
  6600. sprintf(message,"[%d,\"%s\",%s]"
  6601. ,MESSAGE_TYPE_CALLRESULT
  6602. ,uuid
  6603. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  6604. json_object_put(GetInstalledCertificateIds);
  6605. LWS_Send(message);
  6606. return result;
  6607. }
  6608. int sendGetLogConfirmation(char *uuid)
  6609. {
  6610. mtrace();
  6611. int result = PASS;
  6612. char message[4096]={0};
  6613. json_object *GetLog = json_object_new_object();
  6614. DEBUG_INFO("sendGetLogConfirmation...\n");
  6615. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  6616. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  6617. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  6618. sprintf(message,"[%d,\"%s\",%s]"
  6619. ,MESSAGE_TYPE_CALLRESULT
  6620. ,uuid
  6621. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  6622. json_object_put(GetLog);
  6623. LWS_Send(message);
  6624. return result;
  6625. }
  6626. int sendInstallCertificateConfirmation(char *uuid)
  6627. {
  6628. mtrace();
  6629. int result = PASS;
  6630. char message[4096]={0};
  6631. json_object *InstallCertificate = json_object_new_object();
  6632. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  6633. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  6634. sprintf(message,"[%d,\"%s\",%s]"
  6635. ,MESSAGE_TYPE_CALLRESULT
  6636. ,uuid
  6637. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  6638. json_object_put(InstallCertificate);
  6639. LWS_Send(message);
  6640. return result;
  6641. }
  6642. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  6643. {
  6644. mtrace();
  6645. int result = PASS;
  6646. char message[4096]={0};
  6647. json_object *SignedUpdateFirmware = json_object_new_object();
  6648. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  6649. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  6650. sprintf(message,"[%d,\"%s\",%s]"
  6651. ,MESSAGE_TYPE_CALLRESULT
  6652. ,uuid
  6653. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  6654. json_object_put(SignedUpdateFirmware);
  6655. LWS_Send(message);
  6656. return result;
  6657. }
  6658. int sendUnknownConfirmation(char *uuid)
  6659. {
  6660. mtrace();
  6661. int result = PASS;
  6662. char message[256]={0};
  6663. DEBUG_INFO("sendUnknownConfirmation...\n");
  6664. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  6665. LWS_Send(message);
  6666. return result;
  6667. }
  6668. //==========================================
  6669. // Handle server request routine Start
  6670. //==========================================
  6671. int handleCancelReservationRequest(char *uuid, char *payload)
  6672. {
  6673. mtrace();
  6674. int result = FAIL;
  6675. int gunNO = 0;
  6676. int reservationIdInt = -1;
  6677. char comfirmstr[20];
  6678. DEBUG_INFO("handleCancelReservationRequest...\n");
  6679. json_object *CancelReservation;
  6680. CancelReservation = json_tokener_parse(payload);
  6681. if(!is_error(CancelReservation))
  6682. {
  6683. // Required data
  6684. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  6685. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  6686. }
  6687. json_object_put(CancelReservation);
  6688. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  6689. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6690. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  6691. if(reservationIdInt != -1)
  6692. {
  6693. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6694. //check Transaction active
  6695. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6696. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6697. {
  6698. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  6699. {
  6700. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6701. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6702. if(gunType[2] == GUN_TYPE_CHAdeMO)
  6703. {
  6704. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  6705. }
  6706. else
  6707. {
  6708. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  6709. }
  6710. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6711. goto end;
  6712. }
  6713. }
  6714. for (int index = 0; index < CCS_QUANTITY; index++)
  6715. {
  6716. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  6717. {
  6718. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6719. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6720. if(gunType[2] == GUN_TYPE_CCS)
  6721. {
  6722. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  6723. }
  6724. else
  6725. {
  6726. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  6727. }
  6728. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6729. goto end;
  6730. }
  6731. }
  6732. for (int index = 0; index < GB_QUANTITY; index++)
  6733. {
  6734. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  6735. {
  6736. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6737. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6738. if(gunType[2] == GUN_TYPE_GBT)
  6739. {
  6740. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  6741. }
  6742. else
  6743. {
  6744. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  6745. }
  6746. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6747. goto end;
  6748. }
  6749. }
  6750. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6751. {
  6752. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  6753. {
  6754. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6755. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6756. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  6757. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6758. goto end;
  6759. }
  6760. }
  6761. for (int index = 0; index < AC_QUANTITY; index++)
  6762. {
  6763. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  6764. {
  6765. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6766. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6767. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6768. {
  6769. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  6770. }
  6771. else
  6772. {
  6773. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  6774. }
  6775. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6776. goto end;
  6777. }
  6778. }
  6779. }
  6780. //The reservationId does NOT match the reservationId
  6781. sendCancelReservationConfirmation(uuid, comfirmstr);
  6782. end:
  6783. // Fill in ocpp packet uuid
  6784. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  6785. return result;
  6786. }
  6787. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  6788. {
  6789. mtrace();
  6790. int result = FAIL;
  6791. int gunIndex = 0;
  6792. char typeStr[16]={0};
  6793. char comfirmstr[20];
  6794. int specificId = FALSE;
  6795. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  6796. json_object *ChangeAvailability;
  6797. ChangeAvailability = json_tokener_parse(payload);
  6798. if(!is_error(ChangeAvailability))
  6799. {
  6800. // Required data
  6801. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  6802. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  6803. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  6804. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  6805. }
  6806. json_object_put(ChangeAvailability);
  6807. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6808. {
  6809. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  6810. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  6811. }
  6812. else if(gunIndex == 0)
  6813. {
  6814. for(int i=0; i < gunTotalNumber; i++)
  6815. {
  6816. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  6817. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  6818. }
  6819. }
  6820. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6821. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6822. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  6823. {
  6824. specificId = TRUE;
  6825. }
  6826. if(specificId == FALSE)
  6827. goto end;
  6828. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  6829. {
  6830. //----------------------gunIndex is 0 ------------------------------------------------//
  6831. if(gunIndex == 0)
  6832. {
  6833. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6834. {
  6835. for(int i=0; i < gunTotalNumber; i++)
  6836. {
  6837. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6838. {
  6839. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  6840. {
  6841. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6842. {
  6843. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6844. goto end;
  6845. }
  6846. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6847. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6848. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6849. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6850. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6851. {
  6852. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6853. goto end;
  6854. }
  6855. }
  6856. }//END FOR CHAdeMO_QUANTITY
  6857. for (int index = 0; index < CCS_QUANTITY; index++)
  6858. {
  6859. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  6860. {
  6861. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  6862. {
  6863. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6864. goto end;
  6865. }
  6866. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6867. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6868. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6869. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6870. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6871. {
  6872. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6873. goto end;
  6874. }
  6875. }
  6876. }//END FOR CCS_QUANTITY
  6877. for (int index = 0; index < GB_QUANTITY; index++)
  6878. {
  6879. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  6880. {
  6881. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6882. {
  6883. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6884. goto end;
  6885. }
  6886. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6887. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6888. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6889. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6890. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6891. {
  6892. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6893. goto end;
  6894. }
  6895. }
  6896. }// END FOR GB_QUANTITY
  6897. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6898. {
  6899. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  6900. {
  6901. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6902. {
  6903. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6904. goto end;
  6905. }
  6906. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6907. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6908. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6909. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6910. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6911. {
  6912. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6913. goto end;
  6914. }
  6915. }
  6916. }// END FOR GENERAL_GUN_QUANTITY
  6917. for (int index = 0; index < AC_QUANTITY; index++)
  6918. {
  6919. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  6920. {
  6921. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6922. {
  6923. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6924. goto end;
  6925. }
  6926. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6927. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6928. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6929. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6930. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6931. {
  6932. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6933. goto end;
  6934. }
  6935. }
  6936. }//END FOR AC_QUANTITY
  6937. }// END FOR gunTotalNumber
  6938. }
  6939. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6940. {
  6941. for(int i=0; i < gunTotalNumber; i++)
  6942. {
  6943. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6944. {
  6945. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6946. goto end;
  6947. }
  6948. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6949. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  6950. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  6951. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  6952. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6953. {
  6954. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6955. goto end;
  6956. }
  6957. }
  6958. }
  6959. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6960. goto end;
  6961. }
  6962. //----------------------gunIndex is not 0 ------------------------------------------------//
  6963. //check Transaction active
  6964. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6965. {
  6966. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  6967. {
  6968. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  6969. {
  6970. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6971. goto end;
  6972. }
  6973. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6974. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6975. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6976. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6977. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6978. {
  6979. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6980. goto end;
  6981. }
  6982. else
  6983. {
  6984. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  6985. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6986. goto end;
  6987. }
  6988. }
  6989. }//END FOR CHAdeMO_QUANTITY
  6990. for (int index = 0; index < CCS_QUANTITY; index++)
  6991. {
  6992. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  6993. {
  6994. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  6995. {
  6996. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6997. goto end;
  6998. }
  6999. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7000. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7001. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7002. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7003. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7004. {
  7005. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7006. goto end;
  7007. }
  7008. else
  7009. {
  7010. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7011. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7012. goto end;
  7013. }
  7014. }
  7015. }//END FOR CCS_QUANTITY
  7016. for (int index = 0; index < GB_QUANTITY; index++)
  7017. {
  7018. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7019. {
  7020. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7021. {
  7022. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7023. goto end;
  7024. }
  7025. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7026. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7027. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7028. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7029. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7030. {
  7031. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7032. goto end;
  7033. }
  7034. else
  7035. {
  7036. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7037. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7038. goto end;
  7039. }
  7040. }
  7041. }// END FOR GB_QUANTITY
  7042. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7043. {
  7044. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7045. {
  7046. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7047. {
  7048. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7049. goto end;
  7050. }
  7051. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7052. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7053. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7054. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7055. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7056. {
  7057. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7058. goto end;
  7059. }
  7060. else
  7061. {
  7062. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7063. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7064. goto end;
  7065. }
  7066. }
  7067. }// END FOR GENERAL_GUN_QUANTITY
  7068. for (int index = 0; index < AC_QUANTITY; index++)
  7069. {
  7070. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7071. {
  7072. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7073. {
  7074. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7075. goto end;
  7076. }
  7077. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7078. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7079. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7080. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7081. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7082. {
  7083. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7084. goto end;
  7085. }
  7086. else
  7087. {
  7088. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7089. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7090. goto end;
  7091. }
  7092. }
  7093. }//END FOR AC_QUANTITY
  7094. }//END FOR AvailabilityTypeStr[Inoperative]
  7095. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7096. {
  7097. //----------------------gunIndex is 0 ------------------------------------------------//
  7098. if(gunIndex == 0)
  7099. {
  7100. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7101. {
  7102. for(int i=0; i < gunTotalNumber; i++)
  7103. {
  7104. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7105. {
  7106. 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
  7107. {
  7108. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7109. goto end;
  7110. }
  7111. }//END FOR CHAdeMO_QUANTITY
  7112. for (int index = 0; index < CCS_QUANTITY; index++)
  7113. {
  7114. 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
  7115. {
  7116. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7117. goto end;
  7118. }
  7119. }//END FOR CCS_QUANTITY
  7120. for (int index = 0; index < GB_QUANTITY; index++)
  7121. {
  7122. 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
  7123. {
  7124. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7125. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7126. goto end;
  7127. }
  7128. }// END FOR GB_QUANTITY
  7129. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7130. {
  7131. 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
  7132. {
  7133. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7134. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7135. goto end;
  7136. }
  7137. }// END FOR GENERAL_GUN_QUANTITY
  7138. for (int index = 0; index < AC_QUANTITY; index++)
  7139. {
  7140. 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
  7141. {
  7142. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7143. goto end;
  7144. }
  7145. }//END FOR CHAdeMO_QUANTITY
  7146. }// END FOR gunTotalNumber
  7147. }
  7148. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7149. {
  7150. for(int i=0; i < gunTotalNumber; i++)
  7151. {
  7152. for (int index = 0; index < AC_QUANTITY; index++)
  7153. {
  7154. 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
  7155. {
  7156. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7157. goto end;
  7158. }
  7159. }//END FOR CHAdeMO_QUANTITY
  7160. } // END FOR gunTotalNumber
  7161. }
  7162. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7163. goto end;
  7164. }
  7165. //----------------------gunIndex is not 0 ------------------------------------------------//
  7166. //check Transaction active
  7167. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7168. {
  7169. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7170. {
  7171. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7172. goto end;
  7173. }
  7174. }//END FOR CHAdeMO_QUANTITY
  7175. for (int index = 0; index < CCS_QUANTITY; index++)
  7176. {
  7177. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7178. {
  7179. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7180. goto end;
  7181. }
  7182. }//END FOR CCS_QUANTITY
  7183. for (int index = 0; index < GB_QUANTITY; index++)
  7184. {
  7185. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7186. {
  7187. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7188. goto end;
  7189. }
  7190. }// END FOR GB_QUANTITY
  7191. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7192. {
  7193. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7194. {
  7195. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7196. goto end;
  7197. }
  7198. }// END FOR GENERAL_GUN_QUANTITY
  7199. for (int index = 0; index < AC_QUANTITY; index++)
  7200. {
  7201. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7202. {
  7203. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7204. goto end;
  7205. }
  7206. }//END FOR AC_QUANTITY
  7207. }//END FOR AvailabilityTypeStr[Operative]
  7208. end:
  7209. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7210. {
  7211. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  7212. }
  7213. else
  7214. {
  7215. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  7216. }
  7217. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7218. {
  7219. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7220. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7221. }
  7222. else if(gunIndex == 0)
  7223. {
  7224. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7225. {
  7226. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  7227. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  7228. }
  7229. }
  7230. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  7231. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7232. return result;
  7233. }
  7234. int handleChangeConfigurationRequest(char *uuid, char *payload)
  7235. {
  7236. mtrace();
  7237. int result = FAIL;
  7238. char keystr[40]={0};
  7239. char valuestr[256]={0};
  7240. char comfirmstr[20]={0};
  7241. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  7242. json_object *ChangeConfiguration;
  7243. ChangeConfiguration = json_tokener_parse(payload);
  7244. if(!is_error(ChangeConfiguration))
  7245. {
  7246. // Required data
  7247. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  7248. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  7249. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  7250. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  7251. }
  7252. json_object_put(ChangeConfiguration);
  7253. if((uuid==NULL) || (payload ==NULL) )
  7254. {
  7255. DEBUG_ERROR("Payload is null\n");
  7256. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7257. }
  7258. else
  7259. {
  7260. int status = setKeyValue(keystr, valuestr);
  7261. switch(status)
  7262. {
  7263. case ConfigurationStatus_Accepted:
  7264. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  7265. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  7266. StoreConfigurationTable();
  7267. break;
  7268. case RebootRequired:
  7269. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  7270. StoreConfigurationTable();
  7271. break;
  7272. case NotSupported:
  7273. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  7274. break;
  7275. case ConfigurationStatus_Rejected:
  7276. default:
  7277. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7278. break;
  7279. }
  7280. }
  7281. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  7282. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  7283. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  7284. {
  7285. ChageWebSocketPingInterval(atoi(valuestr));
  7286. }
  7287. if(((strcmp(keystr,"AuthorizationKey")==0) || ((strcmp(keystr,"SecurityProfile")==0))) &&
  7288. (strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  7289. {
  7290. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7291. SetOcppConnStatus(FALSE);
  7292. }
  7293. return result;
  7294. }
  7295. int handleClearCacheRequest(char *uuid, char *payload)
  7296. {
  7297. mtrace();
  7298. int result = FAIL;
  7299. char comfirmstr[20];
  7300. char rmFileCmd[100]={0};
  7301. struct stat stats;
  7302. DEBUG_INFO("handleClearCacheRequest...\n");
  7303. stat("/Storage/OCPP", &stats);
  7304. // Check for directory existence
  7305. if (S_ISDIR(stats.st_mode) == 1)
  7306. {}
  7307. else
  7308. {
  7309. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  7310. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  7311. system(rmFileCmd);
  7312. }
  7313. if(OCPP_cleanLocalCache())
  7314. {
  7315. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  7316. }
  7317. else
  7318. {
  7319. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  7320. }
  7321. sendClearCacheConfirmation(uuid, comfirmstr);
  7322. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7323. return result;
  7324. }
  7325. int handleClearChargingProfileRequest(char *uuid, char *payload)
  7326. {
  7327. mtrace();
  7328. int result = FAIL;
  7329. int resultRename;
  7330. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  7331. char chargingProfilePurposeStr[26]={0};
  7332. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  7333. char tempchargingProfilePurposeStr[26]={0};
  7334. char str[100]={0};
  7335. char fname[200]={0};
  7336. char comfirmstr[20]={0};
  7337. char word[1600]={0};
  7338. int clearflag = FALSE;
  7339. int chargingProfileIdIsNULL = FALSE;
  7340. int connectorIsNULL = FALSE;
  7341. int chargingProfilePurposeIsNULL = FALSE;
  7342. int stackLevelIsNULL = FALSE;
  7343. //int GotoEnd = FALSE;
  7344. FILE *fptr1, *fptr2;
  7345. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  7346. int n_chargingProfile=0;
  7347. int isEmptyFile = FALSE;
  7348. char sLineWord[1600]={0};
  7349. char chargingProfiles[10][100]={0};
  7350. int ChargeProfileCount = 0;
  7351. int ch;
  7352. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  7353. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  7354. json_object *ClearChargingProfile;
  7355. ClearChargingProfile = json_tokener_parse(payload);
  7356. if(!is_error(ClearChargingProfile))
  7357. {
  7358. // Optional data
  7359. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  7360. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  7361. else
  7362. chargingProfileIdIsNULL = TRUE;
  7363. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  7364. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  7365. else
  7366. connectorIsNULL = TRUE;
  7367. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  7368. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  7369. else
  7370. chargingProfilePurposeIsNULL = TRUE;
  7371. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  7372. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  7373. else
  7374. stackLevelIsNULL = TRUE;
  7375. }
  7376. json_object_put(ClearChargingProfile);
  7377. if(connectorIsNULL == FALSE)
  7378. {
  7379. switch(connectorIdInt)
  7380. {
  7381. case 0:
  7382. if(chargingProfilePurposeIsNULL == TRUE)
  7383. {
  7384. int l = 0;
  7385. strcpy(fname, ChargePointMaxProfile_JSON);
  7386. if((access(fname,F_OK))!=-1)
  7387. {
  7388. strcpy(chargingProfiles[l], fname);
  7389. l = l + 1;
  7390. }
  7391. strcpy(fname, TxDefaultProfile_0_JSON);
  7392. if((access(fname,F_OK))!=-1)
  7393. {
  7394. strcpy(chargingProfiles[l], fname);
  7395. l = l + 1;
  7396. }
  7397. ChargeProfileCount = l;
  7398. }
  7399. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  7400. {
  7401. strcpy(fname, ChargePointMaxProfile_JSON);
  7402. if((access(fname,F_OK))!=-1)
  7403. {
  7404. strcpy(chargingProfiles[0], fname);
  7405. ChargeProfileCount = 1;
  7406. }
  7407. }
  7408. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7409. {
  7410. strcpy(fname, TxDefaultProfile_0_JSON);
  7411. if((access(fname,F_OK))!=-1)
  7412. {
  7413. strcpy(chargingProfiles[0], fname);
  7414. ChargeProfileCount = 1;
  7415. }
  7416. }
  7417. break;
  7418. default:
  7419. if(chargingProfilePurposeIsNULL == TRUE)
  7420. {
  7421. int m = 0;
  7422. memset(fname, 0, ARRAY_SIZE(fname));
  7423. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  7424. if((access(fname,F_OK))!=-1)
  7425. {
  7426. strcpy(chargingProfiles[m], fname);
  7427. m = m + 1;
  7428. }
  7429. memset(fname, 0, ARRAY_SIZE(fname));
  7430. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7431. if((access(fname,F_OK))!=-1)
  7432. {
  7433. strcpy(chargingProfiles[m], fname);
  7434. m = m + 1;
  7435. }
  7436. ChargeProfileCount = m;
  7437. }
  7438. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7439. {
  7440. //strcpy(fname, TxDefaultProfile_1_JSON);
  7441. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  7442. if((access(fname,F_OK))!=-1)
  7443. {
  7444. strcpy(chargingProfiles[0], fname);
  7445. ChargeProfileCount = 1;
  7446. }
  7447. }
  7448. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  7449. {
  7450. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7451. if((access(fname,F_OK))!=-1)
  7452. {
  7453. strcpy(chargingProfiles[0], fname);
  7454. ChargeProfileCount = 1;
  7455. }
  7456. //strcpy(fname, TxProfile_1_JSON);
  7457. }
  7458. //strcpy(fname, ChargePointMaxProfile_JSON );
  7459. break;
  7460. }
  7461. }
  7462. else // Check all Charging Profiles
  7463. {
  7464. int i = 0;
  7465. char fnametemp[200]={0};
  7466. ChargeProfileCount = 0;
  7467. //Check ChargePointMaxProfile.json exit
  7468. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  7469. {
  7470. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  7471. i = i + 1;
  7472. }
  7473. //Check TxDefaultProfile_0.json exit
  7474. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  7475. {
  7476. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  7477. i = i + 1;
  7478. }
  7479. //Check TxDefaultProfile_%d.json
  7480. for(int j=1; j <= gunTotalNumber; j++)
  7481. {
  7482. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7483. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  7484. if((access(fnametemp,F_OK))!=-1)
  7485. {
  7486. strcpy(chargingProfiles[i], fnametemp);
  7487. i = i + 1;
  7488. }
  7489. }
  7490. //Check TxProfile_%d.json
  7491. for(int j=1; j <= gunTotalNumber; j++)
  7492. {
  7493. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7494. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  7495. if((access(fnametemp,F_OK))!=-1)
  7496. {
  7497. strcpy(chargingProfiles[i], fnametemp);
  7498. i = i + 1;
  7499. }
  7500. }
  7501. ChargeProfileCount = i;
  7502. }// End connectorIsNULL is TRUE
  7503. if(ChargeProfileCount == 0)
  7504. {
  7505. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7506. goto end;
  7507. }
  7508. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  7509. {
  7510. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7511. goto end;
  7512. }
  7513. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  7514. {
  7515. memset(str, 0, ARRAY_SIZE(str));
  7516. // clear temp file
  7517. sprintf(str,"rm -f %s",temp);
  7518. system(str);
  7519. for(int k=0; k < ChargeProfileCount; k++)
  7520. {
  7521. memset(str, 0, ARRAY_SIZE(str));
  7522. //clear file in C
  7523. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7524. system(str);
  7525. }
  7526. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7527. goto end;
  7528. }
  7529. else if(connectorIsNULL == TRUE)
  7530. {
  7531. for(int k=0; k < ChargeProfileCount; k++)
  7532. {
  7533. fptr1 = fopen(chargingProfiles[k], "r");
  7534. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  7535. //Check Charging Profile Count
  7536. while(fscanf(fptr1, "%s", word) != EOF)
  7537. {
  7538. //DEBUG_INFO("word=%s\n",word);
  7539. if(strstr(word, "chargingProfileId")!= NULL)
  7540. {
  7541. //DEBUG_INFO("test chargingProfileId \n");
  7542. n_chargingProfile = n_chargingProfile + 1;
  7543. //DEBUG_INFO("chargingProfileId Found\n");
  7544. }
  7545. }
  7546. rewind(fptr1);
  7547. //search Charging Profile Element
  7548. //int i= 0;
  7549. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7550. {
  7551. json_object *tmpProfilee;
  7552. tmpProfilee = json_tokener_parse(sLineWord);
  7553. if(!is_error(tmpProfilee))
  7554. {
  7555. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7556. {
  7557. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7558. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7559. }
  7560. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7561. {
  7562. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7563. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7564. }
  7565. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7566. {
  7567. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7568. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7569. }
  7570. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7571. {
  7572. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7573. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7574. }
  7575. }
  7576. json_object_put(tmpProfilee);
  7577. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7578. {
  7579. //------- not write to fptr2-------//
  7580. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7581. //clearflag = TRUE;
  7582. }
  7583. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7584. {
  7585. //------- not write to fptr2-------//
  7586. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7587. }
  7588. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7589. {
  7590. //------- not write to fptr2-------//
  7591. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7592. }
  7593. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  7594. {
  7595. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7596. }
  7597. else
  7598. {
  7599. fprintf(fptr2, sLineWord);//writing data into file
  7600. }
  7601. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7602. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7603. if(clearflag == TRUE)
  7604. {
  7605. fclose(fptr1);
  7606. fclose(fptr2);
  7607. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7608. system(str);
  7609. // clear temp file
  7610. sprintf(str,"rm -f %s",temp);
  7611. system(str);
  7612. }
  7613. else
  7614. {
  7615. fclose(fptr1);
  7616. fclose(fptr2);
  7617. memset(str, 0, ARRAY_SIZE(str));
  7618. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7619. system(str);
  7620. resultRename = rename(temp, chargingProfiles[k]);
  7621. if(resultRename == 0)
  7622. {
  7623. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  7624. }
  7625. else
  7626. {
  7627. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  7628. }
  7629. if(comfirmstr[0]== 0)
  7630. {
  7631. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7632. }
  7633. //Check chargingProfile is empty file
  7634. /*------ Read the file ----------------*/
  7635. fptr1=fopen(chargingProfiles[k],"r");
  7636. ch=fgetc(fptr1);
  7637. rewind(fptr1);
  7638. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7639. if(ch!=EOF)
  7640. {
  7641. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7642. {
  7643. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7644. if(sLineWord[0]=='\0')
  7645. {
  7646. isEmptyFile = TRUE;
  7647. break;
  7648. }
  7649. else
  7650. {
  7651. isEmptyFile = FALSE;
  7652. break;
  7653. }
  7654. }
  7655. }
  7656. else
  7657. isEmptyFile = TRUE;
  7658. fclose(fptr1);
  7659. if(isEmptyFile == TRUE)
  7660. {
  7661. memset(str, 0, ARRAY_SIZE(str));
  7662. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7663. system(str);
  7664. }
  7665. }
  7666. }// End of while(int k=0; k < ChargePointCount; k++)
  7667. }
  7668. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  7669. {
  7670. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  7671. for(int k=0; k < ChargeProfileCount; k++)
  7672. {
  7673. fptr1 = fopen(chargingProfiles[k], "r");
  7674. fptr2 = fopen(temp, "w+");
  7675. //Check Charging Profile Count
  7676. while(fscanf(fptr1, "%s", word) != EOF)
  7677. {
  7678. //DEBUG_INFO("word=%s\n",word);
  7679. if(strstr(word, "chargingProfileId")!= NULL)
  7680. {
  7681. n_chargingProfile = n_chargingProfile + 1;
  7682. }
  7683. }
  7684. rewind(fptr1);
  7685. //search Charging Profile Element
  7686. //int i= 0;
  7687. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7688. {
  7689. json_object *tmpProfilee;
  7690. tmpProfilee = json_tokener_parse(sLineWord);
  7691. if(!is_error(tmpProfilee))
  7692. {
  7693. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7694. {
  7695. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7696. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7697. }
  7698. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7699. {
  7700. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7701. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7702. }
  7703. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7704. {
  7705. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7706. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7707. }
  7708. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7709. {
  7710. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7711. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7712. }
  7713. }
  7714. json_object_put(tmpProfilee);
  7715. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7716. {
  7717. //------- not write to fptr2-------//
  7718. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7719. //clearflag = TRUE;
  7720. }
  7721. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7722. {
  7723. //------- not write to fptr2-------//
  7724. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7725. }
  7726. else if(stackLevelIsNULL == TRUE)
  7727. {
  7728. //Clear Whole File
  7729. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7730. clearflag = TRUE;
  7731. break;
  7732. }
  7733. else
  7734. {
  7735. fprintf(fptr2, sLineWord);//writing data into file
  7736. }
  7737. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7738. }
  7739. if(clearflag == TRUE)
  7740. {
  7741. fclose(fptr1);
  7742. fclose(fptr2);
  7743. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7744. system(str);
  7745. // clear temp file
  7746. sprintf(str,"rm -f %s",temp);
  7747. system(str);
  7748. }
  7749. else
  7750. {
  7751. fclose(fptr1);
  7752. fclose(fptr2);
  7753. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7754. system(str);
  7755. resultRename = rename(temp, chargingProfiles[k]);
  7756. if(resultRename == 0)
  7757. {
  7758. DEBUG_INFO("File ChargingProfile renamed successfully");
  7759. }
  7760. else
  7761. {
  7762. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  7763. }
  7764. if(comfirmstr[0]== 0)
  7765. {
  7766. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7767. }
  7768. //Check chargingProfile is empty file
  7769. /*------ Read the file ----------------*/
  7770. fptr1=fopen(chargingProfiles[k],"r");
  7771. ch=fgetc(fptr1);
  7772. rewind(fptr1);
  7773. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7774. if(ch!=EOF)
  7775. {
  7776. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7777. {
  7778. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7779. if(sLineWord[0]=='\0')
  7780. {
  7781. isEmptyFile = TRUE;
  7782. break;
  7783. }
  7784. else
  7785. {
  7786. isEmptyFile = FALSE;
  7787. break;
  7788. }
  7789. }
  7790. }
  7791. else
  7792. isEmptyFile = TRUE;
  7793. fclose(fptr1);
  7794. if(isEmptyFile == TRUE)
  7795. {
  7796. memset(str, 0, ARRAY_SIZE(str));
  7797. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7798. system(str);
  7799. }
  7800. /*------- End of reading ---------------*/
  7801. }
  7802. } // while(int k=0; k < ChargeProfileCount; k++)
  7803. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  7804. end:
  7805. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  7806. {
  7807. if(connectorIdInt == 0)
  7808. {
  7809. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  7810. {
  7811. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  7812. }
  7813. }
  7814. else
  7815. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  7816. }
  7817. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  7818. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7819. return result;
  7820. }
  7821. void createFirmwareVersionByDataTransfer(void)
  7822. {
  7823. json_object *FirmwareDataTransfer = json_object_new_object();
  7824. // AC & DC model
  7825. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  7826. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  7827. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  7828. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  7829. // DC model
  7830. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  7831. {
  7832. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  7833. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  7834. (gunType[3] != GUN_TYPE_UNKNOWN))
  7835. {
  7836. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  7837. }
  7838. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  7839. {
  7840. // DS DM DW
  7841. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7842. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7843. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  7844. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  7845. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7846. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7847. }
  7848. else
  7849. {
  7850. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7851. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7852. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7853. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7854. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  7855. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  7856. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  7857. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  7858. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  7859. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  7860. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  7861. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  7862. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  7863. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  7864. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  7865. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  7866. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  7867. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  7868. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  7869. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  7870. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  7871. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  7872. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  7873. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  7874. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  7875. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  7876. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  7877. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  7878. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  7879. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  7880. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  7881. }
  7882. }
  7883. // 4G model
  7884. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  7885. {
  7886. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  7887. }
  7888. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  7889. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  7890. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  7891. json_object_put(FirmwareDataTransfer);
  7892. }
  7893. int handleDataTransferRequest(char *uuid, char *payload)
  7894. {
  7895. mtrace();
  7896. json_object *response = json_object_new_object();
  7897. int result = FAIL;
  7898. char tempvendorId[255]={0};
  7899. char tempmessageId[50]={0};
  7900. char tempdata[512]={0};
  7901. char message[2048]={0};
  7902. DEBUG_INFO("handleDataTransferRequest...\n");
  7903. if((uuid != NULL) && (payload != NULL))
  7904. {
  7905. json_object *DataTransfer;
  7906. DataTransfer = json_tokener_parse(payload);
  7907. if(!is_error(DataTransfer))
  7908. {
  7909. // Required data
  7910. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  7911. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  7912. // Optional data
  7913. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  7914. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  7915. if(json_object_object_get(DataTransfer, "data") != NULL)
  7916. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  7917. result = PASS;
  7918. }
  7919. json_object_put(DataTransfer);
  7920. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  7921. {
  7922. // Send all moudle firmware version on EVSE
  7923. createFirmwareVersionByDataTransfer();
  7924. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7925. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  7926. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7927. json_object_put(response);
  7928. }
  7929. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  7930. {
  7931. system("/usr/bin/run_tmate_restart.sh &");
  7932. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7933. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7934. json_object_put(response);
  7935. }
  7936. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  7937. {
  7938. json_object *data;
  7939. data = json_tokener_parse(tempdata);
  7940. if(!is_error(data))
  7941. {
  7942. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  7943. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  7944. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  7945. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  7946. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  7947. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  7948. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  7949. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  7950. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  7951. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  7952. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7953. }
  7954. else
  7955. {
  7956. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7957. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7958. }
  7959. json_object_put(data);
  7960. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7961. json_object_put(response);
  7962. }
  7963. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  7964. {
  7965. json_object *data;
  7966. data = json_tokener_parse(tempdata);
  7967. if(!is_error(data))
  7968. {
  7969. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  7970. if(json_object_object_get(data, "idToken") != NULL)
  7971. {
  7972. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  7973. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  7974. }
  7975. if(json_object_object_get(data, "price") != NULL)
  7976. {
  7977. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  7978. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  7979. }
  7980. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7981. }
  7982. else
  7983. {
  7984. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7985. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7986. }
  7987. json_object_put(data);
  7988. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7989. json_object_put(response);
  7990. }
  7991. else if(strstr(tempmessageId, "RunningCost") != NULL)
  7992. {
  7993. json_object *data;
  7994. data = json_tokener_parse(tempdata);
  7995. if(!is_error(data))
  7996. {
  7997. if(json_object_object_get(data, "txId") != NULL)
  7998. {
  7999. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8000. for(int idx = 0;idx<gunTotalNumber;idx++)
  8001. {
  8002. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8003. {
  8004. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8005. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8006. if(json_object_object_get(data, "description") != NULL)
  8007. {
  8008. // California pricing V1.0
  8009. DEBUG_INFO("California pricing V1.0\n");
  8010. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8011. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8012. }
  8013. else
  8014. {
  8015. // California pricing V1.1
  8016. DEBUG_INFO("California pricing V1.1\n");
  8017. if(json_object_object_get(data, "timestamp") != NULL)
  8018. {
  8019. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8020. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8021. }
  8022. if(json_object_object_get(data, "meterValue") != NULL)
  8023. {
  8024. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8025. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8026. }
  8027. if(json_object_object_get(data, "cost") != NULL)
  8028. {
  8029. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8030. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8031. }
  8032. if(json_object_object_get(data, "state") != NULL)
  8033. {
  8034. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8035. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8036. }
  8037. if(json_object_object_get(data, "chargingPrice") != NULL)
  8038. {
  8039. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8040. {
  8041. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8042. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8043. }
  8044. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8045. {
  8046. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8047. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8048. }
  8049. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8050. {
  8051. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8052. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8053. }
  8054. }
  8055. if(json_object_object_get(data, "idlePrice") != NULL)
  8056. {
  8057. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8058. {
  8059. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8060. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8061. }
  8062. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8063. {
  8064. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8065. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8066. }
  8067. }
  8068. if(json_object_object_get(data, "nextPeriod") != NULL)
  8069. {
  8070. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8071. {
  8072. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8073. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8074. }
  8075. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8076. {
  8077. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8078. {
  8079. DEBUG_INFO("nextPeriod-chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice")));
  8080. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice"));
  8081. }
  8082. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8083. {
  8084. DEBUG_INFO("nextPeriod-chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice")));
  8085. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice"));
  8086. }
  8087. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8088. {
  8089. DEBUG_INFO("nextPeriod-chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee")));
  8090. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee"));
  8091. }
  8092. }
  8093. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8094. {
  8095. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8096. {
  8097. DEBUG_INFO("nextPeriod-idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes")));
  8098. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes"));
  8099. }
  8100. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8101. {
  8102. DEBUG_INFO("nextPeriod-idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice")));
  8103. ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice"));
  8104. }
  8105. }
  8106. }
  8107. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8108. {
  8109. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8110. {
  8111. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8112. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8113. }
  8114. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8115. {
  8116. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8117. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8118. }
  8119. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8120. {
  8121. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8122. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8123. }
  8124. }
  8125. }
  8126. }
  8127. }
  8128. }
  8129. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8130. }
  8131. else
  8132. {
  8133. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8134. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8135. }
  8136. json_object_put(data);
  8137. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8138. json_object_put(response);
  8139. }
  8140. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8141. {
  8142. json_object *data;
  8143. data = json_tokener_parse(tempdata);
  8144. if(!is_error(data))
  8145. {
  8146. if(json_object_object_get(data, "txId") != NULL)
  8147. {
  8148. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8149. for(int idx = 0;idx<gunTotalNumber;idx++)
  8150. {
  8151. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8152. {
  8153. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8154. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8155. if(json_object_object_get(data, "description") != NULL)
  8156. {
  8157. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8158. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8159. }
  8160. }
  8161. }
  8162. }
  8163. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8164. }
  8165. else
  8166. {
  8167. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8168. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8169. }
  8170. json_object_put(data);
  8171. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8172. json_object_put(response);
  8173. }
  8174. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  8175. {
  8176. json_object *data;
  8177. data = json_tokener_parse(tempdata);
  8178. if(!is_error(data))
  8179. {
  8180. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8181. if(json_object_object_get(data, "Content_Type") != NULL)
  8182. {
  8183. 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))
  8184. {
  8185. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  8186. if(json_object_object_get(data, "Customization_Conent") != NULL)
  8187. {
  8188. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  8189. }
  8190. }
  8191. else
  8192. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8193. }
  8194. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8195. }
  8196. else
  8197. {
  8198. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8199. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8200. }
  8201. json_object_put(data);
  8202. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8203. json_object_put(response);
  8204. }
  8205. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  8206. {
  8207. json_object *data;
  8208. data = json_tokener_parse(tempdata);
  8209. if(!is_error(data))
  8210. {
  8211. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8212. if(json_object_object_get(data, "Page_Index") != NULL)
  8213. {
  8214. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  8215. }
  8216. if(json_object_object_get(data, "Duration") != NULL)
  8217. {
  8218. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  8219. }
  8220. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  8221. }
  8222. else
  8223. {
  8224. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8225. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8226. }
  8227. json_object_put(data);
  8228. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8229. json_object_put(response);
  8230. }
  8231. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  8232. {
  8233. json_object *data;
  8234. data = json_tokener_parse(tempdata);
  8235. if(!is_error(data))
  8236. {
  8237. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8238. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  8239. {
  8240. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  8241. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  8242. else
  8243. {
  8244. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8245. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8246. }
  8247. }
  8248. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  8249. {
  8250. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  8251. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  8252. else
  8253. {
  8254. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8255. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8256. }
  8257. }
  8258. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  8259. {
  8260. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  8261. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  8262. else
  8263. {
  8264. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8265. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8266. }
  8267. }
  8268. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  8269. {
  8270. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  8271. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  8272. else
  8273. {
  8274. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8275. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8276. }
  8277. }
  8278. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  8279. {
  8280. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  8281. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  8282. else
  8283. {
  8284. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8285. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8286. }
  8287. }
  8288. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  8289. {
  8290. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  8291. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  8292. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  8293. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  8294. else
  8295. {
  8296. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8297. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8298. }
  8299. }
  8300. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  8301. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8302. }
  8303. else
  8304. {
  8305. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8306. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8307. }
  8308. json_object_put(data);
  8309. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8310. json_object_put(response);
  8311. }
  8312. else
  8313. {
  8314. // Can not find valid message id
  8315. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  8316. }
  8317. }
  8318. else
  8319. {
  8320. // Payload is null
  8321. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  8322. }
  8323. LWS_Send(message);
  8324. return result;
  8325. }
  8326. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  8327. {
  8328. mtrace();
  8329. int result = FAIL;
  8330. int connectorIdInt, durationInt;
  8331. char chargingRateUnitStr[4]={0};
  8332. char comfirmstr[20];
  8333. int confirmPeriods = 0;
  8334. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  8335. json_object *GetCompositeSchedule;
  8336. GetCompositeSchedule = json_tokener_parse(payload);
  8337. if(!is_error(GetCompositeSchedule))
  8338. {
  8339. // Required data
  8340. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  8341. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  8342. else
  8343. connectorIdInt = -1;
  8344. if(json_object_object_get(GetCompositeSchedule, "duration"))
  8345. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  8346. else
  8347. durationInt = 86400;
  8348. // Optional data
  8349. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  8350. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  8351. }
  8352. json_object_put(GetCompositeSchedule);
  8353. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  8354. if((connectorIdInt == 0) ||
  8355. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  8356. {
  8357. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  8358. struct StructChargingProfile tmpProfile[1];
  8359. if(strstr(chargingRateUnitStr, "W") != NULL)
  8360. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  8361. else
  8362. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  8363. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8364. {
  8365. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8366. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8367. }
  8368. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  8369. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  8370. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  8371. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8372. {
  8373. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8374. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8375. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  8376. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  8377. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  8378. {
  8379. confirmPeriods = idx;
  8380. break;
  8381. }
  8382. }
  8383. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  8384. {
  8385. confirmPeriods += 1;
  8386. }
  8387. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  8388. }
  8389. else
  8390. {
  8391. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  8392. }
  8393. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  8394. return result;
  8395. }
  8396. int handleGetConfigurationRequest(char *uuid, char *payload)
  8397. {
  8398. mtrace();
  8399. int result = FAIL;
  8400. int MaxKeySupported = 0;
  8401. int n_keys = 0;
  8402. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  8403. DEBUG_INFO("handleGetConfigurationRequest...\n");
  8404. json_object *GetConfiguration;
  8405. GetConfiguration = json_tokener_parse(payload);
  8406. if(!is_error(GetConfiguration))
  8407. {
  8408. // Optional data
  8409. if(json_object_object_get(GetConfiguration, "key") != NULL)
  8410. {
  8411. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  8412. {
  8413. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  8414. n_keys = idx + 1;
  8415. }
  8416. }
  8417. }
  8418. json_object_put(GetConfiguration);
  8419. UnknownKeynum = 0;
  8420. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  8421. MaxKeySupported = GetConfigurationMaxKeysNUM;
  8422. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  8423. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  8424. if(n_keys != 0)
  8425. {
  8426. for(int i=0;i<n_keys;i++)
  8427. {
  8428. getKeyValue(requestKey[i]);
  8429. }
  8430. }
  8431. else
  8432. {
  8433. DEBUG_INFO("There is no key in Message, get all configuration\n");
  8434. getKeyValue("");
  8435. }
  8436. processUnkownKey();
  8437. sendGetConfigurationConfirmation(uuid);
  8438. return result;
  8439. }
  8440. static char fnamePlusPath[100]={0};
  8441. static char fnamePWithNoPath[60]={0};
  8442. void checkUploadLog(void)
  8443. {
  8444. FILE *fp;
  8445. /* Open the command for reading. */
  8446. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  8447. if (fp == NULL) {
  8448. DEBUG_WARN("Failed to run command\n" );
  8449. exit(1);
  8450. }
  8451. int ftppathlen = 0;
  8452. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  8453. int i = 0;
  8454. /* Read the output a line at a time - output it. */
  8455. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  8456. if(i==0)
  8457. {
  8458. ftppathlen = strlen(fnamePlusPath);
  8459. DEBUG_INFO("%s\n", fnamePlusPath);
  8460. fnamePlusPath[ftppathlen]='\0';
  8461. break;
  8462. }
  8463. i= i+1;
  8464. }
  8465. /* close */
  8466. pclose(fp);
  8467. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  8468. {
  8469. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  8470. {
  8471. fnamePlusPath[k]='\0';
  8472. }
  8473. }
  8474. i=1;
  8475. //char fname[60]={0};
  8476. while(i < ftppathlen)
  8477. {
  8478. int len=ftppathlen-i;
  8479. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  8480. {
  8481. DEBUG_INFO("compare '/' all right\n");
  8482. break;
  8483. }
  8484. i=i+1;
  8485. }
  8486. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  8487. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  8488. fnamePWithNoPath[i+1] = '\0';
  8489. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  8490. {
  8491. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  8492. {
  8493. fnamePWithNoPath[j]='\0';
  8494. }
  8495. }
  8496. FILE* fp1 = fopen(fnamePlusPath, "r");
  8497. if (fp1)
  8498. {
  8499. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  8500. // file exists
  8501. fclose(fp1);
  8502. }
  8503. else
  8504. {
  8505. // file doesn't exist
  8506. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  8507. }
  8508. }
  8509. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  8510. {
  8511. mtrace();
  8512. int result = FAIL;
  8513. time_t CurrentTime;
  8514. struct tm *tm;
  8515. pthread_t th_Status;
  8516. CurrentTime = time(NULL);
  8517. tm = localtime(&CurrentTime);
  8518. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  8519. 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);
  8520. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  8521. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  8522. return result;
  8523. }
  8524. void* GetDiagnosticsProcess(void* data)
  8525. {
  8526. pthread_detach(pthread_self());
  8527. mtrace();
  8528. int retriesInt=0, retryIntervalInt=0;
  8529. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  8530. 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};
  8531. int port=0;
  8532. int isSuccess = FALSE;
  8533. char cmdBuf[2048];
  8534. struct tm *tmNow;
  8535. time_t CurrentTime;
  8536. struct tm tmStart;
  8537. struct tm tmStop;
  8538. CurrentTime = time(NULL);
  8539. tmNow=localtime(&CurrentTime);
  8540. uint16_t targetYear, targetMonth;
  8541. json_object *GetDiagnostics;
  8542. DEBUG_INFO("GetDiagnosticsProcess...\n");
  8543. GetDiagnostics = json_tokener_parse(data);
  8544. if(!is_error(GetDiagnostics))
  8545. {
  8546. // Required data
  8547. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  8548. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  8549. // Optional data
  8550. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  8551. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  8552. else
  8553. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  8554. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  8555. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  8556. else
  8557. retryIntervalInt = 30;
  8558. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  8559. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  8560. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  8561. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  8562. }
  8563. json_object_put(GetDiagnostics);
  8564. // Pack log to compress file
  8565. 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) &&
  8566. (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))
  8567. {
  8568. // Pack system log
  8569. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8570. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  8571. targetYear = tmStart.tm_year;
  8572. targetMonth = tmStart.tm_mon;
  8573. do
  8574. {
  8575. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8576. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog", cmdBuf, targetYear, targetMonth);
  8577. if(targetMonth+1>=13)
  8578. {
  8579. targetYear += 1;
  8580. targetMonth = 1;
  8581. }
  8582. else
  8583. {
  8584. targetMonth += 1;
  8585. }
  8586. }while((targetYear < (tmNow->tm_year+1900)) ||
  8587. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8588. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  8589. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  8590. system(cmdBuf);
  8591. // Pack charging & event log
  8592. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8593. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  8594. targetYear = tmStart.tm_year;
  8595. targetMonth = tmStart.tm_mon;
  8596. do
  8597. {
  8598. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8599. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog", cmdBuf, targetYear, targetMonth);
  8600. if(targetMonth+1>=13)
  8601. {
  8602. targetYear += 1;
  8603. targetMonth = 1;
  8604. }
  8605. else
  8606. {
  8607. targetMonth += 1;
  8608. }
  8609. }while((targetYear < (tmNow->tm_year+1900)) ||
  8610. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8611. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  8612. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  8613. system(cmdBuf);
  8614. // Combine log file
  8615. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  8616. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  8617. }
  8618. else
  8619. {
  8620. system("exec /root/logPackTools 'log' 6");
  8621. }
  8622. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  8623. system(cmdBuf);
  8624. checkUploadLog();
  8625. //****************location*******************/
  8626. if(strcmp(locationstr,"")==0)
  8627. {
  8628. DEBUG_INFO("location is <Empty>!\n");
  8629. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8630. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8631. goto end;
  8632. }
  8633. memset(protocol, 0, ARRAY_SIZE(protocol));
  8634. memset(user, 0, ARRAY_SIZE(user) );
  8635. memset(password, 0, ARRAY_SIZE(password));
  8636. memset(host, 0, ARRAY_SIZE(host));
  8637. memset(path, 0, ARRAY_SIZE(path));
  8638. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  8639. memset(host1, 0, ARRAY_SIZE(host1));
  8640. memset(path1, 0, ARRAY_SIZE(path1));
  8641. /*location: ftp://user:password@host:port/path*/
  8642. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  8643. if((access(fnamePlusPath,F_OK))!=-1)
  8644. {
  8645. DEBUG_INFO("fnamePlusPath exist.\n");
  8646. }
  8647. else
  8648. {
  8649. DEBUG_INFO("fnamePlusPath not exist!\n");
  8650. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8651. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8652. goto end;
  8653. }
  8654. if(strchr(locationstr,'@')==NULL)
  8655. {
  8656. sscanf(locationstr,
  8657. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8658. protocol, host, &port, path);
  8659. strcpy(user,"anonymous");
  8660. strcpy(password,"");
  8661. }
  8662. else
  8663. {
  8664. //DEBUG_INFO("pch=%s\n", pch);
  8665. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8666. protocol, user, password, host, &port, path);
  8667. }
  8668. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  8669. {
  8670. DEBUG_INFO("protocol is not ftp/http ! \n");
  8671. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8672. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8673. goto end;
  8674. }
  8675. if(strncmp(locationstr,"http", 4) == 0)
  8676. {
  8677. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  8678. sprintf(ftppath,"/%s", path);
  8679. do
  8680. {
  8681. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8682. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8683. sleep(3);
  8684. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  8685. if(!isSuccess)
  8686. {
  8687. DEBUG_INFO("Diagnostics fail.\n");
  8688. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8689. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8690. sleep(retryIntervalInt);
  8691. }
  8692. else
  8693. {
  8694. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8695. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8696. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8697. }
  8698. retriesInt--;
  8699. }while((isSuccess == 0)&&(retriesInt >= 0));
  8700. }
  8701. else
  8702. {
  8703. sscanf(host,"%[^/]%s",host1, path1);
  8704. if(strlen(path) > 0)
  8705. sprintf(ftppath,"/%s", path);
  8706. else
  8707. sprintf(ftppath,"/%s", path1);
  8708. int ftppathlen=strlen(ftppath);
  8709. int i=1;
  8710. char filenametemp[50];
  8711. while(i < ftppathlen)
  8712. {
  8713. int len=ftppathlen-i;
  8714. if(ftppath[len]== 47) // '/' ascll code: 47
  8715. {
  8716. DEBUG_INFO("find '/' all right\n");
  8717. break;
  8718. }
  8719. i=i+1;
  8720. }
  8721. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  8722. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8723. filenametemp[i+1] = 0;
  8724. if(port == 0)
  8725. port = 21;
  8726. do
  8727. {
  8728. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8729. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8730. sleep(3);
  8731. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  8732. if(!isSuccess)
  8733. {
  8734. DEBUG_INFO("Diagnostics fail.\n");
  8735. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8736. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8737. sleep(retryIntervalInt);
  8738. }
  8739. else
  8740. {
  8741. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8742. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8743. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8744. }
  8745. retriesInt--;
  8746. }while((!isSuccess)&&(retriesInt >= 0));
  8747. }
  8748. end:
  8749. system("rm -f /mnt/*");
  8750. sleep(5);
  8751. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8752. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8753. pthread_exit(NULL);
  8754. }
  8755. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  8756. {
  8757. mtrace();
  8758. int result = FAIL;
  8759. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  8760. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  8761. {
  8762. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  8763. locallistVersion = -1;
  8764. }
  8765. else
  8766. {
  8767. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  8768. OCPP_getListVerion();
  8769. }
  8770. //from db.OCPP_getListVerion
  8771. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  8772. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  8773. sendGetLocalListVersionConfirmation(uuid,"");
  8774. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  8775. return result;
  8776. }
  8777. int handleRemoteStartRequest(char *uuid, char *payload)
  8778. {
  8779. mtrace();
  8780. int result = FAIL;
  8781. int connectorIdInt=0;
  8782. int tempIndex = 0;
  8783. int connectorIdIsNULL, chargingProfileIsNULL;
  8784. char comfirmstr[20]={0};
  8785. char cmdBuf[512];
  8786. json_object *RemoteStartTransaction;
  8787. FILE *fp;
  8788. DEBUG_INFO("handleRemoteStartRequest ...\n");
  8789. if(server_pending == TRUE)
  8790. {
  8791. return 0;
  8792. }
  8793. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  8794. RemoteStartTransaction = json_tokener_parse(payload);
  8795. if(!is_error(RemoteStartTransaction))
  8796. {
  8797. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  8798. {
  8799. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  8800. if(connectorIdInt <= gunTotalNumber)
  8801. {
  8802. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  8803. // Required data
  8804. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  8805. // Optional data
  8806. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  8807. {
  8808. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  8809. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  8810. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  8811. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  8812. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  8813. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  8814. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  8815. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  8816. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  8817. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  8818. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  8819. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  8820. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  8821. {
  8822. 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")));
  8823. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  8824. 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"));
  8825. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  8826. 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"));
  8827. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  8828. 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")));
  8829. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8830. {
  8831. 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++)
  8832. {
  8833. 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"));
  8834. 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"));
  8835. 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)
  8836. 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"));
  8837. }
  8838. }
  8839. }
  8840. }
  8841. else
  8842. chargingProfileIsNULL = TRUE;
  8843. }
  8844. }
  8845. else
  8846. connectorIdIsNULL = TRUE;
  8847. }
  8848. else
  8849. connectorIdIsNULL = TRUE;
  8850. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  8851. {
  8852. DEBUG_WARN("Connector id is NULL\n.");
  8853. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8854. goto end;
  8855. }
  8856. /*
  8857. enum _SYSTEM_STATUS
  8858. {
  8859. S_BOOTING = 0,
  8860. S_IDLE, = 1
  8861. S_AUTHORIZING, = 2
  8862. S_REASSIGN_CHECK, = 3
  8863. S_REASSIGN, = 4
  8864. S_PRECHARGE, = 5
  8865. S_PREPARING_FOR_EV, = 6
  8866. S_PREPARING_FOR_EVSE, = 7
  8867. S_CHARGING, = 8
  8868. S_TERMINATING, = 9
  8869. S_COMPLETE, = 10
  8870. S_ALARM, = 11
  8871. S_FAULT = 12
  8872. }
  8873. */
  8874. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  8875. {
  8876. //check Transaction active
  8877. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8878. {
  8879. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8880. {
  8881. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8882. }
  8883. else
  8884. {
  8885. tempIndex = connectorIdInt -1;
  8886. }
  8887. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8888. {
  8889. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  8890. {
  8891. 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))
  8892. {
  8893. //Reserved
  8894. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8895. }
  8896. 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))
  8897. {
  8898. //Reserved
  8899. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8900. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8901. goto end;
  8902. }
  8903. else
  8904. {
  8905. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8906. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  8907. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  8908. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  8909. {
  8910. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  8911. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8912. goto end;
  8913. }
  8914. }//END FOR ELSE
  8915. }
  8916. }// END FOR CHAdeMO_QUANTITY
  8917. }
  8918. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8919. {
  8920. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8921. {
  8922. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8923. }
  8924. else
  8925. {
  8926. tempIndex = connectorIdInt -1;
  8927. }
  8928. for (int index = 0; index < CCS_QUANTITY; index++)
  8929. {
  8930. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8931. {
  8932. 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))
  8933. {
  8934. //Reserved
  8935. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8936. }
  8937. 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))
  8938. {
  8939. //Reserved
  8940. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8941. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8942. goto end;
  8943. }
  8944. else
  8945. {
  8946. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8947. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8948. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8949. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8950. {
  8951. DEBUG_WARN("CCS connector not allow start\n.");
  8952. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8953. goto end;
  8954. }
  8955. }// END FOR ELSE
  8956. }
  8957. }// END FOR CCS_QUANTITY
  8958. }
  8959. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8960. {
  8961. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8962. {
  8963. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8964. }
  8965. else
  8966. {
  8967. tempIndex = connectorIdInt -1;
  8968. }
  8969. for (int index = 0; index < GB_QUANTITY; index++)
  8970. {
  8971. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  8972. {
  8973. 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))
  8974. {
  8975. //Reserved
  8976. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8977. }
  8978. 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))
  8979. {
  8980. //Reserved
  8981. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8982. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8983. goto end;
  8984. }
  8985. else
  8986. {
  8987. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8988. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8989. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8990. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8991. {
  8992. DEBUG_WARN("GB connector not allow start\n.");
  8993. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8994. goto end;
  8995. }
  8996. }// END FOR ELSE
  8997. }
  8998. } // END FOR GB_QUANTITY
  8999. }
  9000. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9001. {
  9002. tempIndex = connectorIdInt -1;
  9003. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9004. {
  9005. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9006. {
  9007. 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))
  9008. {
  9009. //Reserved
  9010. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9011. }
  9012. 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))
  9013. {
  9014. //Reserved
  9015. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9016. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9017. goto end;
  9018. }
  9019. else
  9020. {
  9021. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9022. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9023. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9024. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9025. {
  9026. DEBUG_WARN("GB connector not allow start\n.");
  9027. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9028. goto end;
  9029. }
  9030. }// END FOR ELSE
  9031. }
  9032. } // END FOR GB_QUANTITY
  9033. }
  9034. else
  9035. {
  9036. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9037. {
  9038. tempIndex = 2;
  9039. }
  9040. else
  9041. {
  9042. tempIndex = connectorIdInt -1;
  9043. }
  9044. for (int index = 0; index < AC_QUANTITY; index++)
  9045. {
  9046. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  9047. {
  9048. 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))
  9049. {
  9050. //Reserved
  9051. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9052. }
  9053. 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))
  9054. {
  9055. //Reserved
  9056. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9057. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9058. goto end;
  9059. }
  9060. else
  9061. {
  9062. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9063. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9064. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9065. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9066. {
  9067. DEBUG_WARN("AC connector not allow start\n.");
  9068. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9069. goto end;
  9070. }
  9071. }//END FOR ELSE
  9072. }
  9073. }// END FOR AC_QUANTITY
  9074. }
  9075. if(chargingProfileIsNULL == FALSE)
  9076. {
  9077. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9078. {
  9079. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9080. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9081. //memset idTag
  9082. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9083. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9084. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9085. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9086. // Save profile to file
  9087. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9088. system(cmdBuf);
  9089. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9090. fp = fopen(cmdBuf, "w");
  9091. 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));
  9092. fclose(fp);
  9093. }
  9094. else
  9095. {
  9096. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  9097. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9098. }
  9099. }
  9100. else
  9101. {
  9102. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9103. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9104. //memset idTag
  9105. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9106. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9107. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9108. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9109. }
  9110. }
  9111. else
  9112. {
  9113. DEBUG_WARN("Connector id over\n.");
  9114. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9115. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9116. }
  9117. end:
  9118. json_object_put(RemoteStartTransaction);
  9119. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  9120. {
  9121. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  9122. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9123. }
  9124. //OCPP send RemoteStartConfirmation by first.
  9125. sendRemoteStartConfirmation(uuid, comfirmstr);
  9126. return result;
  9127. }
  9128. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  9129. {
  9130. mtrace();
  9131. int result = FAIL;
  9132. int match = FALSE;
  9133. int GunNO = 0;
  9134. int tempIndex = 0;
  9135. int transactionIdInt=0;
  9136. int transactionIdIsNULL= TRUE;
  9137. char comfirmstr[20];
  9138. json_object *RemoteStopTransaction;
  9139. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  9140. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  9141. if(server_pending == TRUE)
  9142. {
  9143. return 0;
  9144. }
  9145. RemoteStopTransaction = json_tokener_parse(payload);
  9146. if(!is_error(RemoteStopTransaction))
  9147. {
  9148. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  9149. {
  9150. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  9151. transactionIdIsNULL = FALSE;
  9152. }
  9153. }
  9154. json_object_put(RemoteStopTransaction);
  9155. if(transactionIdIsNULL == FALSE)
  9156. {
  9157. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  9158. {
  9159. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  9160. {
  9161. //check Transaction active
  9162. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9163. {
  9164. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9165. {
  9166. tempIndex = ((gun_index==2) ? 1: 0);
  9167. }
  9168. else
  9169. {
  9170. tempIndex = gun_index;
  9171. }
  9172. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9173. {
  9174. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9175. {
  9176. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9177. {
  9178. match = TRUE;
  9179. GunNO = gun_index;
  9180. }
  9181. }
  9182. }// END FOR CHAdeMO_QUANTITY
  9183. }
  9184. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9185. {
  9186. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9187. {
  9188. tempIndex = ((gun_index==2) ? 1: 0);
  9189. }
  9190. else
  9191. {
  9192. tempIndex = gun_index;
  9193. }
  9194. for (int index = 0; index < CCS_QUANTITY; index++)
  9195. {
  9196. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9197. {
  9198. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9199. {
  9200. match = TRUE;
  9201. GunNO = gun_index;
  9202. }
  9203. }
  9204. }// END FOR CCS_QUANTITY
  9205. }
  9206. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9207. {
  9208. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9209. {
  9210. tempIndex = ((gun_index==2) ? 1: 0);
  9211. }
  9212. else
  9213. {
  9214. tempIndex = gun_index;
  9215. }
  9216. for (int index = 0; index < GB_QUANTITY; index++)
  9217. {
  9218. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9219. {
  9220. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9221. {
  9222. match = TRUE;
  9223. GunNO = gun_index;
  9224. }
  9225. }
  9226. }// END FOR GB_QUANTITY
  9227. }
  9228. else if(gunType[gun_index] == GUN_TYPE_DO)
  9229. {
  9230. tempIndex = gun_index;
  9231. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9232. {
  9233. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9234. {
  9235. 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
  9236. {
  9237. match = TRUE;
  9238. GunNO = gun_index;
  9239. }
  9240. }
  9241. }// END FOR GB_QUANTITY
  9242. }
  9243. else
  9244. {
  9245. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9246. {
  9247. tempIndex = 2;
  9248. }
  9249. else
  9250. {
  9251. tempIndex = gun_index;
  9252. }
  9253. for (int index = 0; index < AC_QUANTITY; index++)
  9254. {
  9255. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9256. {
  9257. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9258. {
  9259. match = TRUE;
  9260. GunNO = gun_index;
  9261. }
  9262. }
  9263. }// END FOR CHAdeMO_QUANTITY
  9264. } // END FOR AC ELSE
  9265. }// CHECK IF ResponseTransactionId == transactionIdInt
  9266. }//END FOR
  9267. if( match == TRUE)
  9268. {
  9269. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  9270. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9271. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  9272. }
  9273. else
  9274. {
  9275. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9276. }
  9277. }
  9278. else
  9279. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9280. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  9281. return result;
  9282. }
  9283. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  9284. {
  9285. mtrace();
  9286. int result = FAIL;
  9287. int connectorIdInt=0, reservationIdInt=0;
  9288. int tempIndex = 0;
  9289. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  9290. char comfirmstr[20]={0};
  9291. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  9292. int c = 0;
  9293. char *loc;
  9294. //char *ptr;
  9295. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  9296. strcpy(sstrtemp, stringtrimspace(payload));
  9297. //***(1)connectorId ****/
  9298. c=0;
  9299. loc = strstr(sstrtemp, "connectorId");
  9300. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9301. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  9302. {
  9303. sstr[c] = loc[strlen("connectorId")+2+c];
  9304. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9305. c++;
  9306. }
  9307. sstr[c] = '\0';
  9308. connectorIdInt = atoi(sstr);
  9309. //***(2)expiryDate ****/
  9310. loc = strstr(sstrtemp, "expiryDate");
  9311. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9312. c = 0;
  9313. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  9314. {
  9315. sstr[c] = loc[3+strlen("expiryDate")+c];
  9316. c++;
  9317. }
  9318. sstr[c] = '\0';
  9319. strcpy(expiryDatestr, sstr);
  9320. //***(3)idTag ****/
  9321. loc = strstr(sstrtemp, "idTag");
  9322. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9323. c = 0;
  9324. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  9325. {
  9326. sstr[c] = loc[3+strlen("idTag")+c];
  9327. c++;
  9328. }
  9329. sstr[c] = '\0';
  9330. strcpy(idTagstr, sstr);
  9331. //***(4)parentIdTag ****/
  9332. loc = strstr(sstrtemp, "parentIdTag");
  9333. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9334. c = 0;
  9335. if(loc == NULL)
  9336. {
  9337. strcpy(parentIdTagstr, "");
  9338. }
  9339. else
  9340. {
  9341. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9342. {
  9343. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9344. c++;
  9345. }
  9346. sstr[c] = '\0';
  9347. strcpy(parentIdTagstr, sstr);
  9348. }
  9349. //***(5)reservationId ****/
  9350. c=0;
  9351. loc = strstr(sstrtemp, "reservationId");
  9352. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9353. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  9354. {
  9355. sstr[c] = loc[strlen("reservationId")+2+c];
  9356. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9357. c++;
  9358. }
  9359. sstr[c] = '\0';
  9360. reservationIdInt = atoi(sstr);
  9361. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9362. /*
  9363. enum SYSTEM_STATUS
  9364. {
  9365. SYS_MODE_BOOTING = 0,
  9366. SYS_MODE_IDLE = 1,
  9367. SYS_MODE_AUTHORIZING = 2,
  9368. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  9369. SYS_MODE_REASSIGN = 4,
  9370. SYS_MODE_PREPARING = 5,
  9371. SYS_MODE_PREPARE_FOR_EV = 6,
  9372. SYS_MODE_PREPARE_FOR_EVSE = 7,
  9373. SYS_MODE_CHARGING = 8,
  9374. SYS_MODE_TERMINATING = 9,
  9375. SYS_MODE_COMPLETE = 10,
  9376. SYS_MODE_ALARM = 11,
  9377. SYS_MODE_FAULT = 12,
  9378. SYS_MODE_RESERVATION = 13,
  9379. SYS_MODE_BOOKING = 14,
  9380. SYS_MODE_MAINTAIN = 15,
  9381. SYS_MODE_DEBUG = 16,
  9382. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  9383. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  9384. SYS_MODE_UPDATE = 19
  9385. };
  9386. */
  9387. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  9388. {
  9389. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9390. goto end;
  9391. }
  9392. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  9393. {
  9394. //check Transaction active
  9395. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9396. {
  9397. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9398. {
  9399. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9400. }
  9401. else
  9402. {
  9403. tempIndex = connectorIdInt -1;
  9404. }
  9405. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9406. {
  9407. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9408. {
  9409. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9410. {
  9411. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9412. {
  9413. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9414. {
  9415. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9416. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9417. }
  9418. 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'))
  9419. {
  9420. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9421. }
  9422. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9423. {
  9424. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9425. }
  9426. else
  9427. {
  9428. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9429. }
  9430. }
  9431. 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
  9432. {
  9433. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9434. }
  9435. }
  9436. else
  9437. {
  9438. //replace reservation
  9439. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9440. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9441. }
  9442. }
  9443. } // END FOR CHAdeMO_QUANTITY
  9444. }
  9445. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9446. {
  9447. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9448. {
  9449. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9450. }
  9451. else
  9452. {
  9453. tempIndex = connectorIdInt -1;
  9454. }
  9455. for (int index = 0; index < CCS_QUANTITY; index++)
  9456. {
  9457. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9458. {
  9459. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9460. {
  9461. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9462. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9463. {
  9464. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9465. {
  9466. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9467. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9468. }
  9469. 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'))
  9470. {
  9471. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9472. }
  9473. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  9474. {
  9475. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9476. }
  9477. else
  9478. {
  9479. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9480. }
  9481. }
  9482. 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
  9483. {
  9484. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9485. }
  9486. }
  9487. else
  9488. {
  9489. //replace reservation
  9490. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9491. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9492. }
  9493. }
  9494. } // END FOR CCS_QUANTITY
  9495. }
  9496. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9497. {
  9498. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9499. {
  9500. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9501. }
  9502. else
  9503. {
  9504. tempIndex = connectorIdInt -1;
  9505. }
  9506. for (int index = 0; index < GB_QUANTITY; index++)
  9507. {
  9508. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9509. {
  9510. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9511. {
  9512. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9513. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9514. {
  9515. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9516. {
  9517. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9518. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9519. }
  9520. 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'))
  9521. {
  9522. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9523. }
  9524. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9525. {
  9526. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9527. }
  9528. else
  9529. {
  9530. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9531. }
  9532. }
  9533. 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
  9534. {
  9535. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9536. }
  9537. }
  9538. else
  9539. {
  9540. //replace reservation
  9541. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9542. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9543. }
  9544. }
  9545. }// END FOR GB_QUANTITY
  9546. }
  9547. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9548. {
  9549. tempIndex = connectorIdInt -1;
  9550. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9551. {
  9552. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9553. {
  9554. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  9555. {
  9556. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9557. 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
  9558. {
  9559. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9560. {
  9561. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9562. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9563. }
  9564. 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'))
  9565. {
  9566. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9567. }
  9568. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9569. {
  9570. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9571. }
  9572. else
  9573. {
  9574. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9575. }
  9576. }
  9577. 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
  9578. {
  9579. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9580. }
  9581. }
  9582. else
  9583. {
  9584. //replace reservation
  9585. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9586. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9587. }
  9588. }
  9589. }// END FOR GB_QUANTITY
  9590. }
  9591. else
  9592. {
  9593. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9594. {
  9595. tempIndex = 2;
  9596. }
  9597. else
  9598. {
  9599. tempIndex = (connectorIdInt -1);
  9600. }
  9601. for (int index = 0; index < AC_QUANTITY; index++)
  9602. {
  9603. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9604. {
  9605. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9606. {
  9607. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9608. {
  9609. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9610. {
  9611. 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))
  9612. {
  9613. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9614. }
  9615. else
  9616. {
  9617. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9618. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9619. }
  9620. }
  9621. 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'))
  9622. {
  9623. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9624. }
  9625. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9626. {
  9627. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9628. }
  9629. else
  9630. {
  9631. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9632. }
  9633. }
  9634. 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
  9635. {
  9636. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9637. }
  9638. }
  9639. else
  9640. {
  9641. //replace reservation
  9642. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9643. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9644. }
  9645. }
  9646. } // END FOR AC_QUANTITY
  9647. }
  9648. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9649. }
  9650. else if(connectorIdInt == 0)
  9651. {
  9652. //check Transaction active
  9653. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9654. {
  9655. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9656. {
  9657. 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'))
  9658. {
  9659. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9660. goto end;
  9661. }
  9662. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9663. {
  9664. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9665. goto end;
  9666. }
  9667. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  9668. {
  9669. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9670. goto end;
  9671. }
  9672. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9673. {
  9674. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9675. goto end;
  9676. }
  9677. }
  9678. }// END FOR CHAdeMO_QUANTITY
  9679. for (int index = 0; index < CCS_QUANTITY; index++)
  9680. {
  9681. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9682. {
  9683. 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'))
  9684. {
  9685. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9686. goto end;
  9687. }
  9688. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  9689. {
  9690. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9691. goto end;
  9692. }
  9693. 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
  9694. {
  9695. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9696. goto end;
  9697. }
  9698. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9699. {
  9700. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9701. goto end;
  9702. }
  9703. }
  9704. } // END FOR CCS_QUANTITY
  9705. for (int index = 0; index < GB_QUANTITY; index++)
  9706. {
  9707. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9708. {
  9709. 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'))
  9710. {
  9711. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9712. goto end;
  9713. }
  9714. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9715. {
  9716. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9717. goto end;
  9718. }
  9719. 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
  9720. {
  9721. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9722. goto end;
  9723. }
  9724. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9725. {
  9726. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9727. goto end;
  9728. }
  9729. }
  9730. } // END FOR GB_QUANTITY
  9731. for (int index = 0; index < AC_QUANTITY; index++)
  9732. {
  9733. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9734. {
  9735. 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'))
  9736. {
  9737. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9738. goto end;
  9739. }
  9740. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9741. {
  9742. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9743. goto end;
  9744. }
  9745. 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
  9746. {
  9747. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9748. goto end;
  9749. }
  9750. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9751. {
  9752. 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))
  9753. {
  9754. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9755. goto end;
  9756. }
  9757. }
  9758. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9759. {
  9760. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9761. goto end;
  9762. }
  9763. }
  9764. }// END FOR AC_QUANTITY
  9765. //The connectorId is 0
  9766. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  9767. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9768. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  9769. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  9770. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  9771. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  9772. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  9773. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  9774. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  9775. result = TRUE;
  9776. return result;
  9777. }
  9778. else
  9779. {
  9780. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9781. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9782. }
  9783. if(strcmp(comfirmstr,"Accepted") == 0)
  9784. {
  9785. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  9786. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  9787. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  9788. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  9789. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  9790. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  9791. result = TRUE;
  9792. return result;
  9793. }
  9794. end:
  9795. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  9796. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  9797. return result;
  9798. }
  9799. int handleResetRequest(char *uuid, char *payload)
  9800. {
  9801. mtrace();
  9802. int result = FAIL;
  9803. char sstr[10]={0},sstrtemp[30]={ 0 };
  9804. char typestr[10]={0};
  9805. char comfirmstr[20]={0};
  9806. int c = 0;
  9807. char *loc;
  9808. DEBUG_INFO("handleResetRequest...\n");
  9809. strcpy(sstrtemp, stringtrimspace(payload));
  9810. loc = strstr(sstrtemp, "type");
  9811. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9812. c = 0;
  9813. while (loc[3+strlen("type")+c] != '\"')
  9814. {
  9815. sstr[c] = loc[3+strlen("type")+c];
  9816. c++;
  9817. }
  9818. sstr[c] = '\0';
  9819. strcpy(typestr,sstr);
  9820. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  9821. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  9822. {
  9823. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  9824. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  9825. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  9826. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  9827. }
  9828. else
  9829. {
  9830. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  9831. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  9832. result = PASS;
  9833. }
  9834. sendResetConfirmation(uuid, comfirmstr);
  9835. return result;
  9836. }
  9837. int handleSendLocalListRequest(char *uuid, char *payload)
  9838. {
  9839. mtrace();
  9840. int result = FAIL;
  9841. char comfirmstr[20];
  9842. int checkState_Faulted = FALSE;
  9843. json_object *SendLocalList;
  9844. DEBUG_INFO("handleSendLocalListRequest...\n");
  9845. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  9846. {
  9847. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9848. goto end;
  9849. }
  9850. //check Charge Point state
  9851. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9852. {
  9853. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9854. {
  9855. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9856. }
  9857. }
  9858. for (int index = 0; index < CCS_QUANTITY; index++)
  9859. {
  9860. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9861. {
  9862. checkState_Faulted = TRUE; //OCPP Status
  9863. }
  9864. }
  9865. for (int index = 0; index < GB_QUANTITY; index++)
  9866. {
  9867. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9868. {
  9869. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9870. }
  9871. }
  9872. //check Charge Point state
  9873. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9874. {
  9875. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9876. {
  9877. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9878. }
  9879. }
  9880. //check Charge Point state
  9881. for (int index = 0; index < AC_QUANTITY; index++)
  9882. {
  9883. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9884. {
  9885. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9886. }
  9887. }
  9888. if(checkState_Faulted == TRUE)
  9889. {
  9890. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9891. goto end;
  9892. }
  9893. // Parsing payload
  9894. SendLocalList = json_tokener_parse(payload);
  9895. if(!is_error(SendLocalList))
  9896. {
  9897. // Required data
  9898. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  9899. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  9900. // Optional data
  9901. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  9902. {
  9903. //Check UpdateType
  9904. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  9905. {
  9906. //Local list full update
  9907. DEBUG_INFO("Local list full update.\n");
  9908. OCPP_getListVerion();
  9909. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  9910. {
  9911. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9912. goto end;
  9913. }
  9914. OCPP_cleanLocalList();
  9915. }
  9916. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  9917. {
  9918. //Local list different update
  9919. DEBUG_INFO("Local list different update.\n");
  9920. OCPP_getListVerion();
  9921. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  9922. {
  9923. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  9924. goto end;
  9925. }
  9926. }
  9927. else
  9928. {
  9929. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9930. goto end;
  9931. }
  9932. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  9933. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  9934. {
  9935. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag")));
  9936. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  9937. {
  9938. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "status")));
  9939. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  9940. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate")));
  9941. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  9942. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag")));
  9943. }
  9944. // Add to db
  9945. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  9946. {
  9947. //Local list full update
  9948. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  9949. idx,
  9950. ShmOCPP16Data->SendLocalList.ListVersion,
  9951. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9952. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9953. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9954. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9955. // update list
  9956. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  9957. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9958. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9959. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9960. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9961. }
  9962. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  9963. {
  9964. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  9965. idx,
  9966. ShmOCPP16Data->SendLocalList.ListVersion,
  9967. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9968. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9969. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9970. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9971. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  9972. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9973. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9974. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9975. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9976. }
  9977. }
  9978. }
  9979. else
  9980. {
  9981. //Check UpdateType
  9982. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  9983. {
  9984. //Local list full update
  9985. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  9986. OCPP_cleanLocalList();
  9987. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9988. goto end;
  9989. }
  9990. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  9991. {
  9992. //Local list different update
  9993. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  9994. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9995. goto end;
  9996. }
  9997. }
  9998. result = PASS;
  9999. }
  10000. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10001. end:
  10002. json_object_put(SendLocalList);
  10003. sendSendLocalListConfirmation(uuid, comfirmstr);
  10004. return result;
  10005. }
  10006. #define MAX 200
  10007. int handleSetChargingProfileRequest(char *uuid, char *payload)
  10008. {
  10009. mtrace();
  10010. int result = FAIL;
  10011. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  10012. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  10013. char chargingProfilePurposeStr[30]={0};
  10014. char chargingProfileKindStr[16]={0};
  10015. char recurrencyKindStr[10]={0};
  10016. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  10017. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  10018. int chargingSchedulePeriodCount = 0;
  10019. char comfirmstr[20]={0};
  10020. int meet= FALSE;
  10021. FILE *fptr1;
  10022. char filename[MAX]={0};
  10023. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  10024. char rmFileCmd[50]={0};
  10025. char tempchargingProfilePurposeStr[30]={0};
  10026. char word[1600]={0};
  10027. int n_chargingProfile = 0;
  10028. json_object *SetChargingProfile;
  10029. DEBUG_INFO("handleSetChargingProfileRequest\n");
  10030. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  10031. SetChargingProfile = json_tokener_parse(payload);
  10032. if(!is_error(SetChargingProfile))
  10033. {
  10034. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  10035. {
  10036. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  10037. if(connectorIdInt == 0)
  10038. {
  10039. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  10040. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  10041. }
  10042. else
  10043. {
  10044. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  10045. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  10046. }
  10047. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  10048. }
  10049. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  10050. {
  10051. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10052. {
  10053. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10054. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10055. {
  10056. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  10057. }
  10058. else
  10059. {
  10060. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  10061. }
  10062. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  10063. }
  10064. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10065. {
  10066. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  10067. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10068. {
  10069. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  10070. }
  10071. else
  10072. {
  10073. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  10074. }
  10075. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  10076. }
  10077. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10078. {
  10079. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10080. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10081. {
  10082. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  10083. }
  10084. else
  10085. {
  10086. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  10087. }
  10088. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  10089. }
  10090. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  10091. {
  10092. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  10093. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10094. {
  10095. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  10096. }
  10097. else
  10098. {
  10099. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  10100. }
  10101. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  10102. }
  10103. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  10104. {
  10105. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  10106. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10107. {
  10108. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  10109. }
  10110. else
  10111. {
  10112. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  10113. }
  10114. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  10115. }
  10116. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  10117. {
  10118. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  10119. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10120. {
  10121. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  10122. }
  10123. else
  10124. {
  10125. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  10126. }
  10127. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  10128. }
  10129. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  10130. {
  10131. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  10132. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10133. {
  10134. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  10135. }
  10136. else
  10137. {
  10138. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  10139. }
  10140. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  10141. }
  10142. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  10143. {
  10144. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  10145. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10146. {
  10147. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  10148. }
  10149. else
  10150. {
  10151. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  10152. }
  10153. //DEBUG_INFO("validToStr: %s\n", validToStr);
  10154. }
  10155. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  10156. {
  10157. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  10158. {
  10159. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  10160. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10161. {
  10162. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  10163. }
  10164. else
  10165. {
  10166. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  10167. }
  10168. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  10169. }
  10170. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  10171. {
  10172. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  10173. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10174. {
  10175. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  10176. }
  10177. else
  10178. {
  10179. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  10180. }
  10181. //DEBUG_INFO("durationInt: %d\n", durationInt);
  10182. }
  10183. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  10184. {
  10185. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  10186. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10187. {
  10188. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  10189. }
  10190. else
  10191. {
  10192. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  10193. }
  10194. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  10195. }
  10196. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  10197. {
  10198. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  10199. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10200. {
  10201. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  10202. }
  10203. else
  10204. {
  10205. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  10206. }
  10207. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  10208. }
  10209. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10210. {
  10211. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  10212. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  10213. if(chargingSchedulePeriodCount <= 10)
  10214. {
  10215. 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++)
  10216. {
  10217. 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)
  10218. {
  10219. 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"));
  10220. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10221. {
  10222. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  10223. }
  10224. else
  10225. {
  10226. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  10227. }
  10228. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  10229. }
  10230. 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)
  10231. {
  10232. 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"));
  10233. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10234. {
  10235. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  10236. }
  10237. else
  10238. {
  10239. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  10240. }
  10241. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  10242. }
  10243. 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)
  10244. {
  10245. 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"));
  10246. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10247. {
  10248. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  10249. }
  10250. else
  10251. {
  10252. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  10253. }
  10254. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  10255. }
  10256. }
  10257. }
  10258. }
  10259. }
  10260. }
  10261. }
  10262. json_object_put(SetChargingProfile);
  10263. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  10264. {
  10265. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10266. goto end;
  10267. }
  10268. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  10269. {
  10270. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  10271. if(connectorIdInt != 0)
  10272. {
  10273. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10274. goto end;
  10275. }
  10276. strcpy(filename, ChargePointMaxProfile_JSON );
  10277. fptr1 = fopen(filename, "r");
  10278. if (!fptr1)
  10279. {
  10280. //file not exist
  10281. DEBUG_INFO("Unable to open the input file!!\n");
  10282. fptr1 = fopen(filename, "w+");
  10283. }
  10284. else
  10285. {
  10286. //Check Charging Profile Count
  10287. while(fscanf(fptr1, "%s", word) != EOF)
  10288. {
  10289. //DEBUG_INFO("word=%s\n",word);
  10290. if(strstr(word, "chargingProfileId")!= NULL)
  10291. {
  10292. //DEBUG_INFO("test chargingProfileId \n");
  10293. n_chargingProfile = n_chargingProfile + 1;
  10294. //DEBUG_INFO("chargingProfileId Found\n");
  10295. }
  10296. }
  10297. }
  10298. fclose(fptr1);
  10299. }
  10300. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  10301. {
  10302. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  10303. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  10304. {
  10305. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10306. goto end;
  10307. }
  10308. memset(filename, 0, ARRAY_SIZE(filename));
  10309. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  10310. fptr1 = fopen(filename, "r");
  10311. if (!fptr1)
  10312. {
  10313. //file not exist
  10314. //DEBUG_INFO("Unable to open the input file!!\n");
  10315. fptr1 = fopen(filename, "w+");
  10316. }
  10317. else
  10318. {
  10319. //Check Charging Profile Count
  10320. while(fscanf(fptr1, "%s", word) != EOF)
  10321. {
  10322. //DEBUG_INFO("word=%s\n",word);
  10323. if(strstr(word, "chargingProfileId")!= NULL)
  10324. {
  10325. //DEBUG_INFO("test chargingProfileId \n");
  10326. n_chargingProfile = n_chargingProfile + 1;
  10327. //DEBUG_INFO("chargingProfileId Found\n");
  10328. }
  10329. }
  10330. }
  10331. fclose(fptr1);
  10332. }
  10333. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10334. {
  10335. //printf("set chargingProfile 1-4\n");
  10336. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  10337. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  10338. if(connectorIdInt == 0)
  10339. {
  10340. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10341. goto end;
  10342. }
  10343. int tempIndex = 0;
  10344. //check Transaction active
  10345. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10346. {
  10347. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10348. {
  10349. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10350. }
  10351. else
  10352. {
  10353. tempIndex = connectorIdInt -1;
  10354. }
  10355. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10356. {
  10357. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10358. {
  10359. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  10360. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10361. {
  10362. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10363. {
  10364. meet = TRUE;
  10365. break;
  10366. }
  10367. }
  10368. }
  10369. }
  10370. }
  10371. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10372. {
  10373. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10374. {
  10375. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10376. }
  10377. else
  10378. {
  10379. tempIndex = connectorIdInt -1;
  10380. }
  10381. for (int index = 0; index < CCS_QUANTITY; index++)
  10382. {
  10383. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10384. {
  10385. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  10386. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10387. {
  10388. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10389. {
  10390. meet = TRUE;
  10391. break;
  10392. }
  10393. }
  10394. }
  10395. }
  10396. }
  10397. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10398. {
  10399. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10400. {
  10401. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10402. }
  10403. else
  10404. {
  10405. tempIndex = connectorIdInt -1;
  10406. }
  10407. for (int index = 0; index < GB_QUANTITY; index++)
  10408. {
  10409. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10410. {
  10411. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  10412. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10413. {
  10414. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10415. {
  10416. meet = TRUE;
  10417. break;
  10418. }
  10419. }
  10420. }
  10421. }
  10422. }
  10423. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10424. {
  10425. tempIndex = connectorIdInt -1;
  10426. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10427. {
  10428. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10429. {
  10430. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  10431. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10432. {
  10433. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10434. {
  10435. meet = TRUE;
  10436. break;
  10437. }
  10438. }
  10439. }
  10440. }
  10441. }
  10442. else
  10443. {
  10444. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10445. {
  10446. tempIndex = 2;
  10447. }
  10448. else
  10449. {
  10450. tempIndex = (connectorIdInt -1);
  10451. }
  10452. for (int index = 0; index < AC_QUANTITY; index++)
  10453. {
  10454. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10455. {
  10456. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  10457. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  10458. {
  10459. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10460. {
  10461. meet = TRUE;
  10462. break;
  10463. }
  10464. }
  10465. }
  10466. }
  10467. }
  10468. //check Transaction active
  10469. if(meet == FALSE)
  10470. {
  10471. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10472. goto end;
  10473. }
  10474. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  10475. {
  10476. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10477. goto end;
  10478. }
  10479. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10480. fptr1 = fopen(filename, "r");
  10481. if (!fptr1)
  10482. {
  10483. //file not exist
  10484. DEBUG_INFO("Unable to open the input file!!\n");
  10485. fptr1 = fopen(filename, "w+");
  10486. }
  10487. else
  10488. {
  10489. //Check Charging Profile Count
  10490. while(fscanf(fptr1, "%s", word) != EOF)
  10491. {
  10492. //DEBUG_INFO("word=%s\n",word);
  10493. if(strstr(word, "chargingProfileId")!= NULL)
  10494. {
  10495. //DEBUG_INFO("test chargingProfileId \n");
  10496. n_chargingProfile = n_chargingProfile + 1;
  10497. //DEBUG_INFO("chargingProfileId Found\n");
  10498. }
  10499. }
  10500. }
  10501. fclose(fptr1);
  10502. }
  10503. // Check ChargeProfileMaxStackLevel
  10504. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  10505. {
  10506. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10507. goto end;
  10508. }
  10509. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10510. {
  10511. int i = 0;
  10512. char fnametemp[200]={0};
  10513. n_chargingProfile = 0;
  10514. //Check ChargePointMaxProfile.json exit
  10515. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  10516. {
  10517. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  10518. //Check Charging Profile Count
  10519. while(fscanf(fptr1, "%s", word) != EOF)
  10520. {
  10521. //DEBUG_INFO("word=%s\n",word);
  10522. if(strstr(word, "chargingProfileId")!= NULL)
  10523. {
  10524. //DEBUG_INFO("test chargingProfileId \n");
  10525. n_chargingProfile = n_chargingProfile + 1;
  10526. i = i + 1;
  10527. //DEBUG_INFO("chargingProfileId Found\n");
  10528. }
  10529. memset(word, 0, ARRAY_SIZE(word));
  10530. }
  10531. fclose(fptr1);
  10532. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  10533. }
  10534. //Check TxDefaultProfile_0.json exit
  10535. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  10536. {
  10537. i = 0;
  10538. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  10539. //Check Charging Profile Count
  10540. while(fscanf(fptr1, "%s", word) != EOF)
  10541. {
  10542. //DEBUG_INFO("word=%s\n",word);
  10543. if(strstr(word, "chargingProfileId")!= NULL)
  10544. {
  10545. //DEBUG_INFO("test chargingProfileId \n");
  10546. n_chargingProfile = n_chargingProfile + 1;
  10547. i = i + 1;
  10548. //DEBUG_INFO("chargingProfileId Found\n");
  10549. }
  10550. memset(word, 0, ARRAY_SIZE(word));
  10551. }
  10552. fclose(fptr1);
  10553. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  10554. }
  10555. //Check TxDefaultProfile_%d.json
  10556. for(int j=1; j <= gunTotalNumber; j++)
  10557. {
  10558. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10559. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  10560. if((access(fnametemp,F_OK))!=-1)
  10561. {
  10562. i = 0;
  10563. fptr1 = fopen(fnametemp, "r");
  10564. //Check Charging Profile Count
  10565. while(fscanf(fptr1, "%s", word) != EOF)
  10566. {
  10567. //DEBUG_INFO("word=%s\n",word);
  10568. if(strstr(word, "chargingProfileId")!= NULL)
  10569. {
  10570. //DEBUG_INFO("test chargingProfileId \n");
  10571. n_chargingProfile = n_chargingProfile + 1;
  10572. i = i + 1;
  10573. //DEBUG_INFO("chargingProfileId Found\n");
  10574. }
  10575. memset(word, 0, ARRAY_SIZE(word));
  10576. }
  10577. fclose(fptr1);
  10578. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10579. }
  10580. }
  10581. //Check TxProfile_%d.json
  10582. for(int j=1; j <= gunTotalNumber; j++)
  10583. {
  10584. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10585. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  10586. if((access(fnametemp,F_OK))!=-1)
  10587. {
  10588. i = 0;
  10589. fptr1 = fopen(fnametemp, "r");
  10590. //Check Charging Profile Count
  10591. while(fscanf(fptr1, "%s", word) != EOF)
  10592. {
  10593. //DEBUG_INFO("word=%s\n",word);
  10594. if(strstr(word, "chargingProfileId")!= NULL)
  10595. {
  10596. //DEBUG_INFO("test chargingProfileId \n");
  10597. n_chargingProfile = n_chargingProfile + 1;
  10598. i = i + 1;
  10599. //DEBUG_INFO("chargingProfileId Found\n");
  10600. }
  10601. memset(word, 0, ARRAY_SIZE(word));
  10602. }
  10603. fclose(fptr1);
  10604. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10605. }
  10606. }
  10607. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  10608. {
  10609. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10610. goto end;
  10611. }
  10612. }
  10613. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10614. //**********************************Write to File********************************************************/
  10615. FILE *infile;
  10616. FILE *outfile;
  10617. infile = fopen (filename, "r");
  10618. outfile = fopen (tempfile, "w");
  10619. int d =0;
  10620. d = fgetc(infile);
  10621. rewind(infile);
  10622. if(d == EOF)
  10623. {
  10624. // Profile is empty
  10625. fprintf(outfile,"%s\n",payload);
  10626. fclose(infile);
  10627. fclose(outfile);
  10628. sprintf(rmFileCmd,"rm -f %s",filename);
  10629. system(rmFileCmd);
  10630. rename(tempfile, filename);
  10631. }
  10632. else
  10633. {
  10634. // Profile is not empty
  10635. char buf[2048]={0};
  10636. int ChargingProfileAdded = FALSE;
  10637. while (fgets(buf, sizeof(buf), infile) != NULL)
  10638. {
  10639. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  10640. json_object *tmpChargingProfile;
  10641. tmpChargingProfile = json_tokener_parse(buf);
  10642. if(!is_error(SetChargingProfile))
  10643. {
  10644. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  10645. {
  10646. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  10647. }
  10648. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  10649. {
  10650. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10651. {
  10652. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10653. }
  10654. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10655. {
  10656. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  10657. }
  10658. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10659. {
  10660. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10661. }
  10662. }
  10663. }
  10664. json_object_put(tmpChargingProfile);
  10665. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  10666. {
  10667. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  10668. {
  10669. //DEBUG_INFO("update set chargingProfile to file -0\n");
  10670. if(ChargingProfileAdded == FALSE)
  10671. {
  10672. fprintf(outfile,"%s\n",payload);
  10673. ChargingProfileAdded = TRUE;
  10674. }
  10675. }
  10676. else
  10677. {
  10678. if(tempstackLevelInt < stackLevelInt)
  10679. {
  10680. if(ChargingProfileAdded == FALSE)
  10681. {
  10682. fprintf(outfile,"%s\n",buf);
  10683. fprintf(outfile,"%s\n",payload);
  10684. ChargingProfileAdded = TRUE;
  10685. }
  10686. else
  10687. {
  10688. fprintf(outfile,"%s\n",buf);
  10689. }
  10690. }
  10691. else
  10692. {
  10693. if(ChargingProfileAdded == FALSE)
  10694. {
  10695. fprintf(outfile,"%s\n",buf);
  10696. fprintf(outfile,"%s\n",payload);
  10697. ChargingProfileAdded = TRUE;
  10698. }
  10699. else
  10700. {
  10701. fprintf(outfile,"%s\n",buf);
  10702. }
  10703. }
  10704. }
  10705. }
  10706. else
  10707. {
  10708. if(tempchargingProfileIdInt < chargingProfileIdInt)
  10709. {
  10710. if(ChargingProfileAdded == FALSE)
  10711. {
  10712. fprintf(outfile,"%s\n",buf);
  10713. fprintf(outfile,"%s\n",payload);
  10714. ChargingProfileAdded = TRUE;
  10715. }
  10716. else
  10717. {
  10718. fprintf(outfile,"%s\n",buf);
  10719. }
  10720. }
  10721. else if(tempstackLevelInt < stackLevelInt)
  10722. {
  10723. if(ChargingProfileAdded == FALSE)
  10724. {
  10725. fprintf(outfile,"%s\n",buf);
  10726. fprintf(outfile,"%s\n",payload);
  10727. ChargingProfileAdded = TRUE;
  10728. }
  10729. else
  10730. {
  10731. fprintf(outfile,"%s\n",buf);
  10732. }
  10733. }
  10734. else
  10735. {
  10736. if(ChargingProfileAdded == FALSE)
  10737. {
  10738. fprintf(outfile,"%s\n",buf);
  10739. fprintf(outfile,"%s\n",payload);
  10740. ChargingProfileAdded = TRUE;
  10741. }
  10742. else
  10743. {
  10744. fprintf(outfile,"%s\n",buf);
  10745. }
  10746. }
  10747. }
  10748. } // end of while loop
  10749. fclose(infile);
  10750. fclose(outfile);
  10751. sprintf(rmFileCmd,"rm -f %s",filename);
  10752. system(rmFileCmd);
  10753. rename(tempfile, filename);
  10754. }
  10755. sleep(1);
  10756. result = TRUE;
  10757. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  10758. end:
  10759. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  10760. {
  10761. if(connectorIdInt == 0)
  10762. {
  10763. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  10764. {
  10765. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  10766. }
  10767. }
  10768. else
  10769. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  10770. }
  10771. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  10772. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10773. return result;
  10774. }
  10775. int handleTriggerMessageRequest(char *uuid, char *payload)
  10776. {
  10777. mtrace();
  10778. int result = FAIL;
  10779. int connectorIdIsNULL = FALSE;
  10780. int connectorIdInt =0;
  10781. char sstr[40]={0},sstrtemp[100]={ 0 };
  10782. char requestedMessagestr[40]={0};
  10783. char comfirmstr[20]={0};
  10784. int c = 0;
  10785. char *loc;
  10786. DEBUG_INFO("handleTriggerMessageRequest\n");
  10787. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  10788. strcpy(sstrtemp, stringtrimspace(payload));
  10789. c = 0;
  10790. loc = strstr(sstrtemp, "requestedMessage");
  10791. while (loc[3+strlen("requestedMessage")+c] != '\"')
  10792. {
  10793. sstr[c] = loc[3+strlen("requestedMessage")+c];
  10794. c++;
  10795. }
  10796. sstr[c] = '\0';
  10797. strcpy(requestedMessagestr, sstr);
  10798. c = 0;
  10799. loc = strstr(sstrtemp, "connectorId");
  10800. if(loc == NULL)
  10801. {
  10802. connectorIdIsNULL = TRUE;
  10803. }
  10804. else
  10805. {
  10806. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10807. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  10808. {
  10809. sstr[c] = loc[strlen("connectorId")+2+c];
  10810. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10811. c++;
  10812. }
  10813. sstr[c] = '\0';
  10814. connectorIdInt = atoi(sstr);
  10815. }
  10816. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  10817. {
  10818. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  10819. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  10820. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10821. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  10822. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  10823. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  10824. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  10825. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  10826. {
  10827. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10828. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10829. return TRUE;
  10830. }
  10831. else
  10832. {
  10833. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10834. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10835. }
  10836. }
  10837. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  10838. {
  10839. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  10840. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10841. return TRUE;
  10842. }
  10843. //==========================
  10844. // Trigger message
  10845. //==========================
  10846. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10847. {
  10848. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  10849. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10850. {
  10851. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10852. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10853. }
  10854. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10855. }
  10856. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  10857. {
  10858. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  10859. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10860. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10861. }
  10862. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  10863. {
  10864. //sendBootNotificationRequest();
  10865. server_sign = FALSE;
  10866. }
  10867. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  10868. {
  10869. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  10870. }
  10871. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  10872. {
  10873. if(connectorIdIsNULL == FALSE)
  10874. {
  10875. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10876. {
  10877. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  10878. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  10879. }
  10880. }
  10881. else
  10882. {
  10883. for(int idx=0;idx< gunTotalNumber;idx++)
  10884. {
  10885. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10886. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10887. }
  10888. }
  10889. }
  10890. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  10891. {
  10892. if(connectorIdIsNULL == FALSE)
  10893. {
  10894. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  10895. {
  10896. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  10897. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  10898. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  10899. }
  10900. }
  10901. else
  10902. {
  10903. for(int idx=0;idx< gunTotalNumber;idx++)
  10904. {
  10905. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  10906. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  10907. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  10908. }
  10909. }
  10910. }
  10911. return result;
  10912. }
  10913. int handleUnlockConnectorRequest(char *uuid, char *payload)
  10914. {
  10915. mtrace();
  10916. int result = FAIL;
  10917. int connectorIdInt =0;
  10918. char comfirmstr[20]={0};
  10919. int tempIndex = 0;
  10920. json_object *UnlockConnector;
  10921. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  10922. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  10923. UnlockConnector = json_tokener_parse(payload);
  10924. if(!is_error(UnlockConnector))
  10925. {
  10926. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  10927. {
  10928. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  10929. }
  10930. }
  10931. json_object_put(UnlockConnector);
  10932. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  10933. if(gunTotalNumber == 0)
  10934. {
  10935. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10936. goto end;
  10937. }
  10938. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  10939. {
  10940. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10941. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10942. goto end;
  10943. }
  10944. else
  10945. {
  10946. //check Transaction active
  10947. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  10948. {
  10949. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10950. {
  10951. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10952. }
  10953. else
  10954. {
  10955. tempIndex = connectorIdInt -1;
  10956. }
  10957. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10958. {
  10959. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10960. {
  10961. //stop Transaction
  10962. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10963. }
  10964. }
  10965. }
  10966. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  10967. {
  10968. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10969. {
  10970. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10971. }
  10972. else
  10973. {
  10974. tempIndex = connectorIdInt -1;
  10975. }
  10976. for (int index = 0; index < CCS_QUANTITY; index++)
  10977. {
  10978. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10979. {
  10980. //stop Transaction
  10981. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10982. }
  10983. }
  10984. }
  10985. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  10986. {
  10987. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10988. {
  10989. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10990. }
  10991. else
  10992. {
  10993. tempIndex = connectorIdInt -1;
  10994. }
  10995. for (int index = 0; index < GB_QUANTITY; index++)
  10996. {
  10997. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  10998. {
  10999. //stop Transaction
  11000. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11001. }
  11002. }
  11003. }
  11004. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  11005. {
  11006. tempIndex = connectorIdInt -1;
  11007. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11008. {
  11009. 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)))
  11010. {
  11011. //stop Transaction
  11012. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11013. }
  11014. }
  11015. }
  11016. else
  11017. {
  11018. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11019. {
  11020. tempIndex = 2;
  11021. }
  11022. else
  11023. {
  11024. tempIndex = connectorIdInt-1;
  11025. }
  11026. for (int index = 0; index < AC_QUANTITY; index++)
  11027. {
  11028. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11029. {
  11030. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11031. }
  11032. }
  11033. }
  11034. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  11035. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  11036. result = TRUE;
  11037. return result;
  11038. }
  11039. end:
  11040. //json_object_put(obj); --- remove temporally
  11041. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  11042. return result;
  11043. }
  11044. static char UpdateFirmwarepayloadData[300]={0};
  11045. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  11046. {
  11047. mtrace();
  11048. int result = FAIL;
  11049. pthread_t t;
  11050. sendUpdateFirmwareConfirmation(uuid);
  11051. memset(UpdateFirmwarepayloadData, 0, 300);
  11052. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  11053. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  11054. ////pthread_join(t, NULL); //
  11055. //pthread_detach(t);
  11056. //sendUpdateFirmwareConfirmation(uuid);
  11057. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  11058. return result;
  11059. }
  11060. void *UpdateFirmwareProcess(void *data)
  11061. {
  11062. pthread_detach(pthread_self());
  11063. mtrace();
  11064. int retriesInt =0, retryIntervalInt=0;
  11065. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  11066. int port=0;
  11067. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  11068. int isSuccess = 0;
  11069. char ftpbuf[1024];
  11070. char temp[1024];
  11071. char * pch;
  11072. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  11073. json_object *UpdateFirmware;
  11074. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  11075. if(!is_error(UpdateFirmware))
  11076. {
  11077. // Required data
  11078. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  11079. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  11080. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  11081. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  11082. // Optional data
  11083. if(json_object_object_get(UpdateFirmware, "retries"))
  11084. {
  11085. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  11086. }
  11087. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  11088. {
  11089. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  11090. }
  11091. }
  11092. json_object_put(UpdateFirmware);
  11093. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11094. memset(path, 0, ARRAY_SIZE(path));
  11095. // Wait retrieveData
  11096. if(strlen(retrieveDatestr) > 10)
  11097. {
  11098. do
  11099. {
  11100. sleep(1);
  11101. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  11102. }
  11103. // Ready to download
  11104. system("rm -f /mnt/*");
  11105. if(strncmp(locationstr,"http", 4) == 0)
  11106. {
  11107. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11108. sprintf(ftppath,"/%s", path);
  11109. DEBUG_INFO("locationstr: %s\n", locationstr);
  11110. DEBUG_INFO("protocol: %s\n",protocol);
  11111. DEBUG_INFO("host: %s\n",host);
  11112. DEBUG_INFO("path: %s\n",path);
  11113. DEBUG_INFO("ftppath: %s\n",ftppath);
  11114. int ftppathlen=strlen(ftppath);
  11115. int i=1;
  11116. char filenametemp[50];
  11117. while(i < ftppathlen)
  11118. {
  11119. int len=ftppathlen-i;
  11120. if(ftppath[len]== 47) // '/' ascll code: 47
  11121. {
  11122. DEBUG_INFO("compare '/' all right\n");
  11123. break;
  11124. }
  11125. i=i+1;
  11126. }
  11127. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11128. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11129. filenametemp[i+1] = 0;
  11130. do
  11131. {
  11132. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11133. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11134. sleep(1);
  11135. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  11136. if(!isSuccess)
  11137. {
  11138. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11139. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11140. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11141. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11142. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11143. }
  11144. else
  11145. {
  11146. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11147. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11148. }
  11149. retriesInt--;
  11150. }while((isSuccess == 0)&&(retriesInt >= 0));
  11151. }
  11152. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  11153. {
  11154. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  11155. memset(temp, 0, ARRAY_SIZE(temp));
  11156. //DEBUG_INFO("locationstr=%s\n",locationstr);
  11157. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  11158. int ftppathlen=strlen(ftpbuf);
  11159. int i=1;
  11160. char filenametemp[50];
  11161. while(i < ftppathlen)
  11162. {
  11163. int len=ftppathlen-i;
  11164. if(ftpbuf[len]== 47) // '/' ascll code: 47
  11165. {
  11166. DEBUG_INFO(" compare '/' all right\n");
  11167. break;
  11168. }
  11169. i=i+1;
  11170. }
  11171. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11172. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  11173. filenametemp[i+1] = 0;
  11174. strncpy(temp, ftpbuf, ftppathlen-i+1);
  11175. pch=strchr(temp,'@');
  11176. if(pch==NULL)
  11177. {
  11178. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11179. protocol, host, &port, path);
  11180. strcpy(user,"anonymous");
  11181. strcpy(password,"");
  11182. }
  11183. else
  11184. {
  11185. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11186. protocol, user, password, host, &port, path);
  11187. }
  11188. sscanf(host,"%[^/]%s",host1, path1);
  11189. sprintf(ftppath,"%s", path1);
  11190. //DEBUG_INFO("protocol =%s\n",protocol);
  11191. //DEBUG_INFO("user =%s\n",user);
  11192. //DEBUG_INFO("password =%s\n",password);
  11193. //DEBUG_INFO("host1 =%s\n",host1);
  11194. //DEBUG_INFO("port =%d\n",port);
  11195. //DEBUG_INFO("path1 =%s\n",path1);
  11196. //DEBUG_INFO("ftppath=%s\n",ftppath);
  11197. //ftpFile(host, user, password, port, ftppath, fname);
  11198. //download firmware pthred
  11199. if(port == 0)
  11200. {
  11201. port = 21;
  11202. }
  11203. do
  11204. {
  11205. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11206. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11207. sleep(1);
  11208. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  11209. if(!isSuccess)
  11210. {
  11211. //BulldogUtil.sleepMs(interval*1000);
  11212. DEBUG_INFO("Update firmware request and download file fail.\n");
  11213. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11214. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11215. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11216. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11217. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11218. }
  11219. else
  11220. {
  11221. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11222. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11223. }
  11224. retriesInt--;
  11225. }while((!isSuccess)&&(retriesInt >= 0));
  11226. }
  11227. else
  11228. {
  11229. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11230. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11231. sleep(1);
  11232. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11233. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11234. }
  11235. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  11236. pthread_exit(NULL);
  11237. }
  11238. int handleCertificateSignedRequest(char *uuid, char *payload)
  11239. {
  11240. mtrace();
  11241. int result = PASS;
  11242. json_object *CertificateSigned;
  11243. DEBUG_INFO("handleCertificateSignedRequest...\n");
  11244. CertificateSigned = json_tokener_parse(payload);
  11245. if(!is_error(CertificateSigned))
  11246. {
  11247. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  11248. }
  11249. json_object_put(CertificateSigned);
  11250. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  11251. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  11252. fclose(fp);
  11253. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11254. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  11255. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  11256. sendCertificateSignedConfirmation(uuid);
  11257. return result;
  11258. }
  11259. int handleDeleteCertificateRequest(char *uuid, char *payload)
  11260. {
  11261. mtrace();
  11262. int result = PASS;
  11263. json_object *DeleteCertificate;
  11264. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  11265. DeleteCertificate = json_tokener_parse(payload);
  11266. if(!is_error(DeleteCertificate))
  11267. {
  11268. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  11269. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  11270. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  11271. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  11272. }
  11273. json_object_put(DeleteCertificate);
  11274. /*
  11275. * TODO: Delete certificateSigned process
  11276. */
  11277. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  11278. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  11279. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  11280. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  11281. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  11282. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  11283. sendDeleteCertificateConfirmation(uuid);
  11284. return result;
  11285. }
  11286. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  11287. {
  11288. mtrace();
  11289. int result = PASS;
  11290. json_object *ExtendedTriggerMessage;
  11291. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  11292. ExtendedTriggerMessage = json_tokener_parse(payload);
  11293. if(!is_error(ExtendedTriggerMessage))
  11294. {
  11295. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  11296. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  11297. {
  11298. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  11299. }
  11300. else
  11301. {
  11302. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  11303. }
  11304. }
  11305. json_object_put(ExtendedTriggerMessage);
  11306. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  11307. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  11308. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  11309. {
  11310. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  11311. }
  11312. else
  11313. {
  11314. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  11315. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  11316. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11317. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  11318. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  11319. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  11320. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  11321. {
  11322. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11323. }
  11324. else
  11325. {
  11326. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11327. }
  11328. }
  11329. sendExtendedTriggerMessageConfirmation(uuid);
  11330. //==========================
  11331. // Trigger message
  11332. //==========================
  11333. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  11334. {
  11335. //sendBootNotificationRequest();
  11336. server_sign = FALSE;
  11337. }
  11338. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  11339. {
  11340. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  11341. }
  11342. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11343. {
  11344. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  11345. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11346. {
  11347. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11348. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11349. }
  11350. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11351. }
  11352. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  11353. {
  11354. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  11355. }
  11356. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  11357. {
  11358. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11359. {
  11360. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  11361. }
  11362. else
  11363. {
  11364. for(int idx=0;idx< gunTotalNumber;idx++)
  11365. {
  11366. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11367. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11368. }
  11369. }
  11370. }
  11371. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  11372. {
  11373. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  11374. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  11375. {
  11376. 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\" &");
  11377. }
  11378. }
  11379. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  11380. {
  11381. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11382. {
  11383. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  11384. }
  11385. else
  11386. {
  11387. for(int idx=0;idx< gunTotalNumber;idx++)
  11388. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  11389. }
  11390. }
  11391. return result;
  11392. }
  11393. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  11394. {
  11395. mtrace();
  11396. int result = PASS;
  11397. json_object *GetInstalledCertificateIds;
  11398. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  11399. GetInstalledCertificateIds = json_tokener_parse(payload);
  11400. if(!is_error(GetInstalledCertificateIds))
  11401. {
  11402. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  11403. }
  11404. json_object_put(GetInstalledCertificateIds);
  11405. /*
  11406. * TODO: Return installed certificate process
  11407. */
  11408. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  11409. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  11410. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  11411. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  11412. sendGetInstalledCertificateIdsConfirmation(uuid);
  11413. return result;
  11414. }
  11415. int handleGetLogRequest(char *uuid, char *payload)
  11416. {
  11417. mtrace();
  11418. int result = PASS;
  11419. json_object *GetLog;
  11420. DEBUG_INFO("handleGetLogRequest...\n");
  11421. GetLog = json_tokener_parse(payload);
  11422. if(!is_error(GetLog))
  11423. {
  11424. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  11425. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  11426. if(json_object_object_get(GetLog, "retries") != NULL)
  11427. {
  11428. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  11429. }
  11430. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  11431. {
  11432. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  11433. }
  11434. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  11435. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  11436. {
  11437. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  11438. }
  11439. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  11440. {
  11441. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  11442. }
  11443. }
  11444. json_object_put(GetLog);
  11445. /*
  11446. * TODO: Upload log process
  11447. */
  11448. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  11449. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  11450. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  11451. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  11452. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  11453. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  11454. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  11455. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  11456. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  11457. sendGetLogConfirmation(uuid);
  11458. return result;
  11459. }
  11460. int handleInstallCertificateRequest(char *uuid, char *payload)
  11461. {
  11462. mtrace();
  11463. int result = PASS;
  11464. json_object *InstallCertificate;
  11465. DEBUG_INFO("handleInstallCertificateRequest...\n");
  11466. InstallCertificate = json_tokener_parse(payload);
  11467. if(!is_error(InstallCertificate))
  11468. {
  11469. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  11470. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  11471. /*
  11472. * TODO: Install certificate process
  11473. */
  11474. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  11475. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  11476. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  11477. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  11478. sendInstallCertificateConfirmation(uuid);
  11479. }
  11480. json_object_put(InstallCertificate);
  11481. return result;
  11482. }
  11483. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  11484. {
  11485. mtrace();
  11486. int result = PASS;
  11487. json_object *SignedUpdateFirmware;
  11488. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  11489. SignedUpdateFirmware = json_tokener_parse(payload);
  11490. if(!is_error(SignedUpdateFirmware))
  11491. {
  11492. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  11493. {
  11494. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  11495. }
  11496. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  11497. {
  11498. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  11499. }
  11500. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  11501. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  11502. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  11503. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  11504. {
  11505. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  11506. }
  11507. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  11508. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  11509. }
  11510. json_object_put(SignedUpdateFirmware);
  11511. /*
  11512. * TODO: Upgrade firmware process
  11513. */
  11514. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  11515. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  11516. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  11517. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  11518. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  11519. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  11520. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  11521. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  11522. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  11523. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  11524. sendInstallCertificateConfirmation(uuid);
  11525. return result;
  11526. }
  11527. int handleUnknownRequest(char *uuid, char *payload)
  11528. {
  11529. mtrace();
  11530. int result = PASS;
  11531. DEBUG_INFO("handleUnknownRequest...\n");
  11532. sendUnknownConfirmation(uuid);
  11533. result = PASS;
  11534. return result;
  11535. }
  11536. //==========================================
  11537. // Handle server response routine
  11538. //==========================================
  11539. void handleAuthorizeResponse(char *payload, int gun_index)
  11540. {
  11541. mtrace();
  11542. char expiryDatestr[30]={0};
  11543. char parentIdTagstr[20]={0};
  11544. char statusstr[20]={0};
  11545. int expiryDateISNULL=FALSE;
  11546. int parentIdTagISNULL=FALSE;
  11547. DEBUG_INFO("handleAuthorizeResponse...\n");
  11548. json_object *Authorize;
  11549. Authorize = json_tokener_parse(payload);
  11550. if(!is_error(Authorize))
  11551. {
  11552. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  11553. {
  11554. // Required data
  11555. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  11556. // Optional data
  11557. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  11558. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  11559. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  11560. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  11561. }
  11562. }
  11563. json_object_put(Authorize);
  11564. if(expiryDateISNULL == FALSE)
  11565. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  11566. if(parentIdTagISNULL == FALSE)
  11567. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  11568. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  11569. //Update idTag information to authorization cache if supproted
  11570. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  11571. {
  11572. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  11573. }
  11574. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  11575. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  11576. authorizeRetryTimes = 0;
  11577. }
  11578. void handleBootNotificationResponse(char *payload, int gun_index)
  11579. {
  11580. mtrace();
  11581. char statusStr[12]={0};
  11582. char currentTimeStr[30]={0};
  11583. int intervalInt = 0;
  11584. DEBUG_INFO("handleBootNotificationResponse...\n");
  11585. json_object *BootNotification;
  11586. BootNotification = json_tokener_parse(payload);
  11587. if(!is_error(BootNotification))
  11588. {
  11589. // Required data
  11590. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  11591. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  11592. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  11593. }
  11594. json_object_put(BootNotification);
  11595. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11596. BootNotificationInterval = intervalInt;
  11597. HeartBeatWaitTime = intervalInt;
  11598. //write back to ShmOCPP16Data->BootNotification
  11599. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  11600. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11601. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  11602. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  11603. {
  11604. server_sign = TRUE;
  11605. server_pending =FALSE;
  11606. }
  11607. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  11608. {
  11609. server_pending = TRUE;
  11610. }
  11611. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  11612. srand(time(NULL));
  11613. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  11614. SetOcppConnStatus(TRUE);
  11615. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  11616. }
  11617. void handleDataTransferResponse(char *payload, int gun_index)
  11618. {
  11619. char sstr[160]={0};//sstr[200]={ 0 };
  11620. int c = 0;
  11621. char *loc;
  11622. DEBUG_INFO("handleDataTransferResponse ...\n");
  11623. loc = strstr(payload, "status");
  11624. c = 0;
  11625. while (loc[3+strlen("status")+c] != '\"')
  11626. {
  11627. sstr[c] = loc[3+strlen("status")+c];
  11628. c++;
  11629. }
  11630. sstr[c] = '\0';
  11631. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  11632. }
  11633. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  11634. {
  11635. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  11636. //struct json_object *obj;
  11637. // obj = json_tokener_parse(payload);
  11638. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  11639. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  11640. //No fields are defined.
  11641. }
  11642. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11643. {
  11644. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  11645. //struct json_object *obj;
  11646. // obj = json_tokener_parse(payload);
  11647. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  11648. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  11649. //No fields are defined.
  11650. }
  11651. void handleHeartbeatResponse(char *payload, int gun_index)
  11652. {
  11653. mtrace();
  11654. DEBUG_INFO("handleHeartbeatResponse...\n");
  11655. json_object *Heartbeat;
  11656. Heartbeat = json_tokener_parse(payload);
  11657. if(!is_error(Heartbeat))
  11658. {
  11659. // Required data
  11660. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  11661. }
  11662. json_object_put(Heartbeat);
  11663. if(FirstHeartBeat == 0)
  11664. {
  11665. FirstHeartBeat = 1;
  11666. DEBUG_INFO("FirstHeartBeat \n");
  11667. }
  11668. HeartBeatWithNOResponse = 0;
  11669. clientTime.Heartbeat=time((time_t*)NULL);
  11670. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  11671. }
  11672. void handleMeterValuesResponse(char *payload, int gun_index)
  11673. {
  11674. mtrace();
  11675. DEBUG_INFO("handleMeterValuesResponse...\n");
  11676. }
  11677. void handleStartTransactionResponse(char *payload, int gun_index)
  11678. {
  11679. mtrace();
  11680. //int transactionIdInt = 0;
  11681. FILE *outfile;
  11682. char data[100]={0};
  11683. DEBUG_INFO("handleStartTransactionResponse...\n");
  11684. json_object *StartTransaction;
  11685. StartTransaction = json_tokener_parse(payload);
  11686. if(!is_error(StartTransaction))
  11687. {
  11688. // Required data
  11689. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  11690. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  11691. // Optional data
  11692. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  11693. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  11694. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11695. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  11696. }
  11697. json_object_put(StartTransaction);
  11698. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  11699. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  11700. //-----------Start : write to the Queue TransactionId file -----------------//
  11701. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  11702. {}
  11703. else
  11704. {
  11705. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  11706. if(log == NULL)
  11707. {
  11708. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  11709. return ;
  11710. }
  11711. else
  11712. {
  11713. fclose(log);
  11714. }
  11715. }
  11716. // open file for writing
  11717. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  11718. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  11719. {
  11720. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  11721. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  11722. fputs(data, outfile);
  11723. fclose (outfile);
  11724. }
  11725. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11726. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11727. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  11728. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  11729. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11730. }
  11731. void handleStatusNotificationResponse(char *payload, int gun_index)
  11732. {
  11733. mtrace();
  11734. DEBUG_INFO("handleStatusNotificationResponse...\n");
  11735. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  11736. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  11737. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  11738. }
  11739. void handleStopTransactionnResponse(char *payload, int gun_index)
  11740. {
  11741. mtrace();
  11742. DEBUG_INFO("handleStopTransactionnResponse...\n");
  11743. json_object *StopTransaction;
  11744. StopTransaction = json_tokener_parse(payload);
  11745. if(!is_error(StopTransaction))
  11746. {
  11747. // Optional data
  11748. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  11749. {
  11750. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  11751. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  11752. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  11753. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11754. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  11755. }
  11756. }
  11757. json_object_put(StopTransaction);
  11758. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  11759. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  11760. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11761. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11762. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  11763. }
  11764. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  11765. {
  11766. mtrace();
  11767. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  11768. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  11769. }
  11770. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  11771. {
  11772. mtrace();
  11773. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  11774. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  11775. }
  11776. void handleSignCertificateResponse(char *payload, int gun_index)
  11777. {
  11778. mtrace();
  11779. DEBUG_INFO("handleSignCertificateResponse...\n");
  11780. json_object *SignCertificate;
  11781. SignCertificate = json_tokener_parse(payload);
  11782. if(!is_error(SignCertificate))
  11783. {
  11784. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  11785. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  11786. }
  11787. json_object_put(SignCertificate);
  11788. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  11789. }
  11790. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11791. {
  11792. mtrace();
  11793. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  11794. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  11795. }
  11796. //==========================================
  11797. // Handle Error routine
  11798. //==========================================
  11799. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  11800. {
  11801. mtrace();
  11802. #ifdef SystemLogMessage
  11803. DEBUG_INFO("errorCode: %s\n", errorCode);
  11804. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  11805. DEBUG_INFO("errorDetails: %s\n", payload);
  11806. #endif
  11807. }
  11808. //===============================================
  11809. // Common routine
  11810. //===============================================
  11811. int initialConfigurationTable(void)
  11812. {
  11813. //clock_t start_t, end_t, total_t;
  11814. FILE *fp;
  11815. FILE *outfile;
  11816. char str[512]={0};
  11817. char sstr[256]={0};
  11818. int c = 0;
  11819. char *loc;
  11820. int confVersion = 5;
  11821. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  11822. //start_t = clock();
  11823. //printf("Starting of the program, start_t = %ld\n", start_t);
  11824. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  11825. // Check configuration file size is correct
  11826. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  11827. {
  11828. struct stat st;
  11829. stat("/Storage/OCPP/OCPPConfiguration", &st);
  11830. if(st.st_size < 3100)
  11831. {
  11832. system("rm -f /Storage/OCPP/OCPPConfiguration");
  11833. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  11834. }
  11835. }
  11836. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  11837. {
  11838. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11839. if(outfile == NULL)
  11840. {
  11841. DEBUG_INFO("Error opening file\n");
  11842. return FALSE;
  11843. }
  11844. /*Core Profile*/
  11845. //AllowOfflineTxForUnknownId
  11846. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11847. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  11849. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11850. //AuthorizationCacheEnabled
  11851. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11854. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11855. //AuthorizeRemoteTxRequests
  11856. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  11859. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11860. //BlinkRepeat
  11861. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11864. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11865. //ClockAlignedDataInterval
  11866. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11868. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11869. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11870. //ConnectionTimeOut
  11871. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11874. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11875. //GetConfigurationMaxKeys
  11876. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11878. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  11879. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11880. // HeartbeatInterval
  11881. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  11884. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11885. // LightIntensity
  11886. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11890. // LocalAuthorizeOffline
  11891. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  11892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11894. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11895. // LocalPreAuthorize
  11896. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  11897. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11898. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11899. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11900. // MaxEnergyOnInvalidId
  11901. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11903. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11904. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11905. // MeterValuesAlignedData
  11906. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11908. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11909. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11910. else
  11911. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11912. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11913. // MeterValuesAlignedDataMaxLength
  11914. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11916. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11917. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  11918. else
  11919. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  11920. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11921. // MeterValuesSampledData
  11922. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11923. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11924. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11925. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11926. else
  11927. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11928. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11929. // MeterValuesSampledDataMaxLength
  11930. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11931. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11932. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11933. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  11934. else
  11935. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  11936. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11937. // MeterValueSampleInterval
  11938. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11939. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11940. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  11941. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11942. // MinimumStatusDuration
  11943. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11945. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  11946. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  11947. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11948. // NumberOfConnectors
  11949. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11951. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11952. {
  11953. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11954. }
  11955. else
  11956. {
  11957. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11958. }
  11959. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11960. // ResetRetries
  11961. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11962. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11963. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11964. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11965. // ConnectorPhaseRotation
  11966. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11967. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11968. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11969. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11970. // ConnectorPhaseRotationMaxLength
  11971. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11973. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11974. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11975. // StopTransactionOnEVSideDisconnect
  11976. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11979. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11980. // StopTransactionOnInvalidId
  11981. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  11982. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11983. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11984. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11985. // StopTxnAlignedData
  11986. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  11987. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11988. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  11989. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11990. // StopTxnAlignedDataMaxLength
  11991. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11994. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11995. // StopTxnSampledData
  11996. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11997. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11998. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  12000. else
  12001. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12002. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12003. // StopTxnSampledDataMaxLength
  12004. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12005. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12006. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12007. {
  12008. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  12009. }
  12010. else
  12011. {
  12012. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  12013. }
  12014. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12015. // SupportedFeatureProfiles
  12016. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12017. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12018. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12019. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12020. // SupportedFeatureProfilesMaxLength
  12021. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12022. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12023. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12024. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12025. // TransactionMessageAttempts
  12026. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12029. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12030. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12031. // TransactionMessageRetryInterval
  12032. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12033. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12035. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12036. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12037. // UnlockConnectorOnEVSideDisconnect
  12038. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12039. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12040. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12041. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12042. // WebSocketPingInterval
  12043. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12044. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12045. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12046. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12047. // QueueOffLineStartTransactionMessage
  12048. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  12049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12051. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12052. // AuthorizationKey
  12053. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12056. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12057. // SecurityProfile
  12058. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12060. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  12061. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12062. // DefaultPrice
  12063. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12066. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12067. // CustomDisplayCostAndPrice
  12068. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12071. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12072. // CustomIdleFeeAfterStop
  12073. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12076. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12077. // TimeOffset
  12078. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  12079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  12080. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  12081. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  12082. // NextTimeOffsetTransitionDateTime
  12083. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  12084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  12085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  12086. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  12087. // TimeOffsetNextTransition
  12088. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  12089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  12090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  12091. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  12092. // Configuration Version
  12093. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  12094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12095. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  12096. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12097. //* Local Auth List Management Profile*/
  12098. #if 0
  12099. //For OCTT Test Case
  12100. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  12102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12103. #endif
  12104. #if 1
  12105. //LocalAuthListEnabled
  12106. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12109. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12110. #endif
  12111. //LocalAuthListMaxLength
  12112. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12115. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12116. //SendLocalListMaxLength
  12117. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  12120. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12121. //ReserveConnectorZeroSupported
  12122. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12123. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12124. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12125. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12126. //* Smart Charging Profile */
  12127. //ChargeProfileMaxStackLevel
  12128. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12130. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12131. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12132. // ChargingScheduleAllowedChargingRateUnit
  12133. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12135. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  12136. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12137. // ChargingScheduleMaxPeriods
  12138. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12141. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12142. // ConnectorSwitch3to1PhaseSupported
  12143. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12144. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12145. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  12146. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12147. // MaxChargingProfilesInstalled
  12148. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12149. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12150. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12151. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12152. fclose(outfile);
  12153. }
  12154. else
  12155. {
  12156. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  12157. char keystr[60]={0};
  12158. char readonlystr[10]={0};
  12159. char valuestr[256]={0};
  12160. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  12161. if(fp == NULL) {
  12162. DEBUG_INFO("Error opening file");
  12163. return FALSE;
  12164. }
  12165. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  12166. {
  12167. //DEBUG_INFO("Get Configuration \n");
  12168. if(strlen(str) > 0)
  12169. {
  12170. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12171. //*************************key*********************************/
  12172. if(strstr(str, "key") != NULL)
  12173. {
  12174. loc = strstr(str, "key");
  12175. c = 0;
  12176. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12177. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12178. {
  12179. sstr[c] = loc[strlen("key")+3+c];
  12180. c++;
  12181. }
  12182. sstr[c] = '\0';
  12183. strcpy(keystr,sstr);
  12184. }
  12185. //*************************readonly*********************************/
  12186. if(strstr(str, "readonly") != NULL)
  12187. {
  12188. loc = strstr(str, "readonly");
  12189. c = 0;
  12190. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12191. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  12192. {
  12193. sstr[c] = loc[strlen("readonly")+2+c];
  12194. c++;
  12195. }
  12196. sstr[c] = '\0';
  12197. strcpy(readonlystr,sstr);
  12198. }
  12199. //*************************value*********************************/
  12200. if(strstr(str, "value") != NULL)
  12201. {
  12202. loc = strstr(str, "value");
  12203. c = 0;
  12204. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12205. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12206. {
  12207. sstr[c] = loc[strlen("value")+3+c];
  12208. c++;
  12209. }
  12210. sstr[c] = '\0';
  12211. strcpy(valuestr,sstr);
  12212. }
  12213. // DEBUG_INFO("keystr=%s\n",keystr);
  12214. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  12215. // DEBUG_INFO("valuestr=%s\n",valuestr);
  12216. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  12217. {
  12218. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12219. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12220. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  12221. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12222. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12223. }
  12224. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  12225. {
  12226. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12227. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12228. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  12229. }
  12230. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  12231. {
  12232. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12233. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  12234. }
  12235. if(strcmp(keystr, "BlinkRepeat") == 0)
  12236. {
  12237. //Charger.BlinkRepeat = Integer.parseInt(value);
  12238. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12239. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  12240. }
  12241. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  12242. {
  12243. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12244. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  12245. }
  12246. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  12247. {
  12248. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12249. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  12250. }
  12251. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  12252. {
  12253. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12254. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  12255. }
  12256. if(strcmp(keystr, "HeartbeatInterval") == 0)
  12257. {
  12258. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12259. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  12260. HeartBeatWaitTime = atoi(valuestr);
  12261. }
  12262. if(strcmp(keystr, "LightIntensity") == 0)
  12263. {
  12264. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12265. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  12266. }
  12267. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  12268. {
  12269. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12270. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  12271. }
  12272. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  12273. {
  12274. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12275. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  12276. }
  12277. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  12278. {
  12279. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12280. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  12281. }
  12282. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  12283. {
  12284. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12285. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  12286. }
  12287. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  12288. {
  12289. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12290. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  12291. }
  12292. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  12293. {
  12294. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12295. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  12296. }
  12297. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  12298. {
  12299. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12300. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  12301. }
  12302. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  12303. {
  12304. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12305. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  12306. }
  12307. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  12308. {
  12309. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12310. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  12311. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  12312. }
  12313. if(strcmp(keystr, "NumberOfConnectors") == 0)
  12314. {
  12315. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12316. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  12317. }
  12318. if(strcmp(keystr, "ResetRetries") == 0)
  12319. {
  12320. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12321. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  12322. }
  12323. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  12324. {
  12325. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12326. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  12327. }
  12328. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  12329. {
  12330. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12331. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  12332. }
  12333. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  12334. {
  12335. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12336. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  12337. }
  12338. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  12339. {
  12340. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12341. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  12342. }
  12343. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  12344. {
  12345. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12346. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  12347. }
  12348. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  12349. {
  12350. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12351. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12352. }
  12353. if(strcmp(keystr, "StopTxnSampledData") == 0)
  12354. {
  12355. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12356. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  12357. }
  12358. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  12359. {
  12360. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12361. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12362. }
  12363. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  12364. {
  12365. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12366. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  12367. }
  12368. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  12369. {
  12370. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12371. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  12372. }
  12373. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  12374. {
  12375. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12376. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  12377. TransactionMessageAttemptsValue = atoi(valuestr);
  12378. }
  12379. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  12380. {
  12381. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12382. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  12383. TransactionMessageRetryIntervalValue = atoi(valuestr);
  12384. }
  12385. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  12386. {
  12387. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12388. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  12389. }
  12390. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  12391. {
  12392. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12393. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  12394. }
  12395. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  12396. {
  12397. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12398. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  12399. }
  12400. if(strcmp(keystr, "AuthorizationKey") == 0)
  12401. {
  12402. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12403. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  12404. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12405. }
  12406. if(strcmp(keystr, "SecurityProfile") == 0)
  12407. {
  12408. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12409. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  12410. }
  12411. if(strcmp(keystr, "DefaultPrice") == 0)
  12412. {
  12413. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12414. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  12415. }
  12416. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  12417. {
  12418. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12419. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  12420. }
  12421. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  12422. {
  12423. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12424. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  12425. }
  12426. if(strcmp(keystr, "TimeOffset") == 0)
  12427. {
  12428. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12429. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  12430. }
  12431. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  12432. {
  12433. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12434. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  12435. }
  12436. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  12437. {
  12438. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12439. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  12440. }
  12441. if(strcmp(keystr, "ConfigurationVersion") == 0)
  12442. {
  12443. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12444. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  12445. }
  12446. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  12447. {
  12448. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12449. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  12450. }
  12451. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  12452. {
  12453. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12454. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  12455. }
  12456. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  12457. {
  12458. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12459. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  12460. }
  12461. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  12462. {
  12463. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12464. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  12465. }
  12466. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  12467. {
  12468. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12469. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  12470. }
  12471. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12472. {
  12473. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12474. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  12475. }
  12476. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  12477. {
  12478. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12479. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  12480. }
  12481. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  12482. {
  12483. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12484. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  12485. }
  12486. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  12487. {
  12488. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12489. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  12490. }
  12491. }
  12492. }
  12493. fclose(fp);
  12494. }
  12495. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  12496. {
  12497. return PASS;
  12498. }
  12499. else
  12500. {
  12501. return FAIL;
  12502. }
  12503. }
  12504. void StoreConfigurationTable(void)
  12505. {
  12506. FILE *outfile;
  12507. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  12508. if(outfile == NULL)
  12509. {
  12510. DEBUG_INFO("Error opening file");
  12511. return ;
  12512. }
  12513. /*Core Profile*/
  12514. //AllowOfflineTxForUnknownId
  12515. /*
  12516. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12517. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  12518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12519. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  12520. */
  12521. //DEBUG_INFO("data=%s\n",data);
  12522. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12523. //AuthorizationCacheEnabled
  12524. /*
  12525. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12527. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12528. */
  12529. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12530. //AuthorizeRemoteTxRequests
  12531. /*
  12532. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12534. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  12535. */
  12536. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12537. //BlinkRepeat
  12538. /*
  12539. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12540. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12542. */
  12543. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12544. //ClockAlignedDataInterval
  12545. /*
  12546. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12548. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12549. */
  12550. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12551. //ConnectionTimeOut
  12552. /*
  12553. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12554. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12555. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12556. */
  12557. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12558. //GetConfigurationMaxKeys
  12559. /*
  12560. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  12563. */
  12564. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12565. // HeartbeatInterval
  12566. /*
  12567. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  12570. */
  12571. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12572. // LightIntensity
  12573. /*
  12574. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12577. */
  12578. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12579. // LocalAuthorizeOffline
  12580. /*
  12581. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  12582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12584. */
  12585. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12586. // LocalPreAuthorize
  12587. /*
  12588. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  12589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12591. */
  12592. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12593. // MaxEnergyOnInvalidId
  12594. /*
  12595. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12598. */
  12599. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  12600. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12601. // MeterValuesAlignedData
  12602. /*
  12603. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12606. */
  12607. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12608. // MeterValuesAlignedDataMaxLength
  12609. /*
  12610. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  12613. */
  12614. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12615. // MeterValuesSampledData
  12616. /*
  12617. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12620. */
  12621. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12622. // MeterValuesSampledDataMaxLength
  12623. /*
  12624. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  12627. */
  12628. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12629. // MeterValueSampleInterval
  12630. /*
  12631. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  12634. */
  12635. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12636. // MinimumStatusDuration
  12637. /*
  12638. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  12641. */
  12642. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12643. // NumberOfConnectors
  12644. /*
  12645. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12647. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12648. {
  12649. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12650. }
  12651. else
  12652. {
  12653. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12654. }
  12655. */
  12656. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12657. // ResetRetries
  12658. /*
  12659. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12660. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12662. */
  12663. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12664. // ConnectorPhaseRotation
  12665. /*
  12666. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12669. */
  12670. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12671. // ConnectorPhaseRotationMaxLength
  12672. /*
  12673. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12676. */
  12677. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12678. // StopTransactionOnEVSideDisconnect
  12679. /*
  12680. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12683. */
  12684. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12685. // StopTransactionOnInvalidId
  12686. /*
  12687. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  12688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12690. */
  12691. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12692. // StopTxnAlignedData
  12693. /*
  12694. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  12695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  12697. */
  12698. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12699. // StopTxnAlignedDataMaxLength
  12700. /*
  12701. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12704. */
  12705. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12706. // StopTxnSampledData
  12707. /*
  12708. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12710. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  12711. */
  12712. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12713. // StopTxnSampledDataMaxLength
  12714. /*
  12715. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  12718. */
  12719. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12720. // SupportedFeatureProfiles
  12721. /*
  12722. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12725. */
  12726. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12727. // SupportedFeatureProfilesMaxLength
  12728. /*
  12729. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12732. */
  12733. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12734. // TransactionMessageAttempts
  12735. /*
  12736. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12739. */
  12740. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12741. // TransactionMessageRetryInterval
  12742. /*
  12743. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12746. */
  12747. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12748. // UnlockConnectorOnEVSideDisconnect
  12749. /*
  12750. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12753. */
  12754. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12755. // WebSocketPingInterval
  12756. /*
  12757. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12760. */
  12761. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12762. // QueueOffLineStartTransactionMessage
  12763. /*
  12764. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  12765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12767. */
  12768. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12769. // AuthorizationKey
  12770. /*
  12771. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  12774. */
  12775. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12776. // SecurityProfile
  12777. /*
  12778. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  12781. */
  12782. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12783. // DefaultPrice
  12784. /*
  12785. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12788. */
  12789. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12790. // CustomDisplayCostAndPrice
  12791. /*
  12792. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12795. */
  12796. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12797. // CustomIdleFeeAfterStop
  12798. /*
  12799. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12802. */
  12803. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12804. // TimeOffset
  12805. /*
  12806. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  12807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  12808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  12809. */
  12810. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  12811. // NextTimeOffsetTransitionDateTime
  12812. /*
  12813. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  12814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  12815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  12816. */
  12817. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  12818. // TimeOffsetNextTransition
  12819. /*
  12820. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  12821. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  12822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  12823. */
  12824. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  12825. // ConfigurationVersion
  12826. /*
  12827. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  12828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  12830. */
  12831. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12832. //* Local Auth List Management Profile*/
  12833. //LocalAuthListEnabled
  12834. /*
  12835. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12836. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12838. */
  12839. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12840. //LocalAuthListMaxLength
  12841. /*
  12842. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12845. */
  12846. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12847. //SendLocalListMaxLength
  12848. /*
  12849. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12852. */
  12853. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12854. //ReserveConnectorZeroSupported
  12855. /*
  12856. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12859. */
  12860. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12861. //* Smart Charging Profile */
  12862. //ChargeProfileMaxStackLevel
  12863. /*
  12864. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12867. */
  12868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12869. // ChargingScheduleAllowedChargingRateUnit
  12870. /*
  12871. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  12874. */
  12875. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12876. // ChargingScheduleMaxPeriods
  12877. /*
  12878. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12881. */
  12882. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12883. // ConnectorSwitch3to1PhaseSupported
  12884. /*
  12885. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  12888. */
  12889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12890. // MaxChargingProfilesInstalled
  12891. /*
  12892. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12895. */
  12896. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12897. fclose(outfile);
  12898. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12899. }
  12900. void getKeyValue(char *keyReq)
  12901. {
  12902. int isEmpty = FALSE;
  12903. int isKnowKey = FALSE;
  12904. DEBUG_INFO("keyReq = %s\n", keyReq);
  12905. if((keyReq == NULL) || (strlen(keyReq) == 0))
  12906. isEmpty = TRUE;
  12907. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  12908. {
  12909. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  12910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  12911. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12912. {
  12913. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  12914. }
  12915. else
  12916. {
  12917. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  12918. }
  12919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  12920. isKnowKey = TRUE;
  12921. }
  12922. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  12923. {
  12924. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  12925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  12926. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12927. {
  12928. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  12929. }
  12930. else
  12931. {
  12932. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  12933. }
  12934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  12935. isKnowKey = TRUE;
  12936. }
  12937. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  12938. {
  12939. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  12940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  12941. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12942. {
  12943. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  12944. }
  12945. else
  12946. {
  12947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  12948. }
  12949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  12950. isKnowKey = TRUE;
  12951. }
  12952. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  12953. {
  12954. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  12955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  12956. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12957. {
  12958. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  12959. }
  12960. else
  12961. {
  12962. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  12963. }
  12964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  12965. isKnowKey = TRUE;
  12966. }
  12967. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  12968. {
  12969. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  12970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  12971. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12972. {
  12973. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  12974. }
  12975. else
  12976. {
  12977. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  12978. }
  12979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  12980. isKnowKey = TRUE;
  12981. }
  12982. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  12983. {
  12984. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  12985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  12986. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12987. {
  12988. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  12989. }
  12990. else
  12991. {
  12992. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  12993. }
  12994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  12995. isKnowKey = TRUE;
  12996. }
  12997. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  12998. {
  12999. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  13000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  13001. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13002. {
  13003. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  13004. }
  13005. else
  13006. {
  13007. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  13008. }
  13009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  13010. isKnowKey = TRUE;
  13011. }
  13012. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  13013. {
  13014. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  13015. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  13016. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13017. {
  13018. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  13019. }
  13020. else
  13021. {
  13022. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  13023. }
  13024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  13025. isKnowKey = TRUE;
  13026. }
  13027. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  13028. {
  13029. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  13030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  13031. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13032. {
  13033. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  13034. }
  13035. else
  13036. {
  13037. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  13038. }
  13039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  13040. isKnowKey = TRUE;
  13041. }
  13042. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  13043. {
  13044. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  13045. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  13046. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13047. {
  13048. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  13049. }
  13050. else
  13051. {
  13052. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  13053. }
  13054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  13055. isKnowKey = TRUE;
  13056. }
  13057. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  13058. {
  13059. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  13060. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  13061. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13062. {
  13063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  13064. }
  13065. else
  13066. {
  13067. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  13068. }
  13069. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  13070. isKnowKey = TRUE;
  13071. }
  13072. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  13073. {
  13074. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  13075. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  13076. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13077. {
  13078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13079. }
  13080. else
  13081. {
  13082. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13083. }
  13084. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  13085. isKnowKey = TRUE;
  13086. }
  13087. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  13088. {
  13089. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  13090. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  13091. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13092. {
  13093. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13094. }
  13095. else
  13096. {
  13097. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13098. }
  13099. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  13100. isKnowKey = TRUE;
  13101. }
  13102. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  13103. {
  13104. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  13105. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  13106. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13107. {
  13108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13109. }
  13110. else
  13111. {
  13112. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13113. }
  13114. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  13115. isKnowKey = TRUE;
  13116. }
  13117. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  13118. {
  13119. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  13120. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  13121. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13122. {
  13123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  13124. }
  13125. else
  13126. {
  13127. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  13128. }
  13129. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  13130. isKnowKey = TRUE;
  13131. }
  13132. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  13133. {
  13134. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  13135. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  13136. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13137. {
  13138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13139. }
  13140. else
  13141. {
  13142. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13143. }
  13144. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  13145. isKnowKey = TRUE;
  13146. }
  13147. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  13148. {
  13149. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  13150. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  13151. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13152. {
  13153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  13154. }
  13155. else
  13156. {
  13157. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  13158. }
  13159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  13160. isKnowKey = TRUE;
  13161. }
  13162. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  13163. {
  13164. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  13165. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  13166. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13167. {
  13168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  13169. }
  13170. else
  13171. {
  13172. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  13173. }
  13174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  13175. isKnowKey = TRUE;
  13176. }
  13177. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  13178. {
  13179. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  13180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  13181. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13182. {
  13183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  13184. }
  13185. else
  13186. {
  13187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  13188. }
  13189. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  13190. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  13191. isKnowKey = TRUE;
  13192. }
  13193. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  13194. {
  13195. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  13196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  13197. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13198. {
  13199. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  13200. }
  13201. else
  13202. {
  13203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  13204. }
  13205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  13206. isKnowKey = TRUE;
  13207. }
  13208. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  13209. {
  13210. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  13211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  13212. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13213. {
  13214. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  13215. }
  13216. else
  13217. {
  13218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  13219. }
  13220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  13221. isKnowKey = TRUE;
  13222. }
  13223. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  13224. {
  13225. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  13226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  13227. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13228. {
  13229. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13230. }
  13231. else
  13232. {
  13233. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13234. }
  13235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  13236. isKnowKey = TRUE;
  13237. }
  13238. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  13239. {
  13240. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  13241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  13242. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13243. {
  13244. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13245. }
  13246. else
  13247. {
  13248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13249. }
  13250. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  13251. isKnowKey = TRUE;
  13252. }
  13253. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  13254. {
  13255. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  13256. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  13257. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13258. {
  13259. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13260. }
  13261. else
  13262. {
  13263. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13264. }
  13265. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  13266. isKnowKey = TRUE;
  13267. }
  13268. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  13269. {
  13270. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  13271. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  13272. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13273. {
  13274. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13275. }
  13276. else
  13277. {
  13278. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13279. }
  13280. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  13281. isKnowKey = TRUE;
  13282. }
  13283. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  13284. {
  13285. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  13286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  13287. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13288. {
  13289. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13290. }
  13291. else
  13292. {
  13293. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13294. }
  13295. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  13296. isKnowKey = TRUE;
  13297. }
  13298. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  13299. {
  13300. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  13301. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  13302. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13303. {
  13304. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  13305. }
  13306. else
  13307. {
  13308. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  13309. }
  13310. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  13311. isKnowKey = TRUE;
  13312. }
  13313. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  13314. {
  13315. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  13316. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  13317. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13318. {
  13319. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13320. }
  13321. else
  13322. {
  13323. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13324. }
  13325. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  13326. isKnowKey = TRUE;
  13327. }
  13328. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  13329. {
  13330. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  13331. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  13332. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13333. {
  13334. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  13335. }
  13336. else
  13337. {
  13338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  13339. }
  13340. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  13341. isKnowKey = TRUE;
  13342. }
  13343. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  13344. {
  13345. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  13346. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  13347. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13348. {
  13349. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13350. }
  13351. else
  13352. {
  13353. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13354. }
  13355. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  13356. isKnowKey = TRUE;
  13357. }
  13358. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  13359. {
  13360. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  13361. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  13362. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13363. {
  13364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  13365. }
  13366. else
  13367. {
  13368. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  13369. }
  13370. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  13371. isKnowKey = TRUE;
  13372. }
  13373. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  13374. {
  13375. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  13376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  13377. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13378. {
  13379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  13380. }
  13381. else
  13382. {
  13383. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  13384. }
  13385. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  13386. isKnowKey = TRUE;
  13387. }
  13388. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  13389. {
  13390. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  13391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  13392. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13393. {
  13394. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13395. }
  13396. else
  13397. {
  13398. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13399. }
  13400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  13401. isKnowKey = TRUE;
  13402. }
  13403. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  13404. {
  13405. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  13406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  13407. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13408. {
  13409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  13410. }
  13411. else
  13412. {
  13413. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  13414. }
  13415. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  13416. isKnowKey = TRUE;
  13417. }
  13418. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  13419. {
  13420. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  13421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  13422. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  13423. {
  13424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  13425. }
  13426. else
  13427. {
  13428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  13429. }
  13430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  13431. isKnowKey = TRUE;
  13432. }
  13433. /*
  13434. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  13435. {
  13436. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  13437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  13438. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  13439. {
  13440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  13441. }
  13442. else
  13443. {
  13444. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  13445. }
  13446. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  13447. isKnowKey = TRUE;
  13448. }*/
  13449. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  13450. {
  13451. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  13452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  13453. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13454. {
  13455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  13456. }
  13457. else
  13458. {
  13459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  13460. }
  13461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  13462. isKnowKey = TRUE;
  13463. }
  13464. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  13465. {
  13466. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  13467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  13468. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  13469. {
  13470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  13471. }
  13472. else
  13473. {
  13474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  13475. }
  13476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  13477. isKnowKey = TRUE;
  13478. }
  13479. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  13480. {
  13481. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  13482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  13483. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13484. {
  13485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  13486. }
  13487. else
  13488. {
  13489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  13490. }
  13491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  13492. isKnowKey = TRUE;
  13493. }
  13494. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  13495. {
  13496. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  13497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  13498. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13499. {
  13500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  13501. }
  13502. else
  13503. {
  13504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  13505. }
  13506. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  13507. isKnowKey = TRUE;
  13508. }
  13509. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  13510. {
  13511. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  13512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  13513. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  13514. {
  13515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  13516. }
  13517. else
  13518. {
  13519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  13520. }
  13521. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  13522. isKnowKey = TRUE;
  13523. }
  13524. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  13525. {
  13526. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  13527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  13528. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  13529. {
  13530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  13531. }
  13532. else
  13533. {
  13534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  13535. }
  13536. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  13537. isKnowKey = TRUE;
  13538. }
  13539. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  13540. {
  13541. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  13542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  13543. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  13544. {
  13545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  13546. }
  13547. else
  13548. {
  13549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  13550. }
  13551. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  13552. isKnowKey = TRUE;
  13553. }
  13554. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  13555. {
  13556. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  13557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  13558. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  13559. {
  13560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  13561. }
  13562. else
  13563. {
  13564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  13565. }
  13566. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  13567. isKnowKey = TRUE;
  13568. }
  13569. #if 1
  13570. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  13571. {
  13572. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  13573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  13574. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13575. {
  13576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  13577. }
  13578. else
  13579. {
  13580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  13581. }
  13582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  13583. isKnowKey = TRUE;
  13584. }
  13585. #endif
  13586. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  13587. {
  13588. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  13589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  13590. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13591. {
  13592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13593. }
  13594. else
  13595. {
  13596. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13597. }
  13598. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  13599. isKnowKey = TRUE;
  13600. }
  13601. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  13602. {
  13603. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  13604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  13605. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13606. {
  13607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13608. }
  13609. else
  13610. {
  13611. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13612. }
  13613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  13614. isKnowKey = TRUE;
  13615. }
  13616. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  13617. {
  13618. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  13619. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  13620. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13621. {
  13622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  13623. }
  13624. else
  13625. {
  13626. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  13627. }
  13628. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13629. isKnowKey = TRUE;
  13630. }
  13631. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  13632. {
  13633. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  13634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  13635. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13636. {
  13637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  13638. }
  13639. else
  13640. {
  13641. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  13642. }
  13643. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13644. isKnowKey = TRUE;
  13645. }
  13646. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  13647. {
  13648. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  13649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  13650. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13651. {
  13652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  13653. }
  13654. else
  13655. {
  13656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  13657. }
  13658. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13659. isKnowKey = TRUE;
  13660. }
  13661. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  13662. {
  13663. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  13664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  13665. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13666. {
  13667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  13668. }
  13669. else
  13670. {
  13671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  13672. }
  13673. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13674. isKnowKey = TRUE;
  13675. }
  13676. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  13677. {
  13678. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  13679. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  13680. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13681. {
  13682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  13683. }
  13684. else
  13685. {
  13686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  13687. }
  13688. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13689. isKnowKey = TRUE;
  13690. }
  13691. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  13692. {
  13693. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  13694. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  13695. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13696. {
  13697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  13698. }
  13699. else
  13700. {
  13701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  13702. }
  13703. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13704. isKnowKey = TRUE;
  13705. }
  13706. //=========================================================
  13707. if(!isEmpty && !isKnowKey)
  13708. {
  13709. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  13710. strcpy(unknownkey[UnknownKeynum], keyReq);
  13711. UnknownKeynum = UnknownKeynum + 1;
  13712. }
  13713. }
  13714. void processUnkownKey(void)
  13715. {
  13716. DEBUG_INFO("processUnkownKey...\n");
  13717. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  13718. for(int index=0; index < UnknownKeynum; index++)
  13719. {
  13720. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  13721. {
  13722. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  13723. }
  13724. }
  13725. }
  13726. int setKeyValue(char *key, char *value)
  13727. {
  13728. int isSuccess = NotSupported;
  13729. int check_ascii=0;
  13730. char str[256]={0};
  13731. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  13732. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  13733. {
  13734. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13735. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13736. {
  13737. strcpy(str, (const char*)value);
  13738. for(int i = 0; str[i]; i++){
  13739. str[i] = tolower(str[i]);
  13740. }
  13741. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13742. isSuccess = ConfigurationStatus_Accepted;
  13743. }
  13744. else
  13745. {
  13746. isSuccess = ConfigurationStatus_Rejected;
  13747. }
  13748. }
  13749. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  13750. {
  13751. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13752. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13753. {
  13754. strcpy(str, (const char*)value);
  13755. for(int i = 0; str[i]; i++){
  13756. str[i] = tolower(str[i]);
  13757. }
  13758. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13759. isSuccess = ConfigurationStatus_Accepted;
  13760. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  13761. }
  13762. else
  13763. {
  13764. isSuccess = ConfigurationStatus_Rejected;
  13765. }
  13766. }
  13767. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  13768. {
  13769. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13770. {
  13771. strcpy(str, (const char*)value);
  13772. for(int i = 0; str[i]; i++)
  13773. {
  13774. str[i] = tolower(str[i]);
  13775. }
  13776. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  13777. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13778. isSuccess = ConfigurationStatus_Accepted;
  13779. }
  13780. else
  13781. {
  13782. isSuccess = ConfigurationStatus_Rejected;
  13783. }
  13784. }
  13785. if(strcmp(key, "BlinkRepeat") == 0)
  13786. {
  13787. //Charger.BlinkRepeat = Integer.parseInt(value);
  13788. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13789. {
  13790. check_ascii = value[0];
  13791. if( (check_ascii < 48) || (check_ascii > 57) )
  13792. {
  13793. isSuccess = ConfigurationStatus_Rejected;
  13794. }
  13795. else
  13796. {
  13797. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  13798. isSuccess = ConfigurationStatus_Accepted;
  13799. }
  13800. }
  13801. else
  13802. {
  13803. isSuccess = ConfigurationStatus_Rejected;
  13804. }
  13805. }
  13806. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  13807. {
  13808. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13809. {
  13810. check_ascii = value[0];
  13811. if( (check_ascii < 48) || (check_ascii > 57) )
  13812. {
  13813. isSuccess = ConfigurationStatus_Rejected;
  13814. }
  13815. else
  13816. {
  13817. if((atoi(value) == 0) || (atoi(value) >= 10))
  13818. {
  13819. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  13820. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  13821. isSuccess = ConfigurationStatus_Accepted;
  13822. }
  13823. else
  13824. isSuccess = ConfigurationStatus_Rejected;
  13825. }
  13826. }
  13827. else
  13828. {
  13829. isSuccess = ConfigurationStatus_Rejected;
  13830. }
  13831. }
  13832. if(strcmp(key, "ConnectionTimeOut") == 0 )
  13833. {
  13834. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13835. {
  13836. check_ascii = value[0];
  13837. if( (check_ascii < 48) || (check_ascii > 57) )
  13838. {
  13839. isSuccess = ConfigurationStatus_Rejected;
  13840. }
  13841. else
  13842. {
  13843. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  13844. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  13845. isSuccess = ConfigurationStatus_Accepted;
  13846. }
  13847. }
  13848. else
  13849. {
  13850. isSuccess = ConfigurationStatus_Rejected;
  13851. }
  13852. }
  13853. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  13854. {
  13855. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13856. {
  13857. check_ascii = value[0];
  13858. if( (check_ascii < 48) || (check_ascii > 57) )
  13859. {
  13860. isSuccess = ConfigurationStatus_Rejected;
  13861. }
  13862. else
  13863. {
  13864. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13865. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  13866. isSuccess = ConfigurationStatus_Accepted;
  13867. }
  13868. }
  13869. else
  13870. {
  13871. isSuccess = ConfigurationStatus_Rejected;
  13872. }
  13873. }
  13874. if(strcmp(key, "HeartbeatInterval") == 0)
  13875. {
  13876. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13877. {
  13878. check_ascii = value[0];
  13879. if( (check_ascii < 48) || (check_ascii > 57) )
  13880. {
  13881. isSuccess = ConfigurationStatus_Rejected;
  13882. }
  13883. else
  13884. {
  13885. if((atoi(value) == 0) || (atoi(value) >= 10))
  13886. {
  13887. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13888. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  13889. HeartBeatWaitTime = atoi(value);
  13890. isSuccess = ConfigurationStatus_Accepted;
  13891. }
  13892. else
  13893. {
  13894. isSuccess = ConfigurationStatus_Rejected;
  13895. }
  13896. }
  13897. }
  13898. else
  13899. {
  13900. isSuccess = ConfigurationStatus_Rejected;
  13901. }
  13902. }
  13903. if(strcmp(key, "LightIntensity") == 0)
  13904. {
  13905. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13906. {
  13907. check_ascii = value[0];
  13908. if( (check_ascii < 48) || (check_ascii > 57) )
  13909. {
  13910. isSuccess = ConfigurationStatus_Rejected;
  13911. }
  13912. else
  13913. {
  13914. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  13915. isSuccess = ConfigurationStatus_Accepted;
  13916. }
  13917. }
  13918. else
  13919. {
  13920. isSuccess = ConfigurationStatus_Rejected;
  13921. }
  13922. }
  13923. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  13924. {
  13925. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13926. {
  13927. strcpy(str, (const char*)value);
  13928. for(int i = 0; str[i]; i++)
  13929. {
  13930. str[i] = tolower(str[i]);
  13931. }
  13932. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13933. isSuccess = ConfigurationStatus_Accepted;
  13934. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13935. }
  13936. else
  13937. {
  13938. isSuccess = ConfigurationStatus_Rejected;
  13939. }
  13940. }
  13941. if(strcmp(key, "LocalPreAuthorize") == 0)
  13942. {
  13943. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13944. {
  13945. strcpy(str, (const char*)value);
  13946. for(int i = 0; str[i]; i++)
  13947. {
  13948. str[i] = tolower(str[i]);
  13949. }
  13950. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13951. isSuccess = ConfigurationStatus_Accepted;
  13952. }
  13953. else
  13954. {
  13955. isSuccess = ConfigurationStatus_Rejected;
  13956. }
  13957. }
  13958. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  13959. {
  13960. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13961. {
  13962. check_ascii = value[0];
  13963. if( (check_ascii < 48) || (check_ascii > 57) )
  13964. {
  13965. isSuccess = ConfigurationStatus_Rejected;
  13966. }
  13967. else
  13968. {
  13969. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  13970. isSuccess = ConfigurationStatus_Accepted;
  13971. }
  13972. }
  13973. else
  13974. {
  13975. isSuccess = ConfigurationStatus_Rejected;
  13976. }
  13977. }
  13978. if(strcmp(key, "MeterValuesAlignedData") == 0)
  13979. {
  13980. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13981. {
  13982. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  13983. isSuccess = ConfigurationStatus_Accepted;
  13984. }
  13985. else
  13986. {
  13987. isSuccess = ConfigurationStatus_Rejected;
  13988. }
  13989. }
  13990. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  13991. {
  13992. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13993. {
  13994. check_ascii = value[0];
  13995. if( (check_ascii < 48) || (check_ascii > 57) )
  13996. {
  13997. isSuccess = ConfigurationStatus_Rejected;
  13998. }
  13999. else
  14000. {
  14001. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14002. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  14003. isSuccess = ConfigurationStatus_Accepted;
  14004. }
  14005. }
  14006. else
  14007. {
  14008. isSuccess = ConfigurationStatus_Rejected;
  14009. }
  14010. }
  14011. if(strcmp(key, "MeterValuesSampledData") == 0 )
  14012. {
  14013. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14014. {
  14015. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  14016. isSuccess = ConfigurationStatus_Accepted;
  14017. }
  14018. else
  14019. {
  14020. isSuccess = ConfigurationStatus_Rejected;
  14021. }
  14022. }
  14023. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  14024. {
  14025. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14026. {
  14027. check_ascii = value[0];
  14028. if( (check_ascii < 48) || (check_ascii > 57) )
  14029. {
  14030. isSuccess = ConfigurationStatus_Rejected;
  14031. }
  14032. else
  14033. {
  14034. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14035. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  14036. isSuccess = ConfigurationStatus_Accepted;
  14037. }
  14038. }
  14039. else
  14040. {
  14041. isSuccess = ConfigurationStatus_Rejected;
  14042. }
  14043. }
  14044. if(strcmp(key, "MeterValueSampleInterval") == 0)
  14045. {
  14046. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14047. {
  14048. check_ascii = value[0];
  14049. if( (check_ascii < 48) || (check_ascii > 57) )
  14050. {
  14051. isSuccess = ConfigurationStatus_Rejected;
  14052. }
  14053. else
  14054. {
  14055. if((atoi(value) == 0) || (atoi(value) >= 10))
  14056. {
  14057. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14058. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  14059. isSuccess = ConfigurationStatus_Accepted;
  14060. }
  14061. else
  14062. {
  14063. isSuccess = ConfigurationStatus_Rejected;
  14064. }
  14065. }
  14066. }
  14067. else
  14068. {
  14069. isSuccess = ConfigurationStatus_Rejected;
  14070. }
  14071. }
  14072. if(strcmp(key, "MinimumStatusDuration") == 0)
  14073. {
  14074. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14075. {
  14076. check_ascii = value[0];
  14077. if( (check_ascii < 48) || (check_ascii > 57) )
  14078. {
  14079. isSuccess = ConfigurationStatus_Rejected;
  14080. }
  14081. else
  14082. {
  14083. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  14084. {
  14085. isSuccess = ConfigurationStatus_Rejected;
  14086. }
  14087. else
  14088. {
  14089. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  14090. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  14091. server_cycle_Status = atoi(value); //StatusNotification Cycle
  14092. isSuccess = ConfigurationStatus_Accepted;
  14093. }
  14094. }
  14095. }
  14096. else
  14097. {
  14098. isSuccess = ConfigurationStatus_Rejected;
  14099. }
  14100. }
  14101. if(strcmp(key, "NumberOfConnectors") == 0)
  14102. {
  14103. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14104. {
  14105. check_ascii = value[0];
  14106. if( (check_ascii < 48) || (check_ascii > 57) )
  14107. {
  14108. isSuccess = ConfigurationStatus_Rejected;
  14109. }
  14110. else
  14111. {
  14112. //Charger.ResetRetries = Integer.parseInt(value);
  14113. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  14114. isSuccess = ConfigurationStatus_Accepted;
  14115. }
  14116. }
  14117. else
  14118. {
  14119. isSuccess = ConfigurationStatus_Rejected;
  14120. }
  14121. }
  14122. if(strcmp(key, "ResetRetries") == 0)
  14123. {
  14124. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14125. {
  14126. check_ascii = value[0];
  14127. if( (check_ascii < 48) || (check_ascii > 57) )
  14128. {
  14129. isSuccess = ConfigurationStatus_Rejected;
  14130. }
  14131. else
  14132. {
  14133. //Charger.ResetRetries = Integer.parseInt(value);
  14134. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  14135. isSuccess = ConfigurationStatus_Accepted;
  14136. }
  14137. }
  14138. else
  14139. {
  14140. isSuccess = ConfigurationStatus_Rejected;
  14141. }
  14142. }
  14143. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  14144. {
  14145. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14146. {
  14147. strcpy(str, (const char*)value);
  14148. for(int i = 0; str[i]; i++)
  14149. {
  14150. str[i] = tolower(str[i]);
  14151. }
  14152. if(strcmp(str, "notapplicable")== 0)
  14153. {
  14154. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  14155. isSuccess = ConfigurationStatus_Accepted;
  14156. }
  14157. else if(strcmp(str, "unknown")== 0)
  14158. {
  14159. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  14160. isSuccess = ConfigurationStatus_Accepted;
  14161. }
  14162. else if(strcmp(str, "rst")== 0)
  14163. {
  14164. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  14165. isSuccess = ConfigurationStatus_Accepted;
  14166. }
  14167. else if(strcmp(str, "rts")== 0)
  14168. {
  14169. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  14170. isSuccess = ConfigurationStatus_Accepted;
  14171. }
  14172. else if(strcmp(str, "srt")== 0)
  14173. {
  14174. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  14175. isSuccess = ConfigurationStatus_Accepted;
  14176. }
  14177. else if(strcmp(str, "str")== 0)
  14178. {
  14179. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  14180. isSuccess = ConfigurationStatus_Accepted;
  14181. }
  14182. else if(strcmp(str, "trs")== 0)
  14183. {
  14184. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  14185. isSuccess = ConfigurationStatus_Accepted;
  14186. }
  14187. else if(strcmp(str, "tsr")== 0)
  14188. {
  14189. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  14190. isSuccess = ConfigurationStatus_Accepted;
  14191. }
  14192. else
  14193. {
  14194. isSuccess = ConfigurationStatus_Rejected;
  14195. }
  14196. }
  14197. else
  14198. {
  14199. isSuccess = ConfigurationStatus_Rejected;
  14200. }
  14201. }
  14202. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  14203. {
  14204. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14205. {
  14206. check_ascii = value[0];
  14207. if( (check_ascii < 48) || (check_ascii > 57) )
  14208. {
  14209. isSuccess = ConfigurationStatus_Rejected;
  14210. }
  14211. else
  14212. {
  14213. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  14214. isSuccess = ConfigurationStatus_Accepted;
  14215. }
  14216. }
  14217. else
  14218. {
  14219. isSuccess = ConfigurationStatus_Rejected;
  14220. }
  14221. }
  14222. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  14223. {
  14224. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14225. {
  14226. strcpy(str, (const char*)value);
  14227. for(int i = 0; str[i]; i++)
  14228. {
  14229. str[i] = tolower(str[i]);
  14230. }
  14231. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14232. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14233. isSuccess = ConfigurationStatus_Accepted;
  14234. }
  14235. else
  14236. {
  14237. isSuccess = ConfigurationStatus_Rejected;
  14238. }
  14239. }
  14240. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  14241. {
  14242. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14243. {
  14244. strcpy(str, (const char*)value);
  14245. for(int i = 0; str[i]; i++)
  14246. {
  14247. str[i] = tolower(str[i]);
  14248. }
  14249. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  14250. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14251. isSuccess = ConfigurationStatus_Accepted;
  14252. }
  14253. else
  14254. {
  14255. isSuccess = ConfigurationStatus_Rejected;
  14256. }
  14257. }
  14258. if(strcmp(key, "StopTxnAlignedData") == 0)
  14259. {
  14260. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14261. {
  14262. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  14263. isSuccess = ConfigurationStatus_Accepted;
  14264. }
  14265. else
  14266. {
  14267. isSuccess = ConfigurationStatus_Rejected;
  14268. }
  14269. }
  14270. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  14271. {
  14272. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14273. {
  14274. check_ascii = value[0];
  14275. if( (check_ascii < 48) || (check_ascii > 57) )
  14276. {
  14277. isSuccess = ConfigurationStatus_Rejected;
  14278. }
  14279. else
  14280. {
  14281. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  14282. isSuccess = ConfigurationStatus_Accepted;
  14283. }
  14284. }
  14285. else
  14286. {
  14287. isSuccess = ConfigurationStatus_Rejected;
  14288. }
  14289. }
  14290. if(strcmp(key, "StopTxnSampledData") == 0)
  14291. {
  14292. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14293. {
  14294. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  14295. isSuccess = ConfigurationStatus_Accepted;
  14296. }
  14297. else
  14298. {
  14299. isSuccess = ConfigurationStatus_Rejected;
  14300. }
  14301. }
  14302. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  14303. {
  14304. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14305. {
  14306. check_ascii = value[0];
  14307. if( (check_ascii < 48) || (check_ascii > 57) )
  14308. {
  14309. isSuccess = ConfigurationStatus_Rejected;
  14310. }
  14311. else
  14312. {
  14313. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  14314. isSuccess = ConfigurationStatus_Accepted;
  14315. }
  14316. }
  14317. else
  14318. {
  14319. isSuccess = ConfigurationStatus_Rejected;
  14320. }
  14321. }
  14322. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  14323. {
  14324. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14325. {
  14326. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  14327. isSuccess = ConfigurationStatus_Accepted;
  14328. }
  14329. else
  14330. {
  14331. isSuccess = ConfigurationStatus_Rejected;
  14332. }
  14333. }
  14334. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  14335. {
  14336. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14337. {
  14338. check_ascii = value[0];
  14339. if( (check_ascii < 48) || (check_ascii > 57) )
  14340. {
  14341. isSuccess = ConfigurationStatus_Rejected;
  14342. }
  14343. else
  14344. {
  14345. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  14346. isSuccess = ConfigurationStatus_Accepted;
  14347. }
  14348. }
  14349. else
  14350. {
  14351. isSuccess = ConfigurationStatus_Rejected;
  14352. }
  14353. }
  14354. if(strcmp(key, "TransactionMessageAttempts") == 0)
  14355. {
  14356. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14357. {
  14358. check_ascii = value[0];
  14359. if( (check_ascii < 48) || (check_ascii > 57) )
  14360. {
  14361. isSuccess = ConfigurationStatus_Rejected;
  14362. }
  14363. else
  14364. {
  14365. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  14366. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  14367. TransactionMessageAttemptsValue = atoi(value);
  14368. isSuccess = ConfigurationStatus_Accepted;
  14369. }
  14370. }
  14371. else
  14372. {
  14373. isSuccess = ConfigurationStatus_Rejected;
  14374. }
  14375. }
  14376. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  14377. {
  14378. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14379. {
  14380. check_ascii = value[0];
  14381. if( (check_ascii < 48) || (check_ascii > 57) )
  14382. {
  14383. isSuccess = ConfigurationStatus_Rejected;
  14384. }
  14385. else
  14386. {
  14387. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  14388. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  14389. TransactionMessageRetryIntervalValue = atoi(value);
  14390. isSuccess = ConfigurationStatus_Accepted;
  14391. }
  14392. }
  14393. else
  14394. {
  14395. isSuccess = ConfigurationStatus_Rejected;
  14396. }
  14397. }
  14398. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  14399. {
  14400. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14401. {
  14402. strcpy(str, (const char*)value);
  14403. for(int i = 0; str[i]; i++)
  14404. {
  14405. str[i] = tolower(str[i]);
  14406. }
  14407. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14408. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14409. isSuccess = ConfigurationStatus_Accepted;
  14410. }
  14411. else
  14412. {
  14413. isSuccess = ConfigurationStatus_Rejected;
  14414. }
  14415. }
  14416. if(strcmp(key, "WebSocketPingInterval") == 0)
  14417. {
  14418. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14419. {
  14420. check_ascii = value[0];
  14421. if( (check_ascii < 48) || (check_ascii > 57) )
  14422. {
  14423. isSuccess = ConfigurationStatus_Rejected;
  14424. }
  14425. else
  14426. {
  14427. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  14428. isSuccess = ConfigurationStatus_Accepted;
  14429. }
  14430. }
  14431. else
  14432. {
  14433. isSuccess = ConfigurationStatus_Rejected;
  14434. }
  14435. }
  14436. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  14437. {
  14438. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  14439. {
  14440. strcpy(str, (const char*)value);
  14441. for(int i = 0; str[i]; i++)
  14442. {
  14443. str[i] = tolower(str[i]);
  14444. }
  14445. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14446. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14447. isSuccess = ConfigurationStatus_Accepted;
  14448. }
  14449. else
  14450. {
  14451. isSuccess = ConfigurationStatus_Rejected;
  14452. }
  14453. }
  14454. if(strcmp(key, "AuthorizationKey") == 0)
  14455. {
  14456. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  14457. {
  14458. strcpy(str, (const char*)value);
  14459. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  14460. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14461. isSuccess = ConfigurationStatus_Accepted;
  14462. }
  14463. else
  14464. {
  14465. isSuccess = ConfigurationStatus_Rejected;
  14466. }
  14467. }
  14468. if(strcmp(key, "SecurityProfile") == 0)
  14469. {
  14470. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14471. {
  14472. check_ascii = value[0];
  14473. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  14474. {
  14475. isSuccess = ConfigurationStatus_Rejected;
  14476. }
  14477. else if(check_ascii == 0x33)
  14478. {
  14479. isSuccess = NotSupported;
  14480. }
  14481. else
  14482. {
  14483. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  14484. {
  14485. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  14486. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  14487. isSuccess = ConfigurationStatus_Accepted;
  14488. }
  14489. else
  14490. isSuccess = ConfigurationStatus_Rejected;
  14491. }
  14492. }
  14493. else
  14494. {
  14495. isSuccess = ConfigurationStatus_Rejected;
  14496. }
  14497. }
  14498. if(strcmp(key, "DefaultPrice") == 0)
  14499. {
  14500. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  14501. {
  14502. strcpy(str, (const char*)value);
  14503. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  14504. isSuccess = ConfigurationStatus_Accepted;
  14505. }
  14506. else
  14507. {
  14508. isSuccess = ConfigurationStatus_Rejected;
  14509. }
  14510. }
  14511. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  14512. {
  14513. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14514. {
  14515. strcpy(str, (const char*)value);
  14516. for(int i = 0; str[i]; i++)
  14517. {
  14518. str[i] = tolower(str[i]);
  14519. }
  14520. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14521. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14522. isSuccess = ConfigurationStatus_Accepted;
  14523. }
  14524. else
  14525. {
  14526. isSuccess = ConfigurationStatus_Rejected;
  14527. }
  14528. }
  14529. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  14530. {
  14531. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14532. {
  14533. strcpy(str, (const char*)value);
  14534. for(int i = 0; str[i]; i++)
  14535. {
  14536. str[i] = tolower(str[i]);
  14537. }
  14538. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14539. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14540. isSuccess = ConfigurationStatus_Accepted;
  14541. }
  14542. else
  14543. {
  14544. isSuccess = ConfigurationStatus_Rejected;
  14545. }
  14546. }
  14547. if(strcmp(key, "TimeOffset") == 0)
  14548. {
  14549. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  14550. {
  14551. strcpy(str, (const char*)value);
  14552. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  14553. isSuccess = ConfigurationStatus_Accepted;
  14554. }
  14555. else
  14556. {
  14557. isSuccess = ConfigurationStatus_Rejected;
  14558. }
  14559. }
  14560. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  14561. {
  14562. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  14563. {
  14564. strcpy(str, (const char*)value);
  14565. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  14566. isSuccess = ConfigurationStatus_Accepted;
  14567. }
  14568. else
  14569. {
  14570. isSuccess = ConfigurationStatus_Rejected;
  14571. }
  14572. }
  14573. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  14574. {
  14575. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  14576. {
  14577. strcpy(str, (const char*)value);
  14578. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  14579. isSuccess = ConfigurationStatus_Accepted;
  14580. }
  14581. else
  14582. {
  14583. isSuccess = ConfigurationStatus_Rejected;
  14584. }
  14585. }
  14586. #if 0
  14587. //For OCPP Test Case
  14588. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  14589. {
  14590. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14591. {
  14592. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  14593. isSuccess = ConfigurationStatus_Accepted;
  14594. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14595. }
  14596. else
  14597. {
  14598. isSuccess = ConfigurationStatus_Rejected;
  14599. }
  14600. }
  14601. #endif
  14602. #if 1
  14603. if(strcmp(key, "LocalAuthListEnabled") == 0)
  14604. {
  14605. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14606. {
  14607. strcpy(str, (const char*)value);
  14608. for(int i = 0; str[i]; i++)
  14609. {
  14610. str[i] = tolower(str[i]);
  14611. }
  14612. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14613. isSuccess = ConfigurationStatus_Accepted;
  14614. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14615. }
  14616. else
  14617. {
  14618. isSuccess = ConfigurationStatus_Rejected;
  14619. }
  14620. }
  14621. #endif
  14622. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  14623. {
  14624. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14625. {
  14626. check_ascii = value[0];
  14627. if( (check_ascii < 48) || (check_ascii > 57) )
  14628. {
  14629. isSuccess = ConfigurationStatus_Rejected;
  14630. }
  14631. else
  14632. {
  14633. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  14634. isSuccess = ConfigurationStatus_Accepted;
  14635. }
  14636. }
  14637. else
  14638. {
  14639. isSuccess = ConfigurationStatus_Rejected;
  14640. }
  14641. }
  14642. if(strcmp(key, "SendLocalListMaxLength") == 0)
  14643. {
  14644. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14645. {
  14646. check_ascii = value[0];
  14647. if( (check_ascii < 48) || (check_ascii > 57) )
  14648. {
  14649. isSuccess = ConfigurationStatus_Rejected;
  14650. }
  14651. else
  14652. {
  14653. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  14654. isSuccess = ConfigurationStatus_Accepted;
  14655. }
  14656. }
  14657. else
  14658. {
  14659. isSuccess = ConfigurationStatus_Rejected;
  14660. }
  14661. }
  14662. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  14663. {
  14664. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14665. {
  14666. strcpy(str, (const char*)value);
  14667. for(int i = 0; str[i]; i++)
  14668. {
  14669. str[i] = tolower(str[i]);
  14670. }
  14671. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14672. isSuccess = ConfigurationStatus_Accepted;
  14673. }
  14674. else
  14675. {
  14676. isSuccess = ConfigurationStatus_Rejected;
  14677. }
  14678. }
  14679. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  14680. {
  14681. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14682. {
  14683. check_ascii = value[0];
  14684. if( (check_ascii < 48) || (check_ascii > 57) )
  14685. {
  14686. isSuccess = ConfigurationStatus_Rejected;
  14687. }
  14688. else
  14689. {
  14690. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  14691. isSuccess = ConfigurationStatus_Accepted;
  14692. }
  14693. }
  14694. else
  14695. {
  14696. isSuccess = ConfigurationStatus_Rejected;
  14697. }
  14698. }
  14699. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14700. {
  14701. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14702. {
  14703. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  14704. isSuccess = ConfigurationStatus_Accepted;
  14705. }
  14706. else
  14707. {
  14708. isSuccess = ConfigurationStatus_Rejected;
  14709. }
  14710. }
  14711. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  14712. {
  14713. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14714. {
  14715. check_ascii = value[0];
  14716. if( (check_ascii < 48) || (check_ascii > 57) )
  14717. {
  14718. isSuccess = ConfigurationStatus_Rejected;
  14719. }
  14720. else
  14721. {
  14722. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  14723. isSuccess = ConfigurationStatus_Accepted;
  14724. }
  14725. }
  14726. else
  14727. {
  14728. isSuccess = ConfigurationStatus_Rejected;
  14729. }
  14730. }
  14731. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  14732. {
  14733. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14734. {
  14735. strcpy(str, (const char*)value);
  14736. for(int i = 0; str[i]; i++)
  14737. {
  14738. str[i] = tolower(str[i]);
  14739. }
  14740. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14741. isSuccess = ConfigurationStatus_Accepted;
  14742. }
  14743. else
  14744. {
  14745. isSuccess = ConfigurationStatus_Rejected;
  14746. }
  14747. }
  14748. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  14749. {
  14750. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14751. {
  14752. check_ascii = value[0];
  14753. if( (check_ascii < 48) || (check_ascii > 57) )
  14754. {
  14755. isSuccess = ConfigurationStatus_Rejected;
  14756. }
  14757. else
  14758. {
  14759. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  14760. isSuccess = ConfigurationStatus_Accepted;
  14761. }
  14762. }
  14763. else
  14764. {
  14765. isSuccess = ConfigurationStatus_Rejected;
  14766. }
  14767. }
  14768. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14769. return isSuccess;
  14770. }
  14771. int TransactionMessageAttemptsGet(void)
  14772. {
  14773. return TransactionMessageAttemptsValue;
  14774. }
  14775. int FirstHeartBeatResponse(void)
  14776. {
  14777. return FirstHeartBeat;
  14778. }
  14779. int TransactionMessageRetryIntervalGet(void)
  14780. {
  14781. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14782. }
  14783. int ReadHttpStatus(int sock)
  14784. {
  14785. //char c;
  14786. char buff[1024]="",*ptr=buff+1;
  14787. int bytes_received, status;
  14788. DEBUG_INFO("Begin Response ..\n");
  14789. while((bytes_received = recv(sock, ptr, 1, 0))){
  14790. if(bytes_received==-1){
  14791. perror("ReadHttpStatus");
  14792. exit(1);
  14793. }
  14794. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  14795. ptr++;
  14796. }
  14797. *ptr=0;
  14798. ptr=buff+1;
  14799. sscanf(ptr,"%*s %d ", &status);
  14800. DEBUG_INFO("%s\n",ptr);
  14801. DEBUG_INFO("status=%d\n",status);
  14802. DEBUG_INFO("End Response ..\n");
  14803. return (bytes_received>0)?status:0;
  14804. }
  14805. //the only filed that it parsed is 'Content-Length'
  14806. int ParseHeader(int sock)
  14807. {
  14808. //char c;
  14809. char buff[1024]="",*ptr=buff+4;
  14810. int bytes_received;
  14811. DEBUG_INFO("Begin HEADER ..\n");
  14812. while((bytes_received = recv(sock, ptr, 1, 0))){
  14813. if(bytes_received==-1){
  14814. perror("Parse Header");
  14815. exit(1);
  14816. }
  14817. if(
  14818. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  14819. (ptr[-1]=='\r') && (*ptr=='\n' )
  14820. ) break;
  14821. ptr++;
  14822. }
  14823. *ptr=0;
  14824. ptr=buff+4;
  14825. //printf("%s",ptr);
  14826. if(bytes_received){
  14827. ptr=strstr(ptr,"Content-Length:");
  14828. if(ptr){
  14829. sscanf(ptr,"%*s %d",&bytes_received);
  14830. }else
  14831. bytes_received=-1; //unknown size
  14832. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  14833. }
  14834. DEBUG_INFO("End HEADER ..\n");
  14835. return bytes_received ;
  14836. }
  14837. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  14838. {
  14839. int result = TRUE;
  14840. char rmFileCmd[100]={0};
  14841. char FilePath[100]={0};
  14842. char ftpbuf[200];
  14843. int systemresult;
  14844. //DEBUG_INFO("filename=%s\n",filename);
  14845. //DEBUG_INFO("url=%s\n",url);
  14846. sprintf(FilePath,"/mnt/%s",filename);
  14847. system("ping 8.8.8.8 &");
  14848. if((access(FilePath,F_OK))!=-1)
  14849. {
  14850. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14851. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14852. system(rmFileCmd);
  14853. }
  14854. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14855. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14856. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14857. systemresult = system(ftpbuf);
  14858. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14859. if(systemresult != 0)
  14860. {
  14861. DEBUG_INFO("http DownLoad error!\n");
  14862. result = FALSE;
  14863. }
  14864. system("pkill ping");
  14865. return result;
  14866. }
  14867. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  14868. {
  14869. int result = TRUE;
  14870. char rmFileCmd[100]={0};
  14871. char FilePath[100]={0};
  14872. char ftpbuf[200];
  14873. int systemresult;
  14874. //char temp[100];
  14875. sprintf(FilePath,"/mnt/%s",filename);
  14876. system("ping 8.8.8.8 &");
  14877. if((access(FilePath,F_OK))!=-1)
  14878. {
  14879. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14880. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14881. system(rmFileCmd);
  14882. }
  14883. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14884. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14885. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  14886. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14887. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14888. systemresult = system(ftpbuf);
  14889. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14890. if(systemresult != 0)
  14891. {
  14892. DEBUG_WARN("wget error!\n");
  14893. result = FALSE;
  14894. }
  14895. system("pkill ping");
  14896. return result;
  14897. }
  14898. int httpUploadFile(char *location, char *path, char *filename,char *url)
  14899. {
  14900. char rmFileCmd[100]={0};
  14901. char FilePath[100]={0};
  14902. char buf[512];
  14903. int systemresult = 0;
  14904. //DEBUG_INFO("filename=%s\n",filename);
  14905. //DEBUG_INFO("url=%s\n",url);
  14906. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  14907. if((access(FilePath,F_OK))!=-1)
  14908. {
  14909. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14910. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14911. system(rmFileCmd);
  14912. }
  14913. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  14914. if(fp == NULL)
  14915. {
  14916. DEBUG_INFO("log is NULL\n");
  14917. return FALSE;
  14918. }
  14919. else
  14920. {
  14921. fprintf(fp, "%s\n", url);
  14922. fprintf(fp, "%s\n", filename);
  14923. fclose(fp);
  14924. }
  14925. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  14926. if(phpFP == NULL)
  14927. {
  14928. DEBUG_INFO("PHP upload fail.\n");
  14929. return FALSE;
  14930. }
  14931. else
  14932. {
  14933. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  14934. {
  14935. if(strstr(buf, "result") != NULL)
  14936. {
  14937. sscanf(buf, "result: %d", &systemresult);
  14938. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  14939. }
  14940. }
  14941. pclose(phpFP);
  14942. }
  14943. if(systemresult != 1)
  14944. {
  14945. DEBUG_INFO("HTTP upload error!\n");
  14946. return FALSE;
  14947. }
  14948. return TRUE;
  14949. }
  14950. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  14951. {
  14952. struct hostent* server;
  14953. char *IPbuffer;
  14954. char ftpbuf[200];
  14955. int systemresult;
  14956. // To retrieve host information
  14957. server = gethostbyname(location);
  14958. // To convert an Internet network
  14959. // address into ASCII string
  14960. IPbuffer = inet_ntoa(*((struct in_addr*)
  14961. server->h_addr_list[0]));
  14962. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14963. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  14964. /* format : ftpput -u username -p passwd IP target source*/
  14965. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  14966. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14967. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14968. systemresult = system(ftpbuf);
  14969. DEBUG_INFO("systemresult=%d\n",systemresult);
  14970. if(systemresult != 0)
  14971. {
  14972. DEBUG_INFO("ftpput error!\n");
  14973. return FALSE;
  14974. }
  14975. return TRUE;
  14976. }
  14977. int GetOcppServerURL()
  14978. {
  14979. int result = FALSE;
  14980. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  14981. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  14982. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  14983. struct yuarel url;
  14984. char urlStr[512];
  14985. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  14986. {
  14987. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  14988. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14989. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14990. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  14991. if(yuarel_parse(&url, urlStr) != -1)
  14992. {
  14993. sprintf(OcppProtocol, "%s", url.scheme);
  14994. sprintf(OcppHost, "%s", url.host);
  14995. if(url.path == NULL)
  14996. OcppTempPath[0] = '\0';
  14997. else
  14998. {
  14999. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  15000. {
  15001. sprintf(OcppTempPath, "%s/", url.path);
  15002. }
  15003. else
  15004. {
  15005. sprintf(OcppTempPath, "%s", url.path);
  15006. }
  15007. }
  15008. if(url.port == 0)
  15009. {
  15010. if(strcmp(OcppProtocol, "wss") == 0)
  15011. OcppPort = 443;
  15012. else
  15013. OcppPort = 80;
  15014. }
  15015. else
  15016. OcppPort = url.port;
  15017. result = TRUE;
  15018. }
  15019. }
  15020. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  15021. {
  15022. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  15023. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15024. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15025. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  15026. if(yuarel_parse(&url, urlStr) != -1)
  15027. {
  15028. sprintf(OcppProtocol, "%s", url.scheme);
  15029. sprintf(OcppHost, "%s", url.host);
  15030. if(url.path == NULL)
  15031. OcppTempPath[0] = '\0';
  15032. else
  15033. sprintf(OcppTempPath, "%s", url.path);
  15034. if(url.port == 0)
  15035. {
  15036. if(strcmp(OcppProtocol, "wss") == 0)
  15037. OcppPort = 443;
  15038. else
  15039. OcppPort = 80;
  15040. }
  15041. else
  15042. OcppPort = url.port;
  15043. result = TRUE;
  15044. }
  15045. }
  15046. else
  15047. {
  15048. strcpy(OcppHost,"");
  15049. }
  15050. return result;
  15051. }
  15052. int GetOcppPath()
  15053. {
  15054. int result = FALSE;
  15055. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  15056. {
  15057. if(OcppTempPath == NULL)
  15058. {
  15059. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15060. }
  15061. else
  15062. {
  15063. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15064. }
  15065. result = TRUE;
  15066. goto End;
  15067. }
  15068. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  15069. {
  15070. if(OcppTempPath == NULL)
  15071. {
  15072. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  15073. }
  15074. else
  15075. {
  15076. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  15077. }
  15078. result = TRUE;
  15079. goto End;
  15080. }
  15081. else
  15082. {
  15083. strcpy(OcppPath,"");
  15084. }
  15085. End:
  15086. return result;
  15087. }
  15088. int GetOcppPort()
  15089. {
  15090. return OcppPort;
  15091. }
  15092. int GetOcppConnStatus(void)
  15093. {
  15094. return ShmOCPP16Data->OcppConnStatus;
  15095. }
  15096. void SetOcppConnStatus(uint8_t status)
  15097. {
  15098. ShmOCPP16Data->OcppConnStatus = status;
  15099. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  15100. }
  15101. int GetHeartBeatWithNOResponse(void)
  15102. {
  15103. return HeartBeatWithNOResponse;
  15104. }
  15105. void SetHeartBeatWithNOResponse(void)
  15106. {
  15107. HeartBeatWithNOResponse = 0;
  15108. }
  15109. void GetStartTransactionIdTag(int gun_index)
  15110. {
  15111. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  15112. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15113. }
  15114. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  15115. {
  15116. char ch;
  15117. FILE *fptr1;
  15118. int temptransactionId;
  15119. char str[100]={0};
  15120. temptransactionId = 0;
  15121. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  15122. {
  15123. DEBUG_INFO("IdTag is empty.\n");
  15124. return temptransactionId;
  15125. }
  15126. /*------ Read the file ----------------*/
  15127. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  15128. if (!fptr1)
  15129. {
  15130. DEBUG_INFO("QueueTransactionId file open error.\n");
  15131. //printf(" File not found or unable to open the input file!!\n");
  15132. return temptransactionId;
  15133. }
  15134. ch=fgetc(fptr1);
  15135. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  15136. rewind(fptr1);
  15137. if(ch!=EOF)
  15138. {
  15139. // printf("%c",ch);
  15140. while (fgets(str, 100, fptr1) != NULL)
  15141. {
  15142. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15143. if(str[0]=='\0')
  15144. {
  15145. break;
  15146. }
  15147. char *revbuf[8] = {0}; // Variable store string split
  15148. int num = 0;// Quantity after string split
  15149. DEBUG_INFO("Transaction queue data= %s\n", str);
  15150. splitstring(str,",",revbuf,&num); // String split
  15151. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  15152. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  15153. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  15154. DEBUG_INFO("------------------------------\n");
  15155. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  15156. {
  15157. if(isStopTransaction)
  15158. {
  15159. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  15160. {
  15161. temptransactionId = atoi(revbuf[2]);
  15162. //break;
  15163. }
  15164. }
  15165. else
  15166. {
  15167. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  15168. {
  15169. temptransactionId = atoi(revbuf[2]);
  15170. //break;
  15171. }
  15172. }
  15173. }
  15174. }
  15175. }
  15176. else
  15177. DEBUG_INFO("EOF\n");
  15178. fclose(fptr1);
  15179. /*------- End of reading ---------------*/
  15180. return temptransactionId;
  15181. }
  15182. void SetTransactionIdZero(int transactionId)
  15183. {
  15184. char ch;
  15185. FILE *fptr1, *fptr2;
  15186. int temptransactionId = 0;
  15187. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  15188. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  15189. if (!fptr1)
  15190. {
  15191. //printf(" File not found or unable to open the input file!!\n");
  15192. return ;
  15193. }
  15194. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  15195. if (!fptr2)
  15196. {
  15197. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  15198. fclose(fptr1);
  15199. return ;
  15200. }
  15201. ch=fgetc(fptr1);
  15202. rewind(fptr1);
  15203. if(ch!=EOF)
  15204. {
  15205. // copy all contents to the temporary file except the specific line
  15206. while (fgets(str, 100, fptr1) != NULL)
  15207. {
  15208. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15209. if(str[0]=='\0')
  15210. {
  15211. break;
  15212. }
  15213. char *revbuf[8] = {0};
  15214. int num = 0;
  15215. strcpy(strtemp, str);
  15216. splitstring(str,",",revbuf,&num);
  15217. if(revbuf[2][0] != '\0')
  15218. {
  15219. temptransactionId = atoi(revbuf[2]);
  15220. if(transactionId != temptransactionId)
  15221. {
  15222. fprintf(fptr2, "%s\n", strtemp);
  15223. }
  15224. }
  15225. }
  15226. }
  15227. fclose(fptr1);
  15228. fclose(fptr2);
  15229. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  15230. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  15231. /*------ Read the file ----------------*/
  15232. }
  15233. int InternetDisconnect(void)
  15234. {
  15235. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  15236. }
  15237. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  15238. void storeTempStopTransaction(int gun_index)
  15239. {
  15240. char guid[37]={0};
  15241. int tempIndex = 0;
  15242. char TempStopTransaction[256];
  15243. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  15244. DEBUG_INFO("storeTempStopTransaction...\n");
  15245. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  15246. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  15247. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  15248. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15249. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15250. {
  15251. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15252. {
  15253. tempIndex = ((gun_index==2) ? 1: 0);
  15254. }
  15255. else
  15256. {
  15257. tempIndex = gun_index;
  15258. }
  15259. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15260. {
  15261. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15262. {
  15263. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  15264. }
  15265. }// END OF CHAdeMO_QUANTITY
  15266. }
  15267. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15268. {
  15269. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15270. {
  15271. tempIndex = ((gun_index==2) ? 1: 0);
  15272. }
  15273. else
  15274. {
  15275. tempIndex = gun_index;
  15276. }
  15277. for (int index = 0; index < CCS_QUANTITY; index++)
  15278. {
  15279. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15280. {
  15281. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  15282. }
  15283. }// END OF CCS_QUANTITY
  15284. }
  15285. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15286. {
  15287. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15288. {
  15289. tempIndex = ((gun_index==2) ? 1: 0);
  15290. }
  15291. else
  15292. {
  15293. tempIndex = gun_index;
  15294. }
  15295. for (int index = 0; index < GB_QUANTITY; index++)
  15296. {
  15297. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15298. {
  15299. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  15300. }
  15301. }// END OF GB_QUANTITY
  15302. }
  15303. else if(gunType[gun_index] == GUN_TYPE_DO)
  15304. {
  15305. tempIndex = gun_index;
  15306. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15307. {
  15308. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15309. {
  15310. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  15311. }
  15312. }
  15313. }
  15314. else
  15315. {
  15316. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15317. {
  15318. tempIndex = 2;
  15319. }
  15320. else
  15321. {
  15322. tempIndex = gun_index;
  15323. }
  15324. for (int index = 0; index < AC_QUANTITY; index++)
  15325. {
  15326. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15327. {
  15328. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  15329. }
  15330. }// END OF AC_QUANTITY
  15331. }
  15332. //Stop Transaction Time
  15333. struct timeval tmnow;
  15334. struct tm *tm;
  15335. char buf[28];//, usec_buf[6];
  15336. gettimeofday(&tmnow, NULL);
  15337. time_t t;
  15338. t = time(NULL);
  15339. /*UTC time and date*/
  15340. tm = gmtime(&t);
  15341. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  15342. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  15343. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  15344. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15345. random_uuid(guid);
  15346. /***********************************transactionData******************************************************/
  15347. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  15348. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  15349. //=================================
  15350. //1. Transaction_Begin
  15351. //=================================
  15352. //============================== Energy.Active.Import.Interval ===========================================
  15353. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15354. {
  15355. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  15356. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15357. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  15358. 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*/]);
  15359. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15360. 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))
  15361. {
  15362. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  15363. }
  15364. else
  15365. {
  15366. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  15367. }
  15368. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  15369. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15370. }
  15371. //=================================
  15372. //2. Transaction_End
  15373. //=================================
  15374. //2.1====================================== Current.Import L1 ==============================================
  15375. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15376. {
  15377. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  15378. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15379. {
  15380. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15381. {
  15382. tempIndex = ((gun_index==2) ? 1: 0);
  15383. }
  15384. else
  15385. {
  15386. tempIndex = gun_index;
  15387. }
  15388. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15389. {
  15390. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15391. {
  15392. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15393. }
  15394. }// End of for CHAdeMO_QUANTITY
  15395. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15396. }
  15397. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15398. {
  15399. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15400. {
  15401. tempIndex = ((gun_index==2) ? 1: 0);
  15402. }
  15403. else
  15404. {
  15405. tempIndex = gun_index;
  15406. }
  15407. for (int index = 0; index < CCS_QUANTITY; index++)
  15408. {
  15409. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15410. {
  15411. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15412. }
  15413. }// End of for CCS_QUANTITY
  15414. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15415. }
  15416. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15417. {
  15418. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15419. {
  15420. tempIndex = ((gun_index==2) ? 1: 0);
  15421. }
  15422. else
  15423. {
  15424. tempIndex = gun_index;
  15425. }
  15426. for (int index = 0; index < GB_QUANTITY; index++)
  15427. {
  15428. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15429. {
  15430. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15431. }
  15432. }// End of for GB_QUANTITY
  15433. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15434. }
  15435. else if(gunType[gun_index] == GUN_TYPE_DO)
  15436. {
  15437. tempIndex = gun_index;
  15438. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15439. {
  15440. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15441. {
  15442. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15443. }
  15444. }
  15445. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15446. }
  15447. else
  15448. {
  15449. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15450. {
  15451. tempIndex = 2;
  15452. }
  15453. else
  15454. {
  15455. tempIndex = gun_index;
  15456. }
  15457. for (int index = 0; index < AC_QUANTITY; index++)
  15458. {
  15459. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15460. {
  15461. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  15462. }
  15463. }// End of for AC_QUANTITY
  15464. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15465. }
  15466. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15467. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  15468. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  15469. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15470. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  15471. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15472. }
  15473. //2.2===================================== Energy.Active.Import.Interval ==========================================
  15474. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15475. {
  15476. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15477. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15478. {
  15479. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15480. {
  15481. tempIndex = ((gun_index==2) ? 1: 0);
  15482. }
  15483. else
  15484. {
  15485. tempIndex = gun_index;
  15486. }
  15487. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15488. {
  15489. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15490. {
  15491. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15492. }
  15493. }// END OF CHAdeMO_QUANTITY
  15494. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15495. }
  15496. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15497. {
  15498. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15499. {
  15500. tempIndex = ((gun_index==2) ? 1: 0);
  15501. }
  15502. else
  15503. {
  15504. tempIndex = gun_index;
  15505. }
  15506. for (int index = 0; index < CCS_QUANTITY; index++)
  15507. {
  15508. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15509. {
  15510. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15511. }
  15512. }// END OF CCS_QUANTITY
  15513. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15514. }
  15515. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15516. {
  15517. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15518. {
  15519. tempIndex = ((gun_index==2) ? 1: 0);
  15520. }
  15521. else
  15522. {
  15523. tempIndex = gun_index;
  15524. }
  15525. for (int index = 0; index < GB_QUANTITY; index++)
  15526. {
  15527. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15528. {
  15529. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15530. }
  15531. }// END OF GB_QUANTITY
  15532. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15533. }
  15534. else if(gunType[gun_index] == GUN_TYPE_DO)
  15535. {
  15536. tempIndex = gun_index;
  15537. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15538. {
  15539. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15540. {
  15541. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15542. }
  15543. }
  15544. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15545. }
  15546. else
  15547. {
  15548. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15549. {
  15550. tempIndex = 2;
  15551. }
  15552. else
  15553. {
  15554. tempIndex = gun_index;
  15555. }
  15556. for (int index = 0; index < AC_QUANTITY; index++)
  15557. {
  15558. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15559. {
  15560. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15561. }
  15562. }// END OF AC_QUANTITY
  15563. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15564. }
  15565. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15566. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  15567. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  15568. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15569. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  15570. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15571. }
  15572. //2.3====================================== Power.Active.Import =========================================
  15573. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  15574. {
  15575. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15576. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15577. {
  15578. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15579. {
  15580. tempIndex = ((gun_index==2) ? 1: 0);
  15581. }
  15582. else
  15583. {
  15584. tempIndex = gun_index;
  15585. }
  15586. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15587. {
  15588. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15589. {
  15590. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15591. }
  15592. } // End for CHAdeMO_QUANTITY
  15593. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15594. }
  15595. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15596. {
  15597. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15598. {
  15599. tempIndex = ((gun_index==2) ? 1: 0);
  15600. }
  15601. else
  15602. {
  15603. tempIndex = gun_index;
  15604. }
  15605. for (int index = 0; index < CCS_QUANTITY; index++)
  15606. {
  15607. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15608. {
  15609. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15610. }
  15611. } // END for CCS_QUANTITY
  15612. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15613. }
  15614. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15615. {
  15616. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15617. {
  15618. tempIndex = ((gun_index==2) ? 1: 0);
  15619. }
  15620. else
  15621. {
  15622. tempIndex = gun_index;
  15623. }
  15624. for (int index = 0; index < GB_QUANTITY; index++)
  15625. {
  15626. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15627. {
  15628. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15629. }
  15630. }// END for GB_QUANTITY
  15631. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15632. }
  15633. else if(gunType[gun_index] == GUN_TYPE_DO)
  15634. {
  15635. tempIndex = gun_index;
  15636. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15637. {
  15638. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15639. {
  15640. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15641. }
  15642. }
  15643. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15644. }
  15645. else
  15646. {
  15647. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15648. {
  15649. tempIndex = 2;
  15650. }
  15651. else
  15652. {
  15653. tempIndex = gun_index;
  15654. }
  15655. for (int index = 0; index < AC_QUANTITY; index++)
  15656. {
  15657. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15658. {
  15659. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15660. }
  15661. } // END for AC_QUANTITY
  15662. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15663. }
  15664. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15665. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  15666. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  15667. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15668. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  15669. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  15670. }
  15671. //2.4====================================== Voltage L1 ====================================================
  15672. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15673. {
  15674. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15675. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15676. {
  15677. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15678. {
  15679. tempIndex = ((gun_index==2) ? 1: 0);
  15680. }
  15681. else
  15682. {
  15683. tempIndex = gun_index;
  15684. }
  15685. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15686. {
  15687. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15688. {
  15689. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15690. }
  15691. } // END OF FOR CHAdeMO_QUANTITY
  15692. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15693. }
  15694. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15695. {
  15696. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15697. {
  15698. tempIndex = ((gun_index==2) ? 1: 0);
  15699. }
  15700. else
  15701. {
  15702. tempIndex = gun_index;
  15703. }
  15704. for (int index = 0; index < CCS_QUANTITY; index++)
  15705. {
  15706. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15707. {
  15708. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15709. }
  15710. } // END OF FOR CCS_QUANTITY
  15711. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15712. }
  15713. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15714. {
  15715. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15716. {
  15717. tempIndex = ((gun_index==2) ? 1: 0);
  15718. }
  15719. else
  15720. {
  15721. tempIndex = gun_index;
  15722. }
  15723. for (int index = 0; index < GB_QUANTITY; index++)
  15724. {
  15725. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15726. {
  15727. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15728. }
  15729. } // END OF FOR GB_QUANTITY
  15730. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15731. }
  15732. else if(gunType[gun_index] == GUN_TYPE_DO)
  15733. {
  15734. tempIndex = gun_index;
  15735. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15736. {
  15737. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15738. {
  15739. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15740. }
  15741. }
  15742. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15743. }
  15744. else
  15745. {
  15746. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15747. {
  15748. tempIndex = 2;
  15749. }
  15750. else
  15751. {
  15752. tempIndex = gun_index;
  15753. }
  15754. for (int index = 0; index < AC_QUANTITY; index++)
  15755. {
  15756. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15757. {
  15758. 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
  15759. }
  15760. } // END OF FOR AC_QUANTITY
  15761. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15762. }
  15763. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15764. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  15765. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  15766. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15767. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  15768. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15769. }
  15770. //2.5============================================== End SoC =========================================================
  15771. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15772. {
  15773. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15774. 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))
  15775. {
  15776. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15777. {
  15778. tempIndex = ((gun_index==2) ? 1: 0);
  15779. }
  15780. else
  15781. {
  15782. tempIndex = gun_index;
  15783. }
  15784. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15785. {
  15786. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15787. {
  15788. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15789. {
  15790. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  15791. }
  15792. }
  15793. }
  15794. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15795. {
  15796. for (int index = 0; index < CCS_QUANTITY; index++)
  15797. {
  15798. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15799. {
  15800. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  15801. }
  15802. }
  15803. }
  15804. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15805. {
  15806. for (int index = 0; index < GB_QUANTITY; index++)
  15807. {
  15808. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15809. {
  15810. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  15811. }
  15812. }
  15813. }
  15814. else if(gunType[gun_index] == GUN_TYPE_DO)
  15815. {
  15816. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15817. {
  15818. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15819. {
  15820. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  15821. }
  15822. }
  15823. }
  15824. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15825. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  15826. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15827. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  15828. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  15829. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15830. } // END FOR DC CASE
  15831. }
  15832. //2.6====================================== Current.Import L2 ==============================================
  15833. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15834. {
  15835. // AC 3 phase L2 current
  15836. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15837. {
  15838. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15839. {
  15840. tempIndex = 2;
  15841. }
  15842. else
  15843. {
  15844. tempIndex = gun_index;
  15845. }
  15846. for (int index = 0; index < AC_QUANTITY; index++)
  15847. {
  15848. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15849. {
  15850. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  15851. }
  15852. }// End of for AC_QUANTITY
  15853. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  15854. }
  15855. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15856. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  15857. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  15858. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  15859. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15860. }
  15861. //2.7====================================== Current.Import L3 ==============================================
  15862. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15863. {
  15864. // AC 3 phase L3 current
  15865. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15866. {
  15867. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15868. {
  15869. tempIndex = 2;
  15870. }
  15871. else
  15872. {
  15873. tempIndex = gun_index;
  15874. }
  15875. for (int index = 0; index < AC_QUANTITY; index++)
  15876. {
  15877. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15878. {
  15879. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  15880. }
  15881. }// End of for AC_QUANTITY
  15882. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  15883. }
  15884. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15885. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  15886. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  15887. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  15888. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15889. }
  15890. //2.9====================================== Voltage L2 ====================================================
  15891. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15892. {
  15893. // AC 3 phase L2 volatge
  15894. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15895. {
  15896. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15897. {
  15898. tempIndex = 2;
  15899. }
  15900. else
  15901. {
  15902. tempIndex = gun_index;
  15903. }
  15904. for (int index = 0; index < AC_QUANTITY; index++)
  15905. {
  15906. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15907. {
  15908. 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
  15909. }
  15910. } // END OF FOR AC_QUANTITY
  15911. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  15912. }
  15913. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15914. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  15915. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  15916. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  15917. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15918. }
  15919. //2.10====================================== Voltage L3 ====================================================
  15920. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15921. {
  15922. // AC 3 phase L3 volatge
  15923. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15924. {
  15925. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15926. {
  15927. tempIndex = 2;
  15928. }
  15929. else
  15930. {
  15931. tempIndex = gun_index;
  15932. }
  15933. for (int index = 0; index < AC_QUANTITY; index++)
  15934. {
  15935. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15936. {
  15937. 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
  15938. }
  15939. } // END OF FOR AC_QUANTITY
  15940. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  15941. }
  15942. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15943. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  15944. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  15945. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  15946. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15947. }
  15948. //====================== Start SoC ================================
  15949. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15950. {
  15951. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15952. 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))
  15953. {
  15954. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15955. {
  15956. tempIndex = ((gun_index==2) ? 1: 0);
  15957. }
  15958. else
  15959. {
  15960. tempIndex = gun_index;
  15961. }
  15962. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15963. {
  15964. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15965. {
  15966. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15967. {
  15968. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  15969. }
  15970. }
  15971. }
  15972. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15973. {
  15974. for (int index = 0; index < CCS_QUANTITY; index++)
  15975. {
  15976. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15977. {
  15978. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  15979. }
  15980. }
  15981. }
  15982. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15983. {
  15984. for (int index = 0; index < GB_QUANTITY; index++)
  15985. {
  15986. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15987. {
  15988. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  15989. }
  15990. }
  15991. }
  15992. else if(gunType[gun_index] == GUN_TYPE_DO)
  15993. {
  15994. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15995. {
  15996. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15997. {
  15998. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  15999. }
  16000. }
  16001. }
  16002. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16003. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  16004. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16005. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  16006. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  16007. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16008. } // END FOR DC CASE
  16009. }
  16010. //======================================== Message create ==============================================
  16011. json_object *StopTransaction = json_object_new_object();
  16012. json_object *transactionDatas = json_object_new_array();
  16013. json_object *sampledValues = json_object_new_array();
  16014. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  16015. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  16016. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  16017. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  16018. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  16019. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  16020. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  16021. {
  16022. json_object *transactionData = json_object_new_object();
  16023. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  16024. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  16025. {
  16026. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  16027. {
  16028. json_object *sampledValue = json_object_new_object();
  16029. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  16030. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  16031. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  16032. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  16033. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  16034. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  16035. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  16036. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  16037. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  16038. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  16039. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  16040. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  16041. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  16042. json_object_array_add(sampledValues, sampledValue);
  16043. }
  16044. }
  16045. json_object_object_add(transactionData, "sampledValue", sampledValues);
  16046. json_object_array_add(transactionDatas, transactionData);
  16047. }
  16048. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  16049. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  16050. ,MESSAGE_TYPE_CALL
  16051. ,guid
  16052. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  16053. json_object_put(StopTransaction);
  16054. // Check File "TempStopTransaction" Exist
  16055. if((access(TempStopTransaction,F_OK))!=-1)
  16056. {
  16057. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  16058. fclose(fopen(TempStopTransaction, "w"));
  16059. }
  16060. else
  16061. {
  16062. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  16063. FILE *log = fopen(TempStopTransaction, "w+");
  16064. if(log == NULL)
  16065. {
  16066. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  16067. return ;
  16068. }
  16069. else
  16070. {
  16071. fclose(log);
  16072. }
  16073. }
  16074. //Add TempStopTransaction | Update TempStopTransaction
  16075. // open file for writing
  16076. FILE *outfile;
  16077. outfile = fopen (TempStopTransaction, "a");
  16078. //DEBUG_INFO("data = %s\n", queuedata);
  16079. fputs(queuedata, outfile);
  16080. fputs("\n", outfile);
  16081. fclose (outfile);
  16082. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16083. }
  16084. void checkTempStopTransaction(int gun_index)
  16085. {
  16086. FILE *fptr1;
  16087. char ch;
  16088. char str[QUEUE_MESSAGE_LENGTH]={0};
  16089. char guid[37]={0};
  16090. char tempdata[65]={0};
  16091. char connectorStr[2]={0};
  16092. char TempStopTransaction[256];
  16093. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  16094. fptr1 = fopen(TempStopTransaction, "r");
  16095. //TempStopTransaction格式: 槍號,StopTransaction封包
  16096. if (!fptr1)
  16097. {
  16098. //printf(" File not found or unable to open the input file!!\n");
  16099. return ;
  16100. }
  16101. ch=fgetc(fptr1);
  16102. //printf(" Now the content of the file %s is : \n",fname);
  16103. rewind(fptr1);
  16104. if(ch!=EOF)
  16105. {
  16106. // copy all contents to the temporary file except the specific line
  16107. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  16108. {
  16109. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16110. if(str[0]=='\0')
  16111. {
  16112. break;
  16113. }
  16114. //TempStopTransaction格式: 槍號,StopTransaction封包
  16115. strncpy(connectorStr, str, 1);
  16116. if(atoi(connectorStr) != (gun_index+1))
  16117. {
  16118. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  16119. fclose(fptr1);
  16120. return ;
  16121. }
  16122. //random_uuid(guid);
  16123. strncpy(guid, str+6, 36); //copy guid
  16124. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  16125. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  16126. {
  16127. //DEBUG_INFO("StopTransaction mapitem pass\n");
  16128. }
  16129. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  16130. OCPP_insert_transaction_msg(NO, str);
  16131. memset(str,0,ARRAY_SIZE(str));
  16132. }
  16133. }
  16134. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  16135. fclose(fptr1);
  16136. remove(TempStopTransaction); // remove the original file
  16137. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16138. }
  16139. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  16140. {
  16141. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  16142. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  16143. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  16144. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  16145. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  16146. }
  16147. int GetWebSocketPingInterval(void)
  16148. {
  16149. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16150. }
  16151. int GetServerSign(void)
  16152. {
  16153. return server_sign;
  16154. }
  16155. uint8_t GetOcppSecurityProfile()
  16156. {
  16157. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16158. }
  16159. void GetOcppChargerBoxId(uint8_t *data)
  16160. {
  16161. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  16162. }
  16163. void GetOcppSecurityPassword(uint8_t *data)
  16164. {
  16165. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16166. }
  16167. void SetOcppVersion(uint8_t *version)
  16168. {
  16169. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  16170. DEBUG_INFO("ocpp version: %s\n", version);
  16171. if(strstr((char*)version, "ocpp1.6") != NULL)
  16172. {
  16173. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  16174. }
  16175. else if(strstr((char*)version, "ocpp2.0") != NULL)
  16176. {
  16177. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  16178. system("pkill OcppBackend");
  16179. }
  16180. }
  16181. void SetServerSign(int value)
  16182. {
  16183. server_sign = value;
  16184. }
  16185. int GetBootNotificationInterval(void)
  16186. {
  16187. return BootNotificationInterval;
  16188. }
  16189. int GetInternetConn(void)
  16190. {
  16191. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  16192. }
  16193. int GetBackendConnectionTimeout(void)
  16194. {
  16195. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  16196. }
  16197. int isConnectorInitMode(int gun_index)
  16198. {
  16199. int tempIndex = 0;
  16200. int result = TRUE;
  16201. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16202. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16203. {
  16204. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16205. {
  16206. tempIndex = ((gun_index==2) ? 1: 0);
  16207. }
  16208. else
  16209. {
  16210. tempIndex = gun_index;
  16211. }
  16212. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16213. {
  16214. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  16215. {
  16216. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16217. } //end of the same index
  16218. }//end of for CHAdeMO_QUANTITY
  16219. }
  16220. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16221. {
  16222. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16223. {
  16224. tempIndex = ((gun_index==2) ? 1: 0);
  16225. }
  16226. else
  16227. {
  16228. tempIndex = gun_index;
  16229. }
  16230. for (int index = 0; index < CCS_QUANTITY; index++)
  16231. {
  16232. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16233. {
  16234. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16235. } //end of the same index
  16236. } // end of for CCS_QUANTITY
  16237. }
  16238. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16239. {
  16240. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16241. {
  16242. tempIndex = ((gun_index==2) ? 1: 0);
  16243. }
  16244. else
  16245. {
  16246. tempIndex = gun_index;
  16247. }
  16248. for (int index = 0; index < GB_QUANTITY; index++)
  16249. {
  16250. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16251. {
  16252. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16253. } //end of the same index
  16254. } // end of for GB_QUANTITY
  16255. }
  16256. else if(gunType[gun_index] == GUN_TYPE_DO)
  16257. {
  16258. tempIndex = gun_index;
  16259. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16260. {
  16261. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16262. {
  16263. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16264. } //end of the same index
  16265. }
  16266. }
  16267. else
  16268. {
  16269. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16270. {
  16271. tempIndex = 2;
  16272. }
  16273. else
  16274. {
  16275. tempIndex = gun_index;
  16276. }
  16277. for (int index = 0; index < AC_QUANTITY; index++)
  16278. {
  16279. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16280. {
  16281. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16282. }//end of the same index
  16283. }//end of for AC_QUANTITY
  16284. }
  16285. return result;
  16286. }
  16287. void refreshProcDogTimer()
  16288. {
  16289. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  16290. }
  16291. void InitialSystemValue(void)
  16292. {
  16293. int connectorIndex = 0;
  16294. //int valueASCII = 0;
  16295. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16296. gunTotalNumber=0;
  16297. SystemInitial = 0;
  16298. locallistVersion=0;
  16299. BootNotificationInterval = 0;
  16300. authorizeRetryTimes = 0;
  16301. GunStatusInterval = 10;
  16302. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16303. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16304. //Hear Beat
  16305. HeartBeatWithNOResponse = 0;
  16306. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  16307. FirstHeartBeat = 0;
  16308. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  16309. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  16310. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  16311. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  16312. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  16313. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  16314. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  16315. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  16316. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  16317. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  16318. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  16319. memset(gunType, 0, ARRAY_SIZE(gunType));
  16320. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  16321. {
  16322. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  16323. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  16324. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  16325. {
  16326. // DO series
  16327. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  16328. {
  16329. SystemInitial = SystemInitial + 1;
  16330. gunTotalNumber = gunTotalNumber + 1;
  16331. gunType[connectorIndex] = GUN_TYPE_DO;
  16332. connectorIndex = connectorIndex + 1;
  16333. }
  16334. }
  16335. else
  16336. {
  16337. // DM, DW, DS series
  16338. //check connector / socket type (index: 8, 9, 10)
  16339. for(int index=7; index <10 ; index++)
  16340. {
  16341. if(index != 8)
  16342. {
  16343. // DC Connector
  16344. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  16345. {
  16346. SystemInitial = SystemInitial + 1;
  16347. gunTotalNumber = gunTotalNumber + 1;
  16348. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  16349. connectorIndex = connectorIndex + 1;
  16350. }
  16351. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  16352. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  16353. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  16354. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  16355. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  16356. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  16357. {
  16358. SystemInitial = SystemInitial + 1;
  16359. gunTotalNumber = gunTotalNumber + 1;
  16360. gunType[connectorIndex] = GUN_TYPE_CCS;
  16361. connectorIndex = connectorIndex + 1;
  16362. }
  16363. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  16364. {
  16365. SystemInitial = SystemInitial + 1;
  16366. gunTotalNumber = gunTotalNumber + 1;
  16367. gunType[connectorIndex] = GUN_TYPE_GBT;
  16368. connectorIndex = connectorIndex + 1;
  16369. }
  16370. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  16371. {
  16372. SystemInitial = SystemInitial + 1;
  16373. gunTotalNumber = gunTotalNumber + 1;
  16374. gunType[connectorIndex] = GUN_TYPE_DO;
  16375. connectorIndex = connectorIndex + 1;
  16376. }
  16377. }
  16378. else
  16379. {
  16380. // AC Connector
  16381. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16382. {
  16383. SystemInitial = SystemInitial + 1;
  16384. gunTotalNumber = gunTotalNumber + 1;
  16385. gunType[connectorIndex] = GUN_TYPE_AC;
  16386. connectorIndex = connectorIndex + 1;
  16387. }
  16388. }
  16389. }
  16390. }
  16391. //DEBUG_INFO("DC ...\n");
  16392. }
  16393. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  16394. {
  16395. //check connector / socket type (index: 8, 9, 10)
  16396. for(int index=7; index <10 ; index++)
  16397. {
  16398. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16399. {
  16400. SystemInitial = SystemInitial + 1;
  16401. gunTotalNumber = gunTotalNumber + 1;
  16402. gunType[connectorIndex] = GUN_TYPE_AC;
  16403. connectorIndex = connectorIndex + 1;
  16404. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  16405. }
  16406. }
  16407. }
  16408. //Status && ConnectorPlugIn Setting
  16409. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16410. {
  16411. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  16412. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  16413. }
  16414. for (int index = 0; index < CCS_QUANTITY; index++)
  16415. {
  16416. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  16417. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  16418. }
  16419. for (int index = 0; index < GB_QUANTITY; index++)
  16420. {
  16421. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  16422. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  16423. }
  16424. for (int index = 0; index < AC_QUANTITY; index++)
  16425. {
  16426. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  16427. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  16428. }
  16429. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16430. {
  16431. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  16432. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  16433. }
  16434. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  16435. {
  16436. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  16437. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  16438. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  16439. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  16440. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  16441. }
  16442. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  16443. clientTime.Heartbeat=time((time_t*)NULL);
  16444. sleep(1);
  16445. }
  16446. void LWS_Send(char *str)
  16447. {
  16448. //=====================================================
  16449. // Check InternetConn 0: disconnected, 1: connected
  16450. //====================================================
  16451. if(GetOcppConnStatus() == 0)
  16452. {
  16453. DEBUG_INFO("offline now !!!\n");
  16454. return;
  16455. }
  16456. // Only disable isWebsocketSendable operation initiated by charger
  16457. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16458. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16459. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16460. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16461. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16462. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16463. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16464. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16465. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16466. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16467. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16468. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16469. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16470. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16471. {
  16472. isWebsocketSendable = 0;
  16473. }
  16474. pthread_mutex_lock(&lock_send);
  16475. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16476. sprintf((char *)SendBuffer, "%s", str);
  16477. SendBufLen = strlen(str);
  16478. pthread_mutex_unlock(&lock_send);
  16479. lws_callback_on_writable(wsi_client);
  16480. //lws_service(context, 0);
  16481. //sleep(1);
  16482. }
  16483. void LWS_SendNow(char *str)
  16484. {
  16485. //=====================================================
  16486. // Check InternetConn 0: disconnected, 1: connected
  16487. //====================================================
  16488. if(GetOcppConnStatus() == 0)
  16489. {
  16490. DEBUG_INFO("offline now !!!\n");
  16491. return;
  16492. }
  16493. // Only disable isWebsocketSendable operation initiated by charger
  16494. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16495. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16496. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16497. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16498. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16499. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16500. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16501. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16502. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16503. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16504. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16505. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16506. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16507. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16508. {
  16509. isWebsocketSendable = 0;
  16510. }
  16511. pthread_mutex_lock(&lock_send);
  16512. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16513. sprintf((char *)SendBuffer, "%s", str);
  16514. SendBufLen = strlen(str);
  16515. pthread_mutex_unlock(&lock_send);
  16516. lws_callback_on_writable(wsi_client);
  16517. lws_service(context, 0);
  16518. //sleep(1);
  16519. }