MessageHandler.c 890 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknown key
  21. //===============================
  22. static char unknownkey[10][36] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static int gunTotalNumber = 0;
  28. static uint8_t gunType[4] = {0};
  29. //===============================
  30. // Local List Version
  31. //===============================
  32. static int locallistVersion=0;
  33. static char idTagAuthorization[32] = {0};
  34. //===============================
  35. // OCPP sign variable
  36. //===============================
  37. static int server_sign = FALSE;
  38. int server_pending = FALSE;
  39. static int BootNotificationInterval = 0;
  40. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  41. //===============================
  42. // OCPP auth variable
  43. //===============================
  44. static int authorizeRetryTimes = 0; //number of Retry times
  45. //===============================
  46. // OCPP other variables
  47. //===============================
  48. static int HeartBeatWaitTime = 10;
  49. static int FirstHeartBeat = 0;
  50. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  51. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  52. static char CurrentChargingProfileScheduleStr[30] = {0};
  53. //========================================
  54. // OCPP status/previous related variables
  55. //========================================
  56. static int GunStatusInterval = 10;
  57. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  58. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  59. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  60. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  61. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  62. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  63. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  64. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  65. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  66. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  67. static int TransactionMessageAttemptsValue = 0;
  68. static int TransactionMessageRetryIntervalValue = 0;
  69. static int TempMeterValueInterval = 0;
  70. static struct OCPPAuthLocalElemet
  71. {
  72. int listVersionInt;
  73. char idTagstr[21];
  74. char parentIdTag[21];
  75. char expiryDate[36];
  76. char idTagstatus[16];
  77. }idTagQuery;
  78. //=============================================
  79. // OCPP HeartBeat Response Not Receive Counts
  80. //============================================
  81. static int HeartBeatWithNOResponse = 0;
  82. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  83. extern sqlite3 *db;
  84. int TransactionMessageAttemptsGet(void);
  85. int TransactionMessageRetryIntervalGet(void);
  86. int GetOcppConnStatus(void);
  87. void SetOcppConnStatus(uint8_t status);
  88. int setKeyValue(char *key, char *value);
  89. void OCPP_get_TableAuthlocalAllData(void);
  90. void processUnkownKey(void);
  91. struct InterLock
  92. {
  93. unsigned char isGetDiagnosticGoing:1;
  94. unsigned char isUpdateFirmwareGoing:1;
  95. }interLock;
  96. struct ClientTime
  97. {
  98. struct timespec Heartbeat;
  99. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  100. struct timespec StartTransaction;
  101. struct timespec StopTransaction;
  102. struct timespec MeterValues[CONNECTOR_QUANTITY];
  103. struct timespec RemoteStartWait;
  104. }clientTime;
  105. typedef union
  106. {
  107. //Operations Initiated by Central System
  108. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  109. struct
  110. {
  111. //CsMsgValue[0]
  112. unsigned char StatusNotificationReq:1; //bit 0,
  113. unsigned char StatusNotificationConf:1; //bit 1,
  114. unsigned char TriggerMeterValue:1; //bit 2,
  115. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  116. unsigned char isOnCharging:1; //bit 4,
  117. unsigned char :3; //bit5~7
  118. }bits[CONNECTOR_QUANTITY];
  119. }CpinitiateMsg;
  120. CpinitiateMsg cpinitateMsg;
  121. //GetConfiguration Array
  122. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  123. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  124. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  125. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  126. #if 0
  127. static char *ChargePointErrorCodeStr[] = {
  128. MACROSTR(ConnectorLockFailure),
  129. MACROSTR(EVCommunicationError),
  130. MACROSTR(GroundFailure),
  131. MACROSTR(HighTemperature),
  132. MACROSTR(InternalError),
  133. MACROSTR(LocalListConflict),
  134. MACROSTR(NoError),
  135. MACROSTR(OtherError),
  136. MACROSTR(OverCurrentFailure),
  137. MACROSTR(OverVoltage),
  138. MACROSTR(PowerMeterFailure),
  139. MACROSTR(PowerSwitchFailure),
  140. MACROSTR(ReaderFailure),
  141. MACROSTR(ResetFailure),
  142. MACROSTR(UnderVoltage),
  143. MACROSTR(WeakSignal)
  144. };
  145. #endif
  146. static char * ChargePointStatusStr[] = {
  147. MACROSTR(Available),
  148. MACROSTR(Preparing),
  149. MACROSTR(Charging),
  150. MACROSTR(SuspendedEVSE),
  151. MACROSTR(SuspendedEV),
  152. MACROSTR(Finishing),
  153. MACROSTR(Reserved),
  154. MACROSTR(Unavailable),
  155. MACROSTR(Faulted)
  156. };
  157. static char *RegistrationStatusStr[] = {
  158. MACROSTR(Accepted),
  159. MACROSTR(Pending),
  160. MACROSTR(Rejected)
  161. };
  162. static char *AvailabilityTypeStr[] = {
  163. MACROSTR(Inoperative),
  164. MACROSTR(Operative)
  165. };
  166. static char *AvailabilityStatusStr[] = {
  167. MACROSTR(Accepted),
  168. MACROSTR(Rejected),
  169. MACROSTR(Scheduled)
  170. };
  171. static char *ConfigurationStatusStr[] = {
  172. MACROSTR(Accepted),
  173. MACROSTR(Rejected),
  174. MACROSTR(RebootRequired),
  175. MACROSTR(NotSupported)
  176. };
  177. static char *ClearCacheStatusStr[] = {
  178. MACROSTR(Accepted),
  179. MACROSTR(Rejected)
  180. };
  181. static char *ChargingProfilePurposeTypeStr[] = {
  182. MACROSTR(ChargePointMaxProfile),
  183. MACROSTR(TxDefaultProfile),
  184. MACROSTR(TxProfile)
  185. };
  186. static char *ChargingProfileStatusStr[] = {
  187. MACROSTR(Accepted),
  188. MACROSTR(Rejected),
  189. MACROSTR(NotSupported)
  190. };
  191. static char *ClearChargingProfileStatusStr[] = {
  192. MACROSTR(Accepted),
  193. MACROSTR(Unknown)
  194. };
  195. static char *GetCompositeScheduleStatusStr[] = {
  196. MACROSTR(Accepted),
  197. MACROSTR(Rejected)
  198. };
  199. static char *UpdateTypeStr[] = {
  200. MACROSTR(Differential),
  201. MACROSTR(Full)
  202. };
  203. static char *UpdateStatusStr[] = {
  204. MACROSTR(Accepted),
  205. MACROSTR(Failed),
  206. MACROSTR(NotSupported),
  207. MACROSTR(VersionMismatch)
  208. };
  209. static char *RemoteStartStopStatusStr[] = {
  210. MACROSTR(Accepted),
  211. MACROSTR(Rejected)
  212. };
  213. static char *ReservationStatusStr[] = {
  214. MACROSTR(Accepted),
  215. MACROSTR(Faulted),
  216. MACROSTR(Occupied),
  217. MACROSTR(Rejected),
  218. MACROSTR(Unavailable)
  219. };
  220. static char *ResetTypeStr[] = {
  221. MACROSTR(Hard),
  222. MACROSTR(Soft)
  223. };
  224. static char *ResetStatusStr[] = {
  225. MACROSTR(Accepted),
  226. MACROSTR(Rejected)
  227. };
  228. static char * DiagnosticsStatusStr[] = {
  229. MACROSTR(Idle),
  230. MACROSTR(Uploaded),
  231. MACROSTR(UploadFailed),
  232. MACROSTR(Uploading)
  233. };
  234. static char * FirmwareStatusStr[] = {
  235. MACROSTR(Downloaded),
  236. MACROSTR(DownloadFailed),
  237. MACROSTR(Downloading),
  238. MACROSTR(Idle),
  239. MACROSTR(InstallationFailed),
  240. MACROSTR(Installing),
  241. MACROSTR(Installed)
  242. };
  243. static char * MessageTriggerStr[] = {
  244. MACROSTR(BootNotification),
  245. MACROSTR(DiagnosticsStatusNotification),
  246. MACROSTR(FirmwareStatusNotification),
  247. MACROSTR(Heartbeat),
  248. MACROSTR(MeterValues),
  249. MACROSTR(StatusNotification)
  250. };
  251. static char * TriggerMessageStatusStr[] = {
  252. MACROSTR(Accepted),
  253. MACROSTR(Rejected),
  254. MACROSTR(NotImplemented)
  255. };
  256. static char * UnlockStatusStr[] = {
  257. MACROSTR(Unlocked),
  258. MACROSTR(UnlockFailed),
  259. MACROSTR(NotSupported)
  260. };
  261. #if 0
  262. static char * StopTransactionReasonStr[] = {
  263. MACROSTR(EmergencyStop),
  264. MACROSTR(EVDisconnected),
  265. MACROSTR(HardReset),
  266. MACROSTR(Local),
  267. MACROSTR(Other),
  268. MACROSTR(PowerLoss),
  269. MACROSTR(Reboot),
  270. MACROSTR(Remote),
  271. MACROSTR(SoftReset),
  272. MACROSTR(UnlockCommand),
  273. MACROSTR(DeAuthorized)
  274. };
  275. #endif
  276. static char * CancelReservationStatusStr[] = {
  277. MACROSTR(Accepted),
  278. MACROSTR(Rejected)
  279. };
  280. static char * ReadingContextStr[] = {
  281. MACROSTR(Interruption.Begin),
  282. MACROSTR(Interruption.End),
  283. MACROSTR(Other),
  284. MACROSTR(Sample.Clock),
  285. MACROSTR(Sample.Periodic),
  286. MACROSTR(Transaction.Begin),
  287. MACROSTR(Transaction.End),
  288. MACROSTR(Trigger)
  289. };
  290. static char * ValueFormatStr[] = {
  291. MACROSTR(Raw),
  292. MACROSTR(SignedData)
  293. };
  294. static char * MeasurandStr[] = {
  295. MACROSTR(Current.Export),
  296. MACROSTR(Current.Import),
  297. MACROSTR(Current.Offered),
  298. MACROSTR(Energy.Active.Export.Register),
  299. MACROSTR(Energy.Active.Import.Register),
  300. MACROSTR(Energy.Reactive.Export.Register),
  301. MACROSTR(Energy.Reactive.Import.Register),
  302. MACROSTR(Energy.Active.Export.Interval),
  303. MACROSTR(Energy.Active.Import.Interval),
  304. MACROSTR(Energy.Reactive.Export.Interval),
  305. MACROSTR(Energy.Reactive.Import.Interval),
  306. MACROSTR(Frequency),
  307. MACROSTR(Power.Active.Export),
  308. MACROSTR(Power.Active.Import),
  309. MACROSTR(Power.Factor),
  310. MACROSTR(Power.Offered),
  311. MACROSTR(Power.Reactive.ExportMACROSTR),
  312. MACROSTR(Power.Reactive.Import),
  313. MACROSTR(RPM),
  314. MACROSTR(SoC),
  315. MACROSTR(Temperature),
  316. MACROSTR(Voltage)
  317. };
  318. static char * LocationStr[] = {
  319. MACROSTR(Body),
  320. MACROSTR(Cable),
  321. MACROSTR(EV),
  322. MACROSTR(Inlet),
  323. MACROSTR(Outlet)
  324. };
  325. static char * PhaseStr[] = {
  326. MACROSTR(L1),
  327. MACROSTR(L2),
  328. MACROSTR(L3),
  329. MACROSTR(N),
  330. MACROSTR(L1-N),
  331. MACROSTR(L2-N),
  332. MACROSTR(L3-N),
  333. MACROSTR(L1-L2),
  334. MACROSTR(L2-L3),
  335. MACROSTR(L3-L1)
  336. };
  337. static char * UnitOfMeasureStr[] = {
  338. MACROSTR(Wh),
  339. MACROSTR(kWh),
  340. MACROSTR(varh),
  341. MACROSTR(kvarh),
  342. MACROSTR(W),
  343. MACROSTR(kW),
  344. MACROSTR(VA),
  345. MACROSTR(kVA),
  346. MACROSTR(var),
  347. MACROSTR(kvar),
  348. MACROSTR(A),
  349. MACROSTR(V),
  350. MACROSTR(Celsius),
  351. MACROSTR(Fahrenheit),
  352. MACROSTR(K),
  353. MACROSTR(Percent)
  354. };
  355. //=========================================
  356. // TTIA routine
  357. //=========================================
  358. int sendTTIAInfo(uint8_t gun_index)
  359. {
  360. static int sn = 0;
  361. int result = FAIL;
  362. struct hostent *server;
  363. int udp_socket_fd;
  364. struct sockaddr_in dest_addr = {0};
  365. uint8_t tx_buf[80] = {0};
  366. uint8_t logBuf[256]= {0};
  367. uint8_t tx_len, tempIndex, socStart, socEnd;
  368. uint16_t PresentChargedEnergy;
  369. struct tm tmStart, tmEnd;
  370. DEBUG_INFO("sendTTIAInfo...\n");
  371. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  372. {
  373. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  374. {
  375. tempIndex = ((gun_index==2) ? 1: 0);
  376. }
  377. else
  378. {
  379. tempIndex = gun_index;
  380. }
  381. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  382. {
  383. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  384. {
  385. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  386. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  387. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  388. }
  389. }
  390. }
  391. else if(gunType[gun_index] == GUN_TYPE_CCS)
  392. {
  393. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  394. {
  395. tempIndex = ((gun_index==2) ? 1: 0);
  396. }
  397. else
  398. {
  399. tempIndex = gun_index;
  400. }
  401. for (int index = 0; index < CCS_QUANTITY; index++)
  402. {
  403. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  404. {
  405. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  406. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  407. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  408. }
  409. }
  410. }
  411. else if(gunType[gun_index] == GUN_TYPE_GBT)
  412. {
  413. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  414. {
  415. tempIndex = ((gun_index==2) ? 1: 0);
  416. }
  417. else
  418. {
  419. tempIndex = gun_index;
  420. }
  421. for (int index = 0; index < GB_QUANTITY; index++)
  422. {
  423. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  424. {
  425. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  426. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  427. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  428. }
  429. }
  430. }
  431. else if(gunType[gun_index] == GUN_TYPE_DO)
  432. {
  433. tempIndex = gun_index;
  434. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  435. {
  436. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  437. {
  438. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  439. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  440. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  441. }
  442. }
  443. }
  444. else
  445. {
  446. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  447. {
  448. tempIndex = 2;
  449. }
  450. else
  451. {
  452. tempIndex = gun_index;
  453. }
  454. for (int index = 0; index < AC_QUANTITY; index++)
  455. {
  456. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  457. {
  458. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  459. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  460. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  461. }
  462. }// END
  463. }
  464. // Message assembly
  465. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  466. tx_buf[4] = 0x02; // Protocol Version
  467. tx_buf[5] = 0xb0; // Message ID
  468. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  469. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  470. tx_buf[8] = 0x00; // CarID low byte
  471. tx_buf[9] = 0x00; // CarID high byte
  472. tx_buf[10] = 0x00; // ID Storage
  473. tx_buf[11] = 0x00; // Driver lowest byte
  474. tx_buf[12] = 0x00; // Driver 2nd byte
  475. tx_buf[13] = 0x00; // Driver 3rd byte
  476. tx_buf[14] = 0x00; // Driver highest byte
  477. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  478. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  479. tx_buf[17] = 0x00; // Reserve
  480. tx_buf[18] = 60 & 0xff; // Payload length low byte
  481. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  482. // EVSE provider
  483. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  484. // EVSE provider
  485. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  486. // EVSE id
  487. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  488. // Connector id
  489. tx_buf[37] = gun_index;
  490. // EVSE station
  491. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  492. // Vehicle SN
  493. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  494. // Mileage
  495. tx_buf[61] = 0x00; // lowest byte
  496. tx_buf[62] = 0x00; // 2nd byte
  497. tx_buf[63] = 0x00; // highest byte
  498. // Start date time 6 bytes
  499. if((sscanf((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6))
  500. {
  501. struct tm *tmTarget;
  502. struct timeb tbTarget;
  503. tmStart.tm_year -= 1900;
  504. tmStart.tm_mon -= 1;
  505. tmStart.tm_gmtoff = 0;
  506. tbTarget.time = mktime(&tmStart);
  507. tbTarget.timezone = 0;
  508. tbTarget.time += (8*3600);
  509. tmTarget = gmtime(&tbTarget.time);
  510. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  511. tx_buf[65] = (tmTarget->tm_mon+1);
  512. tx_buf[66] = tmTarget->tm_mday;
  513. tx_buf[67] = tmTarget->tm_hour;
  514. tx_buf[68] = tmTarget->tm_min;
  515. tx_buf[69] = tmTarget->tm_sec;
  516. }
  517. // Stop date time 6 bytes
  518. if((sscanf((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmEnd.tm_year, &tmEnd.tm_mon, &tmEnd.tm_mday, &tmEnd.tm_hour, &tmEnd.tm_min, &tmEnd.tm_sec) == 6))
  519. {
  520. struct tm *tmTarget;
  521. struct timeb tbTarget;
  522. tmEnd.tm_year -= 1900;
  523. tmEnd.tm_mon -= 1;
  524. tmEnd.tm_gmtoff = 0;
  525. tbTarget.time = mktime(&tmEnd);
  526. tbTarget.timezone = 0;
  527. tbTarget.time += (8*3600);
  528. tmTarget = gmtime(&tbTarget.time);
  529. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  530. tx_buf[71] = (tmTarget->tm_mon+1);
  531. tx_buf[72] = tmTarget->tm_mday;
  532. tx_buf[73] = tmTarget->tm_hour;
  533. tx_buf[74] = tmTarget->tm_min;
  534. tx_buf[75] = tmTarget->tm_sec;
  535. }
  536. // Session energy 2 bytes
  537. tx_buf[76] = PresentChargedEnergy & 0xff;
  538. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  539. // Start SOC 1 byte
  540. tx_buf[78] = socStart;
  541. // Stop SOC 1 byte
  542. tx_buf[79] = socEnd;
  543. // Open socket
  544. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  545. if(udp_socket_fd == -1)
  546. {
  547. DEBUG_ERROR("UDP socket create failed!\n");
  548. }
  549. else
  550. {
  551. // Get server DNS entry
  552. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  553. if (server == NULL)
  554. {
  555. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  556. }
  557. else
  558. {
  559. // Build the server's Internet address
  560. bzero((char *) &dest_addr, sizeof(dest_addr));
  561. dest_addr.sin_family = AF_INET;
  562. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  563. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  564. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  565. {
  566. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  567. {
  568. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  569. }
  570. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  571. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  572. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  573. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  574. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  575. DEBUG_TTIA_INFO("---------- Header ----------\n");
  576. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  577. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  578. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  579. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  580. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  581. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  582. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  583. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  584. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  585. DEBUG_TTIA_INFO("Len: 0x3C\n");
  586. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  587. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  588. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  589. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  590. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  591. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  592. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  593. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  594. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  595. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  596. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  597. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  598. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  599. DEBUG_TTIA_INFO("=========================================\n");
  600. sn++;
  601. result = PASS;
  602. }
  603. else
  604. {
  605. DEBUG_ERROR("UDP sent out fail.\n");
  606. }
  607. }
  608. }
  609. return result;
  610. }
  611. //=========================================
  612. // Save configuration
  613. //=========================================
  614. int runShellCmd(const char*cmd)
  615. {
  616. int result = FAIL;
  617. char buf[256];
  618. FILE *fp;
  619. fp = popen(cmd, "r");
  620. if(fp != NULL)
  621. {
  622. while(fgets(buf, sizeof(buf), fp) != NULL)
  623. {
  624. DEBUG_INFO("%s\n", buf);
  625. }
  626. result = PASS;
  627. }
  628. pclose(fp);
  629. return result;
  630. }
  631. int StoreUsrConfigData(struct SysConfigData *UsrData)
  632. {
  633. int result = PASS;
  634. int fd,wrd;
  635. unsigned int i,Chk;
  636. unsigned char *ptr, *BufTmp;
  637. int MtdBlockSize = 0x300000;
  638. Chk=0;
  639. ptr=(unsigned char *)UsrData;
  640. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  641. {
  642. memset(BufTmp,0,MtdBlockSize);
  643. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  644. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  645. Chk+=*(BufTmp+i);
  646. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  647. // Output configuration to file.
  648. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  649. if (fd < 0)
  650. {
  651. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  652. free(BufTmp);
  653. return 0;
  654. }
  655. wrd=write(fd, BufTmp, MtdBlockSize);
  656. close(fd);
  657. if(wrd<MtdBlockSize)
  658. {
  659. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  660. free(BufTmp);
  661. return 0;
  662. }
  663. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  664. DEBUG_INFO("Erase /dev/mtd10.\n");
  665. runShellCmd("flash_erase /dev/mtd10 0 0");
  666. DEBUG_INFO("Write /dev/mtd10.\n");
  667. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  668. DEBUG_INFO("Erase /dev/mtd11.\n");
  669. runShellCmd("flash_erase /dev/mtd11 0 0");
  670. DEBUG_INFO("Write /dev/mtd11.\n");
  671. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  672. system("rm -f /mnt/EvseConfig.bin");
  673. DEBUG_INFO("EvseConfig write to flash OK\n");
  674. }
  675. else
  676. {
  677. DEBUG_ERROR("alloc BlockSize NG\r\n");
  678. result = FAIL;
  679. }
  680. if(BufTmp!=NULL)
  681. free(BufTmp);
  682. return result;
  683. }
  684. //=========================================
  685. // Sqlite3 related function
  686. //=========================================
  687. static int selectSqlCount = 0;
  688. static int callback(void *data, int argc, char **argv, char **azColName){
  689. int i;
  690. //printf("%s: ", (const char*)data);
  691. selectSqlCount = argc;
  692. for(i = 0; i<argc; i++){
  693. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  694. }
  695. //printf("\n");
  696. return 0;
  697. }
  698. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  699. //int i;
  700. //printf("%s:\n", (const char*)data);
  701. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  702. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  703. return 0;
  704. }
  705. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  706. //printf("%s:\n", (const char*)data);
  707. //idTag
  708. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  709. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  710. //parentIdTag
  711. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  712. //expir_date
  713. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  714. //status
  715. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  716. //version
  717. if(columenCount > 5)
  718. idTagQuery.listVersionInt = atoi(columnValue[5]);
  719. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  720. return 0;
  721. }
  722. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  723. {
  724. // localversion = argv[5] ? atoi(argv[5]) : 0;
  725. // printf("localversion=%d\n", localversion);
  726. return 0;
  727. }
  728. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  729. {
  730. for (int i = 0; i < n_columns; i++)
  731. {
  732. DEBUG_INFO("%s\t", col_values[i]);
  733. }
  734. DEBUG_INFO("\n");
  735. return 0;
  736. }
  737. int OCPP_cleanLocalCache()
  738. {
  739. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  740. char *errMsg = 0;
  741. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  742. if (SQLITE_OK != rc)
  743. {
  744. DEBUG_INFO("SQL error: %s\n",errMsg);
  745. return FALSE;
  746. }
  747. return TRUE;
  748. }
  749. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  750. {
  751. int isSuccess = TRUE;
  752. int ret = 0;
  753. //const char* data = "Callback function called";
  754. char sql[300];
  755. char zErrMsg[200];
  756. memset(sql, 0, 300);
  757. memset(zErrMsg, 0, 200);
  758. 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);
  759. //* Execute SQL statement */
  760. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  761. if( ret != SQLITE_OK )
  762. {
  763. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  764. isSuccess = FALSE;
  765. }
  766. return isSuccess;
  767. }
  768. void OCPP_getIdTagFromLocalCache(char idTag[])
  769. {
  770. int rc = 0;
  771. char sql[100];
  772. char zErrMsg[100];
  773. memset(sql, 0, 100);
  774. memset(zErrMsg, 0, 100);
  775. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  776. memset(&idTagQuery, 0, sizeof(idTagQuery));
  777. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  778. /* Execute SQL statement */
  779. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  780. if( rc != SQLITE_OK )
  781. {
  782. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  783. }
  784. }
  785. void OCPP_getListVerion()
  786. {
  787. int rc = 0;
  788. // const char* data = "Callback function called";
  789. char sql[100];
  790. char zErrMsg[100];
  791. memset(sql, 0, 100);
  792. memset(zErrMsg, 0, 100);
  793. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  794. /* Execute SQL statement */
  795. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  796. if( rc != SQLITE_OK )
  797. {
  798. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  799. }
  800. }
  801. void OCPP_get_TableAuthlocalAllData(void)
  802. {
  803. int rc = 0;
  804. char sql[100];
  805. char zErrMsg[100];
  806. memset(sql, 0, 100);
  807. memset(zErrMsg, 0, 100);
  808. sprintf(sql,"select * from ocpp_auth_local ");
  809. /* Execute SQL statement */
  810. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  811. if( rc != SQLITE_OK )
  812. {
  813. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  814. }
  815. //return ver;
  816. }
  817. int OCPP_cleanLocalList()
  818. {
  819. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  820. char *errMsg = 0;
  821. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  822. if (SQLITE_OK != rc)
  823. {
  824. DEBUG_INFO("%s\n",errMsg);
  825. return FALSE;
  826. }
  827. return TRUE;
  828. }
  829. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  830. {
  831. int isSuccess = FALSE;
  832. int ret = 0;
  833. //const char* data = "Callback function called";
  834. char sql[300];
  835. char zErrMsg[200];
  836. memset(sql, 0, 300);
  837. memset(zErrMsg, 0, 200);
  838. 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);
  839. //* Execute SQL statement */
  840. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  841. if( ret != SQLITE_OK )
  842. {
  843. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  844. return isSuccess;
  845. }
  846. memset(sql, 0, 300);
  847. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  848. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  849. if( ret != SQLITE_OK )
  850. {
  851. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  852. return isSuccess;
  853. }
  854. isSuccess = TRUE;
  855. return isSuccess;
  856. }
  857. void OCPP_getIdTagFromLocalList(char idTag[])
  858. {
  859. int rc = 0;
  860. // const char* data = "Callback function called";
  861. char sql[100];
  862. char zErrMsg[100];
  863. memset(sql, 0, 100);
  864. memset(zErrMsg, 0, 100);
  865. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  866. memset(&idTagQuery, 0, sizeof(idTagQuery));
  867. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  868. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  869. /* Execute SQL statement */
  870. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  871. if( rc != SQLITE_OK )
  872. {
  873. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  874. }
  875. //return ver;
  876. }
  877. void OCPP_deleteIdTagFromLocalList(char idTag[])
  878. {
  879. //int ver = 0;
  880. //int isSuccess = FALSE;
  881. int rc = 0;
  882. char sql[100];
  883. char zErrMsg[100];
  884. memset(sql, 0, 100);
  885. memset(zErrMsg, 0, 100);
  886. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  887. //* Execute SQL statement */
  888. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  889. if( rc != SQLITE_OK )
  890. {
  891. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  892. }
  893. }
  894. int getCurrentYear()
  895. {
  896. int result = 0;
  897. time_t CurrentTime;
  898. struct tm *tm;
  899. CurrentTime = time(NULL);
  900. tm=localtime(&CurrentTime);
  901. result = (tm->tm_year + 1900);
  902. return result;
  903. }
  904. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  905. {
  906. int result = PASS;
  907. char* errMsg = NULL;
  908. char sqlStr[8192];
  909. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  910. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  911. {
  912. result = FAIL;
  913. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  914. }
  915. 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));
  916. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  917. {
  918. result = FAIL;
  919. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  920. }
  921. return result;
  922. }
  923. //==========================================
  924. // Check time passed since today
  925. //==========================================
  926. long long DiffTimebWithNow(struct timeb ST)
  927. {
  928. //return milli-second
  929. struct timeb ET;
  930. long long StartTime,StopTime;
  931. ftime(&ET);
  932. StartTime=(long long)ST.time;
  933. StopTime=(long long)ET.time;
  934. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  935. }
  936. int getTimePassSinceToday(uint8_t gun_index)
  937. {
  938. int result = -1;
  939. static time_t lastTime[4];
  940. time_t t;
  941. struct tm *tmStartToday;
  942. struct timeb tbStartToday;
  943. t=time(NULL);
  944. if(difftime(t, lastTime[gun_index])>0)
  945. {
  946. tmStartToday=localtime(&t);
  947. tmStartToday->tm_hour = 0;
  948. tmStartToday->tm_min = 0;
  949. tmStartToday->tm_sec = 0;
  950. tbStartToday.time = mktime(tmStartToday);
  951. tbStartToday.millitm = 0;
  952. result = DiffTimebWithNow(tbStartToday)/1000;
  953. lastTime[gun_index] = t;
  954. }
  955. return result;
  956. }
  957. void getNowDatetime(uint8_t *data)
  958. {
  959. time_t t = time(NULL);
  960. struct tm tm = *localtime(&t);
  961. 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);
  962. }
  963. int syncDateTimeRTC(uint8_t *data)
  964. {
  965. struct ParsingResult
  966. {
  967. int result;
  968. int scanedElement;
  969. int year;
  970. int month;
  971. int mday;
  972. int hour;
  973. int min;
  974. int sec;
  975. int tz_hour;
  976. int tz_min;
  977. float minSec;
  978. }result;
  979. struct tm tmOrg;
  980. struct tm *tmTarget;
  981. struct timeb tbTarget;
  982. char buf[128];
  983. memset(&result, 0x00, sizeof(struct ParsingResult));
  984. result.result = PASS;
  985. if(strstr((char*)data, ".") != NULL)
  986. {
  987. // Original data with mini second
  988. if(strstr((char*)data, "Z") != NULL)
  989. {
  990. // Original data with Z
  991. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  992. &result.year,
  993. &result.month,
  994. &result.mday,
  995. &result.hour,
  996. &result.min,
  997. &result.sec,
  998. &result.minSec);
  999. }
  1000. else
  1001. {
  1002. // Original data without Z
  1003. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1004. &result.year,
  1005. &result.month,
  1006. &result.mday,
  1007. &result.hour,
  1008. &result.min,
  1009. &result.sec,
  1010. &result.minSec,
  1011. &result.tz_hour,
  1012. &result.tz_min);
  1013. }
  1014. }
  1015. else
  1016. {
  1017. // Original data without mini second
  1018. if(strstr((char*)data, "Z") != NULL)
  1019. {
  1020. // Original data with Z
  1021. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1022. &result.year,
  1023. &result.month,
  1024. &result.mday,
  1025. &result.hour,
  1026. &result.min,
  1027. &result.sec);
  1028. }
  1029. else
  1030. {
  1031. // Original data without Z
  1032. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1033. &result.year,
  1034. &result.month,
  1035. &result.mday,
  1036. &result.hour,
  1037. &result.min,
  1038. &result.sec,
  1039. &result.tz_hour,
  1040. &result.tz_min);
  1041. }
  1042. }
  1043. tmOrg.tm_year = result.year - 1900;
  1044. tmOrg.tm_mon = result.month - 1;
  1045. tmOrg.tm_mday = result.mday;
  1046. tmOrg.tm_hour = result.hour;
  1047. tmOrg.tm_min = result.min;
  1048. tmOrg.tm_sec = result.sec;
  1049. tmOrg.tm_gmtoff = 0;
  1050. tbTarget.time = mktime(&tmOrg);
  1051. tbTarget.timezone = 0;
  1052. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1053. tmTarget = gmtime(&tbTarget.time);
  1054. 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);
  1055. //DEBUG_INFO(" org date time: %s\n", data);
  1056. //DEBUG_INFO("parse date time: %s\n", buf);
  1057. system(buf);
  1058. system("/sbin/hwclock -w --systohc");
  1059. if(result.scanedElement < 6)
  1060. result.result = FAIL;
  1061. return result.result;
  1062. }
  1063. //==========================================
  1064. // GetCompositeSchedule logic related function
  1065. //==========================================
  1066. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1067. {
  1068. //return milli-second
  1069. unsigned int StartTime,StopTime;
  1070. StartTime=(unsigned int)ST.time;
  1071. StopTime=(unsigned int)ET.time;
  1072. return (StopTime-StartTime);
  1073. }
  1074. int DiffTimebWithNowSec(struct timeb ST)
  1075. {
  1076. //return milli-second
  1077. struct timeb ET;
  1078. unsigned int StartTime,StopTime;
  1079. ftime(&ET);
  1080. StartTime=(unsigned int)ST.time;
  1081. StopTime=(unsigned int)ET.time;
  1082. return (StopTime-StartTime);
  1083. }
  1084. int getStartStop(uint8_t *start, uint8_t *stop)
  1085. {
  1086. int result = -1;
  1087. struct tm tmStart;
  1088. struct timeb tbStart;
  1089. struct tm tmStop;
  1090. struct timeb tbStop;
  1091. 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) &&
  1092. (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))
  1093. {
  1094. //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);
  1095. //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);
  1096. tmStart.tm_year -= 1900;
  1097. tmStart.tm_mon -= 1;
  1098. tbStart.time = mktime(&tmStart);
  1099. tbStart.millitm = 0;
  1100. tmStop.tm_year -= 1900;
  1101. tmStop.tm_mon -= 1;
  1102. tbStop.time = mktime(&tmStop);
  1103. tbStop.millitm = 0;
  1104. result = DiffTimebSec(tbStart, tbStop);
  1105. //DEBUG_INFO("getStartStop(): %d\n", result);
  1106. }
  1107. else
  1108. {
  1109. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1110. }
  1111. return result;
  1112. }
  1113. int isOvertNow(uint8_t *start)
  1114. {
  1115. int result = NO;
  1116. struct ParsingResult
  1117. {
  1118. int result;
  1119. int scanedElement;
  1120. int year;
  1121. int month;
  1122. int mday;
  1123. int hour;
  1124. int min;
  1125. int sec;
  1126. int tz_hour;
  1127. int tz_min;
  1128. float minSec;
  1129. }parsingResult;
  1130. struct tm tmStart;
  1131. struct timeb tbStart;
  1132. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1133. if(strstr((char*)start, ".") != NULL)
  1134. {
  1135. // Original data with mini second
  1136. if(strstr((char*)start, "Z") != NULL)
  1137. {
  1138. // Original data with Z
  1139. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1140. &parsingResult.year,
  1141. &parsingResult.month,
  1142. &parsingResult.mday,
  1143. &parsingResult.hour,
  1144. &parsingResult.min,
  1145. &parsingResult.sec,
  1146. &parsingResult.minSec);
  1147. }
  1148. else
  1149. {
  1150. // Original data without Z
  1151. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1152. &parsingResult.year,
  1153. &parsingResult.month,
  1154. &parsingResult.mday,
  1155. &parsingResult.hour,
  1156. &parsingResult.min,
  1157. &parsingResult.sec,
  1158. &parsingResult.minSec,
  1159. &parsingResult.tz_hour,
  1160. &parsingResult.tz_min);
  1161. }
  1162. }
  1163. else
  1164. {
  1165. // Original data without mini second
  1166. if(strstr((char*)start, "Z") != NULL)
  1167. {
  1168. // Original data with Z
  1169. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1170. &parsingResult.year,
  1171. &parsingResult.month,
  1172. &parsingResult.mday,
  1173. &parsingResult.hour,
  1174. &parsingResult.min,
  1175. &parsingResult.sec);
  1176. }
  1177. else
  1178. {
  1179. // Original data without Z
  1180. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1181. &parsingResult.year,
  1182. &parsingResult.month,
  1183. &parsingResult.mday,
  1184. &parsingResult.hour,
  1185. &parsingResult.min,
  1186. &parsingResult.sec,
  1187. &parsingResult.tz_hour,
  1188. &parsingResult.tz_min);
  1189. }
  1190. }
  1191. if(parsingResult.scanedElement >= 6)
  1192. {
  1193. tmStart.tm_year = parsingResult.year - 1900;
  1194. tmStart.tm_mon = parsingResult.month - 1;
  1195. tmStart.tm_mday = parsingResult.mday;
  1196. tmStart.tm_hour = parsingResult.hour;
  1197. tmStart.tm_min = parsingResult.min;
  1198. tmStart.tm_sec = parsingResult.sec;
  1199. tmStart.tm_gmtoff = 0;
  1200. tbStart.time = mktime(&tmStart);
  1201. tbStart.timezone = 0;
  1202. tbStart.millitm = 0;
  1203. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1204. if(DiffTimebWithNowSec(tbStart) <= 0)
  1205. result = NO;
  1206. else
  1207. result = YES;
  1208. }
  1209. else
  1210. {
  1211. DEBUG_WARN("Start date parsing error.\n");
  1212. }
  1213. return result;
  1214. }
  1215. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1216. {
  1217. int result = -1;
  1218. struct tm tmStart;
  1219. struct timeb tbStart;
  1220. struct tm tmStop;
  1221. struct timeb tbStop;
  1222. 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) &&
  1223. (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))
  1224. {
  1225. tmStart.tm_year -= 1900;
  1226. tmStart.tm_mon -= 1;
  1227. tbStart.time = mktime(&tmStart);
  1228. tbStart.millitm = 0;
  1229. tmStop.tm_year -= 1900;
  1230. tmStop.tm_mon -= 1;
  1231. tbStop.time = mktime(&tmStop);
  1232. tbStop.millitm = 0;
  1233. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1234. }
  1235. return result;
  1236. }
  1237. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1238. {
  1239. FILE *fp;
  1240. char profileFileName[128];
  1241. char *line = NULL;
  1242. size_t len = 0;
  1243. time_t CurrentTime;
  1244. struct tm *tmComposite;
  1245. struct StructChargingProfile maxProfile;
  1246. uint8_t limitMax=0;
  1247. int compositePeriodIdx = 0;
  1248. CurrentTime = time(NULL);
  1249. tmComposite=localtime(&CurrentTime);
  1250. 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);
  1251. if(isUnitA)
  1252. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1253. else
  1254. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1255. compositeProfile->ChargingSchedule.Duration = durationReq;
  1256. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1257. {
  1258. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1259. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1260. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1261. }
  1262. compositeProfile->ChargingProfileId = 0;
  1263. compositeProfile->StackLevel = 99 ;
  1264. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1265. maxProfile.ChargingProfileId = -1;
  1266. maxProfile.ChargingSchedule.Duration = -1;
  1267. system("rm -f /tmp/*.json");
  1268. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1269. // Search max profile
  1270. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1271. if((access(profileFileName, F_OK))!=-1)
  1272. {
  1273. fp = fopen(profileFileName, "r");
  1274. while(getline(&line, &len, fp) != -1)
  1275. {
  1276. json_object *obj = NULL;
  1277. obj = json_tokener_parse(line);
  1278. if(is_error(obj))
  1279. {
  1280. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1281. }
  1282. else
  1283. {
  1284. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1285. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1286. )
  1287. {
  1288. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1289. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1290. )
  1291. {
  1292. struct tm tmFrom, tmTo;
  1293. struct timeb tbFrom, tbTo;
  1294. 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) &&
  1295. (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))
  1296. {
  1297. tmFrom.tm_year -= 1900;
  1298. tmFrom.tm_mon -= 1;
  1299. tbFrom.time = mktime(&tmFrom);
  1300. tmTo.tm_year -= 1900;
  1301. tmTo.tm_mon -= 1;
  1302. tbTo.time = mktime(&tmTo);
  1303. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1304. {
  1305. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1306. {
  1307. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1308. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1309. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1310. }
  1311. maxProfile.ChargingProfileId = -1;
  1312. maxProfile.StackLevel = -1;
  1313. if(maxProfile.ChargingProfileId == -1)
  1314. DEBUG_INFO("MaxProfile found.\n");
  1315. else
  1316. DEBUG_INFO("MaxProfile updated.\n");
  1317. // Required item
  1318. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1319. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1320. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1321. if(isUnitA)
  1322. {
  1323. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1324. 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++)
  1325. {
  1326. 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"));
  1327. 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?
  1328. 3:
  1329. 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")));
  1330. 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")));
  1331. }
  1332. }
  1333. else
  1334. {
  1335. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1336. 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++)
  1337. {
  1338. 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"));
  1339. 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?
  1340. 3:
  1341. 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")));
  1342. 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));
  1343. }
  1344. }
  1345. // Optional item
  1346. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1347. {
  1348. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1349. }
  1350. else
  1351. {
  1352. sprintf((char*)maxProfile.ValidFrom, " ");
  1353. }
  1354. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1355. {
  1356. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1357. }
  1358. else
  1359. {
  1360. sprintf((char*)maxProfile.ValidTo, " ");
  1361. }
  1362. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1363. {
  1364. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1365. }
  1366. else
  1367. {
  1368. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1369. }
  1370. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1371. {
  1372. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1373. }
  1374. else
  1375. {
  1376. maxProfile.TransactionId = -1;
  1377. }
  1378. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1379. {
  1380. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1381. }
  1382. else
  1383. {
  1384. maxProfile.ChargingSchedule.Duration = 86400;
  1385. }
  1386. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1387. {
  1388. 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")));
  1389. }
  1390. else
  1391. {
  1392. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1393. }
  1394. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1395. {
  1396. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1397. }
  1398. else
  1399. {
  1400. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1401. }
  1402. }
  1403. }
  1404. }
  1405. else
  1406. {
  1407. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1408. {
  1409. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1410. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1411. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1412. }
  1413. maxProfile.ChargingProfileId = -1;
  1414. maxProfile.StackLevel = -1;
  1415. if(maxProfile.ChargingProfileId == -1)
  1416. DEBUG_INFO("MaxProfile found.\n");
  1417. else
  1418. DEBUG_INFO("MaxProfile updated.\n");
  1419. // Required item
  1420. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1421. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1422. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1423. if(isUnitA)
  1424. {
  1425. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1426. 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++)
  1427. {
  1428. 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"));
  1429. 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?
  1430. 3:
  1431. 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")));
  1432. 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")));
  1433. }
  1434. }
  1435. else
  1436. {
  1437. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1438. 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++)
  1439. {
  1440. 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"));
  1441. 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?
  1442. 3:
  1443. 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")));
  1444. 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));
  1445. }
  1446. }
  1447. // Optional item
  1448. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1449. {
  1450. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1451. }
  1452. else
  1453. {
  1454. sprintf((char*)maxProfile.ValidFrom, " ");
  1455. }
  1456. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1457. {
  1458. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1459. }
  1460. else
  1461. {
  1462. sprintf((char*)maxProfile.ValidTo, " ");
  1463. }
  1464. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1465. {
  1466. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1467. }
  1468. else
  1469. {
  1470. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1471. }
  1472. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1473. {
  1474. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1475. }
  1476. else
  1477. {
  1478. maxProfile.TransactionId = -1;
  1479. }
  1480. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1481. {
  1482. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1483. }
  1484. else
  1485. {
  1486. maxProfile.ChargingSchedule.Duration = 86400;
  1487. }
  1488. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1489. {
  1490. 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")));
  1491. }
  1492. else
  1493. {
  1494. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1495. }
  1496. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1497. {
  1498. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1499. }
  1500. else
  1501. {
  1502. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1503. }
  1504. }
  1505. }
  1506. }
  1507. json_object_put(obj);
  1508. }
  1509. fclose(fp);
  1510. /*
  1511. if(maxProfile.ChargingProfileId !=-1)
  1512. {
  1513. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1514. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1515. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1516. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1517. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1518. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1519. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1520. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1521. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1522. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1523. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1524. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1525. {
  1526. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1527. {
  1528. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1529. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1530. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1531. }
  1532. }
  1533. }
  1534. else
  1535. DEBUG_INFO("MaxProfile not found.\n");
  1536. DEBUG_INFO("------------------------------------\n");*/
  1537. }
  1538. if(maxProfile.ChargingProfileId != -1)
  1539. {
  1540. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1541. {
  1542. if(maxProfile.ChargingSchedule.Duration != -1)
  1543. {
  1544. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1545. 0:
  1546. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1547. }
  1548. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1549. {
  1550. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1551. {
  1552. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1553. 0:
  1554. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1555. if(idxPeriod > 0)
  1556. {
  1557. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1558. {
  1559. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1560. }
  1561. }
  1562. }
  1563. }
  1564. }
  1565. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1566. {
  1567. if(maxProfile.ChargingSchedule.Duration != -1)
  1568. {
  1569. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1570. }
  1571. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1572. {
  1573. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1574. {
  1575. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1576. if(idxPeriod > 0)
  1577. {
  1578. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1579. {
  1580. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1581. }
  1582. }
  1583. }
  1584. }
  1585. }
  1586. else
  1587. {
  1588. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1589. {
  1590. if(maxProfile.ChargingSchedule.Duration != -1)
  1591. {
  1592. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1593. 0:
  1594. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1595. }
  1596. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1597. {
  1598. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1599. {
  1600. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1601. 0:
  1602. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1603. if(idxPeriod > 0)
  1604. {
  1605. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1606. {
  1607. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1608. }
  1609. }
  1610. }
  1611. }
  1612. }
  1613. else
  1614. {
  1615. if(maxProfile.ChargingSchedule.Duration != -1)
  1616. {
  1617. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1618. 0:
  1619. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1620. }
  1621. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1622. {
  1623. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1624. {
  1625. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1626. 0:
  1627. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1628. if(idxPeriod > 0)
  1629. {
  1630. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1631. {
  1632. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1633. }
  1634. }
  1635. }
  1636. }
  1637. }
  1638. }
  1639. /*
  1640. DEBUG_INFO("MaxProfile after align.\n");
  1641. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1642. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1643. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1644. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1645. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1646. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1647. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1648. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1649. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1650. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1651. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1652. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1653. {
  1654. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1655. {
  1656. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1657. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1658. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1659. }
  1660. }
  1661. DEBUG_INFO("------------------------------------\n");*/
  1662. }
  1663. // Find each profile period quantity
  1664. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1665. {
  1666. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1667. limitMax = idx+1;
  1668. }
  1669. if(maxProfile.ChargingProfileId != -1)
  1670. {
  1671. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1672. {
  1673. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1674. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1675. (maxProfile.ChargingSchedule.Duration > 0))
  1676. {
  1677. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1678. {
  1679. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1680. compositePeriodIdx++;
  1681. }
  1682. else
  1683. {
  1684. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1685. }
  1686. }
  1687. }
  1688. }
  1689. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1690. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1691. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1692. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1693. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1694. {
  1695. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1696. {
  1697. compositeProfile->ChargingProfileId = 1;
  1698. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1699. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1700. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1701. }
  1702. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1703. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1704. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1705. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1706. }
  1707. if(line)
  1708. free(line);
  1709. }
  1710. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1711. {
  1712. FILE *fp;
  1713. char profileFileName[128];
  1714. char *line = NULL;
  1715. size_t len = 0;
  1716. time_t CurrentTime;
  1717. struct tm *tmComposite;
  1718. struct StructChargingProfile maxProfile;
  1719. struct StructChargingProfile defaultTxProfile;
  1720. struct StructChargingProfile txProfile;
  1721. struct StructChargingSchedulePeriod tmpPeriod;
  1722. uint8_t limitMax=0;
  1723. uint8_t limitDef=0;
  1724. uint8_t limitTx=0;
  1725. int compositePeriodIdx = 0;
  1726. CurrentTime = time(NULL);
  1727. tmComposite=localtime(&CurrentTime);
  1728. 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);
  1729. if(isUnitA)
  1730. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1731. else
  1732. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1733. compositeProfile->ChargingSchedule.Duration = durationReq;
  1734. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1735. {
  1736. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1737. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1738. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1739. }
  1740. compositeProfile->ChargingProfileId = 0;
  1741. compositeProfile->StackLevel = 99 ;
  1742. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1743. maxProfile.ChargingProfileId = -1;
  1744. defaultTxProfile.ChargingProfileId = -1;
  1745. txProfile.ChargingProfileId = -1;
  1746. maxProfile.ChargingSchedule.Duration = -1;
  1747. defaultTxProfile.ChargingSchedule.Duration = -1;
  1748. txProfile.ChargingSchedule.Duration = -1;
  1749. system("rm -f /tmp/*.json");
  1750. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1751. /*
  1752. * Search valid charging profile
  1753. */
  1754. //DEBUG_INFO("====================================\n");
  1755. // Search tx profile
  1756. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1757. if((access(profileFileName, F_OK))!=-1)
  1758. {
  1759. fp = fopen(profileFileName, "r");
  1760. while(getline(&line, &len, fp) != -1)
  1761. {
  1762. json_object *obj = NULL;
  1763. obj = json_tokener_parse(line);
  1764. if(is_error(obj))
  1765. {
  1766. DEBUG_ERROR("Parse txProfile from file error.\n");
  1767. }
  1768. else
  1769. {
  1770. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1771. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1772. )
  1773. {
  1774. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1775. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1776. )
  1777. {
  1778. struct tm tmFrom, tmTo;
  1779. struct timeb tbFrom, tbTo;
  1780. 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) &&
  1781. (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))
  1782. {
  1783. tmFrom.tm_year -= 1900;
  1784. tmFrom.tm_mon -= 1;
  1785. tbFrom.time = mktime(&tmFrom);
  1786. tmTo.tm_year -= 1900;
  1787. tmTo.tm_mon -= 1;
  1788. tbTo.time = mktime(&tmTo);
  1789. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1790. {
  1791. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1792. {
  1793. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1794. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1795. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1796. }
  1797. txProfile.ChargingProfileId = -1;
  1798. txProfile.StackLevel = -1;
  1799. if(txProfile.ChargingProfileId == -1)
  1800. DEBUG_INFO("TxProfile found.\n");
  1801. else
  1802. DEBUG_INFO("TxProfile updated.\n");
  1803. // Required item
  1804. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1805. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1806. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1807. if(isUnitA)
  1808. {
  1809. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1810. 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++)
  1811. {
  1812. 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"));
  1813. 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?
  1814. 3:
  1815. 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")));
  1816. 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")));
  1817. }
  1818. }
  1819. else
  1820. {
  1821. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  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. 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"));
  1825. 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?
  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. 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));
  1829. }
  1830. }
  1831. // Optional item
  1832. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1833. {
  1834. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1835. }
  1836. else
  1837. {
  1838. sprintf((char*)txProfile.ValidFrom, " ");
  1839. }
  1840. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1841. {
  1842. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1843. }
  1844. else
  1845. {
  1846. sprintf((char*)txProfile.ValidTo, " ");
  1847. }
  1848. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1849. {
  1850. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1851. }
  1852. else
  1853. {
  1854. sprintf((char*)txProfile.RecurrencyKind, " ");
  1855. }
  1856. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1857. {
  1858. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1859. }
  1860. else
  1861. {
  1862. txProfile.TransactionId = -1;
  1863. }
  1864. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1865. {
  1866. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1867. }
  1868. else
  1869. {
  1870. txProfile.ChargingSchedule.Duration = 86400;
  1871. }
  1872. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1873. {
  1874. 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")));
  1875. }
  1876. else
  1877. {
  1878. 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));
  1879. }
  1880. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1881. {
  1882. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1883. }
  1884. else
  1885. {
  1886. txProfile.ChargingSchedule.MinChargingRate = -1;
  1887. }
  1888. }
  1889. }
  1890. }
  1891. else
  1892. {
  1893. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1894. {
  1895. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1896. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1897. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1898. }
  1899. txProfile.ChargingProfileId = -1;
  1900. txProfile.StackLevel = -1;
  1901. if(txProfile.ChargingProfileId == -1)
  1902. DEBUG_INFO("TxProfile found.\n");
  1903. else
  1904. DEBUG_INFO("TxProfile updated.\n");
  1905. // Required item
  1906. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1907. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1908. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1909. if(isUnitA)
  1910. {
  1911. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1912. 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++)
  1913. {
  1914. 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"));
  1915. 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?
  1916. 3:
  1917. 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")));
  1918. 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")));
  1919. }
  1920. }
  1921. else
  1922. {
  1923. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1924. 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++)
  1925. {
  1926. 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"));
  1927. 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?
  1928. 3:
  1929. 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")));
  1930. 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));
  1931. }
  1932. }
  1933. // Optional item
  1934. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1935. {
  1936. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1937. }
  1938. else
  1939. {
  1940. sprintf((char*)txProfile.ValidFrom, " ");
  1941. }
  1942. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1943. {
  1944. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1945. }
  1946. else
  1947. {
  1948. sprintf((char*)txProfile.ValidTo, " ");
  1949. }
  1950. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1951. {
  1952. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1953. }
  1954. else
  1955. {
  1956. sprintf((char*)txProfile.RecurrencyKind, " ");
  1957. }
  1958. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1959. {
  1960. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1961. }
  1962. else
  1963. {
  1964. txProfile.TransactionId = -1;
  1965. }
  1966. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1967. {
  1968. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1969. }
  1970. else
  1971. {
  1972. txProfile.ChargingSchedule.Duration = 86400;
  1973. }
  1974. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1975. {
  1976. 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")));
  1977. }
  1978. else
  1979. {
  1980. 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));
  1981. }
  1982. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1983. {
  1984. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1985. }
  1986. else
  1987. {
  1988. txProfile.ChargingSchedule.MinChargingRate = -1;
  1989. }
  1990. }
  1991. }
  1992. }
  1993. json_object_put(obj);
  1994. }
  1995. fclose(fp);
  1996. /*
  1997. if(txProfile.ChargingProfileId != -1)
  1998. {
  1999. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2000. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2001. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2002. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2003. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2004. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2005. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2006. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2007. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2008. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2009. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2010. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2011. {
  2012. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2013. {
  2014. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2015. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2016. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2017. }
  2018. }
  2019. }
  2020. else
  2021. DEBUG_INFO("TxProfile not found.\n");*/
  2022. }
  2023. // Search default tx profile
  2024. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2025. if((access(profileFileName, F_OK))==-1)
  2026. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2027. if((access(profileFileName, F_OK))!=-1)
  2028. {
  2029. fp = fopen(profileFileName, "r");
  2030. while(getline(&line, &len, fp) != -1)
  2031. {
  2032. json_object *obj = NULL;
  2033. obj = json_tokener_parse(line);
  2034. if(is_error(obj))
  2035. {
  2036. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2037. }
  2038. else
  2039. {
  2040. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2041. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2042. )
  2043. {
  2044. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2045. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2046. )
  2047. {
  2048. struct tm tmFrom, tmTo;
  2049. struct timeb tbFrom, tbTo;
  2050. 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) &&
  2051. (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))
  2052. {
  2053. tmFrom.tm_year -= 1900;
  2054. tmFrom.tm_mon -= 1;
  2055. tbFrom.time = mktime(&tmFrom);
  2056. tmTo.tm_year -= 1900;
  2057. tmTo.tm_mon -= 1;
  2058. tbTo.time = mktime(&tmTo);
  2059. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2060. {
  2061. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2062. {
  2063. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2064. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2065. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2066. }
  2067. defaultTxProfile.ChargingProfileId = -1;
  2068. defaultTxProfile.StackLevel = -1;
  2069. if(defaultTxProfile.ChargingProfileId == -1)
  2070. DEBUG_INFO("TxDefaultProfile found.\n");
  2071. else
  2072. DEBUG_INFO("TxDefaultProfile updated.\n");
  2073. // Required item
  2074. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2075. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2076. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2077. if(isUnitA)
  2078. {
  2079. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2080. 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++)
  2081. {
  2082. 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"));
  2083. 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?
  2084. 3:
  2085. 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")));
  2086. 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")));
  2087. }
  2088. }
  2089. else
  2090. {
  2091. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2092. 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++)
  2093. {
  2094. 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"));
  2095. 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?
  2096. 3:
  2097. 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")));
  2098. 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));
  2099. }
  2100. }
  2101. // Optional item
  2102. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2103. {
  2104. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2105. }
  2106. else
  2107. {
  2108. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2109. }
  2110. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2111. {
  2112. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2113. }
  2114. else
  2115. {
  2116. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2117. }
  2118. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2119. {
  2120. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2121. }
  2122. else
  2123. {
  2124. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2125. }
  2126. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2127. {
  2128. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2129. }
  2130. else
  2131. {
  2132. defaultTxProfile.TransactionId = -1;
  2133. }
  2134. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2135. {
  2136. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2137. }
  2138. else
  2139. {
  2140. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2141. }
  2142. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2143. {
  2144. 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")));
  2145. }
  2146. else
  2147. {
  2148. 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));
  2149. }
  2150. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2151. {
  2152. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2153. }
  2154. else
  2155. {
  2156. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2157. }
  2158. }
  2159. }
  2160. }
  2161. else
  2162. {
  2163. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2164. {
  2165. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2166. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2167. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2168. }
  2169. defaultTxProfile.ChargingProfileId = -1;
  2170. defaultTxProfile.StackLevel = -1;
  2171. if(defaultTxProfile.ChargingProfileId == -1)
  2172. DEBUG_INFO("TxDefaultProfile found.\n");
  2173. else
  2174. DEBUG_INFO("TxDefaultProfile updated.\n");
  2175. // Required item
  2176. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2177. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2178. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2179. if(isUnitA)
  2180. {
  2181. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2182. 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++)
  2183. {
  2184. 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"));
  2185. 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?
  2186. 3:
  2187. 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")));
  2188. 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")));
  2189. }
  2190. }
  2191. else
  2192. {
  2193. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2194. 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++)
  2195. {
  2196. 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"));
  2197. 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?
  2198. 3:
  2199. 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")));
  2200. 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));
  2201. }
  2202. }
  2203. // Optional item
  2204. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2205. {
  2206. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2207. }
  2208. else
  2209. {
  2210. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2211. }
  2212. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2213. {
  2214. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2215. }
  2216. else
  2217. {
  2218. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2219. }
  2220. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2221. {
  2222. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2223. }
  2224. else
  2225. {
  2226. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2227. }
  2228. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2229. {
  2230. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2231. }
  2232. else
  2233. {
  2234. defaultTxProfile.TransactionId = -1;
  2235. }
  2236. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2237. {
  2238. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2239. }
  2240. else
  2241. {
  2242. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2243. }
  2244. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2245. {
  2246. 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")));
  2247. }
  2248. else
  2249. {
  2250. 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));
  2251. }
  2252. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2253. {
  2254. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2255. }
  2256. else
  2257. {
  2258. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2259. }
  2260. }
  2261. }
  2262. }
  2263. json_object_put(obj);
  2264. }
  2265. fclose(fp);
  2266. /*
  2267. if(defaultTxProfile.ChargingProfileId != -1)
  2268. {
  2269. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2270. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2271. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2272. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2273. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2274. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2275. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2276. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2277. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2278. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2279. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2280. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2281. {
  2282. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2283. {
  2284. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2285. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2286. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2287. }
  2288. }
  2289. }
  2290. else
  2291. DEBUG_INFO("TxDefaultProfile not found.\n");
  2292. DEBUG_INFO("------------------------------------\n");*/
  2293. }
  2294. // Search max profile
  2295. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2296. if((access(profileFileName, F_OK))!=-1)
  2297. {
  2298. fp = fopen(profileFileName, "r");
  2299. while(getline(&line, &len, fp) != -1)
  2300. {
  2301. json_object *obj = NULL;
  2302. obj = json_tokener_parse(line);
  2303. if(is_error(obj))
  2304. {
  2305. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2306. }
  2307. else
  2308. {
  2309. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2310. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2311. )
  2312. {
  2313. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2314. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2315. )
  2316. {
  2317. struct tm tmFrom, tmTo;
  2318. struct timeb tbFrom, tbTo;
  2319. 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) &&
  2320. (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))
  2321. {
  2322. tmFrom.tm_year -= 1900;
  2323. tmFrom.tm_mon -= 1;
  2324. tbFrom.time = mktime(&tmFrom);
  2325. tmTo.tm_year -= 1900;
  2326. tmTo.tm_mon -= 1;
  2327. tbTo.time = mktime(&tmTo);
  2328. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2329. {
  2330. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2331. {
  2332. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2333. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2334. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2335. }
  2336. maxProfile.ChargingProfileId = -1;
  2337. maxProfile.StackLevel = -1;
  2338. if(maxProfile.ChargingProfileId == -1)
  2339. DEBUG_INFO("MaxProfile found.\n");
  2340. else
  2341. DEBUG_INFO("MaxProfile updated.\n");
  2342. // Required item
  2343. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2344. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2345. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2346. if(isUnitA)
  2347. {
  2348. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2349. 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++)
  2350. {
  2351. 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"));
  2352. 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?
  2353. 3:
  2354. 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")));
  2355. 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")));
  2356. }
  2357. }
  2358. else
  2359. {
  2360. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2361. 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++)
  2362. {
  2363. 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"));
  2364. 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?
  2365. 3:
  2366. 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")));
  2367. 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));
  2368. }
  2369. }
  2370. // Optional item
  2371. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2372. {
  2373. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2374. }
  2375. else
  2376. {
  2377. sprintf((char*)maxProfile.ValidFrom, " ");
  2378. }
  2379. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2380. {
  2381. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2382. }
  2383. else
  2384. {
  2385. sprintf((char*)maxProfile.ValidTo, " ");
  2386. }
  2387. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2388. {
  2389. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2390. }
  2391. else
  2392. {
  2393. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2394. }
  2395. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2396. {
  2397. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2398. }
  2399. else
  2400. {
  2401. maxProfile.TransactionId = -1;
  2402. }
  2403. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2404. {
  2405. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2406. }
  2407. else
  2408. {
  2409. maxProfile.ChargingSchedule.Duration = 86400;
  2410. }
  2411. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2412. {
  2413. 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")));
  2414. }
  2415. else
  2416. {
  2417. 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));
  2418. }
  2419. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2420. {
  2421. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2422. }
  2423. else
  2424. {
  2425. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2426. }
  2427. }
  2428. }
  2429. }
  2430. else
  2431. {
  2432. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2433. {
  2434. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2435. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2436. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2437. }
  2438. maxProfile.ChargingProfileId = -1;
  2439. maxProfile.StackLevel = -1;
  2440. if(maxProfile.ChargingProfileId == -1)
  2441. DEBUG_INFO("MaxProfile found.\n");
  2442. else
  2443. DEBUG_INFO("MaxProfile updated.\n");
  2444. // Required item
  2445. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2446. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2447. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2448. if(isUnitA)
  2449. {
  2450. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2451. 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++)
  2452. {
  2453. 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"));
  2454. 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?
  2455. 3:
  2456. 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")));
  2457. 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")));
  2458. }
  2459. }
  2460. else
  2461. {
  2462. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2463. 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++)
  2464. {
  2465. 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"));
  2466. 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?
  2467. 3:
  2468. 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")));
  2469. 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));
  2470. }
  2471. }
  2472. // Optional item
  2473. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2474. {
  2475. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2476. }
  2477. else
  2478. {
  2479. sprintf((char*)maxProfile.ValidFrom, " ");
  2480. }
  2481. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2482. {
  2483. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2484. }
  2485. else
  2486. {
  2487. sprintf((char*)maxProfile.ValidTo, " ");
  2488. }
  2489. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2490. {
  2491. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2492. }
  2493. else
  2494. {
  2495. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2496. }
  2497. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2498. {
  2499. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2500. }
  2501. else
  2502. {
  2503. maxProfile.TransactionId = -1;
  2504. }
  2505. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2506. {
  2507. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2508. }
  2509. else
  2510. {
  2511. maxProfile.ChargingSchedule.Duration = 86400;
  2512. }
  2513. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2514. {
  2515. 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")));
  2516. }
  2517. else
  2518. {
  2519. 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));
  2520. }
  2521. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2522. {
  2523. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2524. }
  2525. else
  2526. {
  2527. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2528. }
  2529. }
  2530. }
  2531. }
  2532. json_object_put(obj);
  2533. }
  2534. fclose(fp);
  2535. /*
  2536. if(maxProfile.ChargingProfileId !=-1)
  2537. {
  2538. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2539. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2540. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2541. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2542. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2543. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2544. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2545. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2546. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2547. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2548. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2549. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2550. {
  2551. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2552. {
  2553. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2554. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2555. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2556. }
  2557. }
  2558. }
  2559. else
  2560. DEBUG_INFO("MaxProfile not found.\n");
  2561. DEBUG_INFO("------------------------------------\n");*/
  2562. }
  2563. /*
  2564. * Align found profile start schedule & periods
  2565. */
  2566. //DEBUG_INFO("====================================\n");
  2567. /*
  2568. // For local test usage, force modify found profile start schedule info
  2569. 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);
  2570. 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);
  2571. 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);
  2572. */
  2573. if(txProfile.ChargingProfileId != -1)
  2574. {
  2575. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2576. {
  2577. if(txProfile.ChargingSchedule.Duration != -1)
  2578. {
  2579. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2580. 0:
  2581. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2582. }
  2583. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2584. {
  2585. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2586. {
  2587. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2588. 0:
  2589. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2590. if(idxPeriod > 0)
  2591. {
  2592. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2593. {
  2594. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2595. }
  2596. }
  2597. }
  2598. }
  2599. }
  2600. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2601. {
  2602. if(txProfile.ChargingSchedule.Duration != -1)
  2603. {
  2604. 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?
  2605. 0:
  2606. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2607. }
  2608. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2609. {
  2610. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2611. {
  2612. 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?
  2613. 0:
  2614. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2615. if(idxPeriod > 0)
  2616. {
  2617. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2618. {
  2619. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2620. }
  2621. }
  2622. }
  2623. }
  2624. }
  2625. else
  2626. {
  2627. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2628. {
  2629. if(txProfile.ChargingSchedule.Duration != -1)
  2630. {
  2631. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2632. 0:
  2633. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2634. }
  2635. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2636. {
  2637. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2638. {
  2639. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2640. 0:
  2641. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2642. if(idxPeriod > 0)
  2643. {
  2644. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2645. {
  2646. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2647. }
  2648. }
  2649. }
  2650. }
  2651. }
  2652. else
  2653. {
  2654. if(txProfile.ChargingSchedule.Duration != -1)
  2655. {
  2656. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2657. 0:
  2658. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2659. }
  2660. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2661. {
  2662. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2663. {
  2664. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2665. 0:
  2666. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2667. if(idxPeriod > 0)
  2668. {
  2669. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2670. {
  2671. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2672. }
  2673. }
  2674. }
  2675. }
  2676. }
  2677. }
  2678. /*
  2679. DEBUG_INFO("txProfile after align.\n");
  2680. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2681. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2682. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2683. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2684. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2685. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2686. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2687. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2688. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2689. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2690. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2691. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2692. {
  2693. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2694. {
  2695. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2696. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2697. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2698. }
  2699. }*/
  2700. }
  2701. if(defaultTxProfile.ChargingProfileId != -1)
  2702. {
  2703. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2704. {
  2705. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2706. {
  2707. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2708. 0:
  2709. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2710. }
  2711. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2712. {
  2713. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2714. {
  2715. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2716. 0:
  2717. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2718. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2719. {
  2720. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2721. }
  2722. if(idxPeriod > 0)
  2723. {
  2724. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2725. {
  2726. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2727. }
  2728. }
  2729. }
  2730. }
  2731. }
  2732. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2733. {
  2734. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2735. {
  2736. 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?
  2737. 0:
  2738. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2739. }
  2740. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2741. {
  2742. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2743. {
  2744. 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?
  2745. 0:
  2746. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2747. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2748. {
  2749. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2750. }
  2751. if(idxPeriod > 0)
  2752. {
  2753. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2754. {
  2755. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2756. }
  2757. }
  2758. }
  2759. }
  2760. }
  2761. else
  2762. {
  2763. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2764. {
  2765. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2766. {
  2767. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2768. 0:
  2769. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2770. }
  2771. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2772. {
  2773. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2774. {
  2775. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2776. 0:
  2777. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2778. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2779. {
  2780. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2781. }
  2782. if(idxPeriod > 0)
  2783. {
  2784. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2785. {
  2786. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2787. }
  2788. }
  2789. }
  2790. }
  2791. }
  2792. else
  2793. {
  2794. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2795. {
  2796. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2797. 0:
  2798. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2799. }
  2800. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2801. {
  2802. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2803. {
  2804. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2805. 0:
  2806. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2807. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2808. {
  2809. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2810. }
  2811. if(idxPeriod > 0)
  2812. {
  2813. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2814. {
  2815. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2816. }
  2817. }
  2818. }
  2819. }
  2820. }
  2821. }
  2822. /*
  2823. DEBUG_INFO("defaultTxProfile after align.\n");
  2824. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2825. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2826. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2827. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2828. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2829. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2830. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2831. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2832. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2833. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2834. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2835. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2836. {
  2837. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2838. {
  2839. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2840. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2841. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2842. }
  2843. }
  2844. DEBUG_INFO("------------------------------------\n");*/
  2845. }
  2846. if(maxProfile.ChargingProfileId != -1)
  2847. {
  2848. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2849. {
  2850. if(maxProfile.ChargingSchedule.Duration != -1)
  2851. {
  2852. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2853. 0:
  2854. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2855. }
  2856. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2857. {
  2858. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2859. {
  2860. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2861. 0:
  2862. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2863. if(idxPeriod > 0)
  2864. {
  2865. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2866. {
  2867. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2868. }
  2869. }
  2870. }
  2871. }
  2872. }
  2873. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2874. {
  2875. if(maxProfile.ChargingSchedule.Duration != -1)
  2876. {
  2877. 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?
  2878. 0:
  2879. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2880. }
  2881. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2882. {
  2883. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2884. {
  2885. 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?
  2886. 0:
  2887. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2888. if(idxPeriod > 0)
  2889. {
  2890. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2891. {
  2892. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2893. }
  2894. }
  2895. }
  2896. }
  2897. }
  2898. else
  2899. {
  2900. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2901. {
  2902. if(maxProfile.ChargingSchedule.Duration != -1)
  2903. {
  2904. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2905. 0:
  2906. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2907. }
  2908. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2909. {
  2910. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2911. {
  2912. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2913. 0:
  2914. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2915. if(idxPeriod > 0)
  2916. {
  2917. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2918. {
  2919. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2920. }
  2921. }
  2922. }
  2923. }
  2924. }
  2925. else
  2926. {
  2927. if(maxProfile.ChargingSchedule.Duration != -1)
  2928. {
  2929. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2930. 0:
  2931. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2932. }
  2933. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2934. {
  2935. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2936. {
  2937. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2938. 0:
  2939. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2940. if(idxPeriod > 0)
  2941. {
  2942. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2943. {
  2944. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2945. }
  2946. }
  2947. }
  2948. }
  2949. }
  2950. }
  2951. /*
  2952. DEBUG_INFO("MaxProfile after align.\n");
  2953. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2954. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2955. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2956. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2957. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2958. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2959. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2960. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2961. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2962. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2963. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2964. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2965. {
  2966. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2967. {
  2968. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2969. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2970. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2971. }
  2972. }
  2973. DEBUG_INFO("------------------------------------\n");*/
  2974. }
  2975. /*
  2976. * Merge to conposite schedule
  2977. */
  2978. //DEBUG_INFO("====================================\n");
  2979. // Find each profile period quantity
  2980. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2981. {
  2982. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2983. limitMax = idx+1;
  2984. }
  2985. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2986. {
  2987. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2988. limitDef = idx+1;
  2989. }
  2990. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2991. {
  2992. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2993. limitTx = idx+1;
  2994. }
  2995. // TxProfile found, composite schedule based on it
  2996. if(txProfile.ChargingProfileId != -1)
  2997. {
  2998. compositeProfile->ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  2999. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3000. {
  3001. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3002. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3003. (txProfile.ChargingSchedule.Duration > 0))
  3004. {
  3005. if(maxProfile.ChargingProfileId != -1)
  3006. {
  3007. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3008. {
  3009. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3010. {
  3011. if((maxProfile.ChargingSchedule.Duration > 0))
  3012. {
  3013. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3014. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3015. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3016. }
  3017. else
  3018. {
  3019. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3020. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3021. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3022. }
  3023. }
  3024. if(idxMaxPeriod == (limitMax-1))
  3025. {
  3026. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3027. {
  3028. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3029. {
  3030. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3031. compositePeriodIdx++;
  3032. }
  3033. else
  3034. {
  3035. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3036. }
  3037. }
  3038. }
  3039. }
  3040. }
  3041. else
  3042. {
  3043. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3044. {
  3045. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3046. compositePeriodIdx++;
  3047. }
  3048. else
  3049. {
  3050. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3051. }
  3052. }
  3053. }
  3054. if(idxTxPeriod == (limitTx-1))
  3055. {
  3056. if(defaultTxProfile.ChargingProfileId != -1)
  3057. {
  3058. compositeProfile->ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile->ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile->ChargingSchedule.Duration;
  3059. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3060. {
  3061. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3062. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3063. (defaultTxProfile.ChargingSchedule.Duration>0))
  3064. {
  3065. if(maxProfile.ChargingProfileId != -1)
  3066. {
  3067. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3068. {
  3069. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3070. {
  3071. if((maxProfile.ChargingSchedule.Duration > 0))
  3072. {
  3073. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3074. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3075. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3076. }
  3077. else
  3078. {
  3079. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3080. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3081. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3082. }
  3083. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3084. {
  3085. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3086. {
  3087. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3088. compositePeriodIdx++;
  3089. }
  3090. else
  3091. {
  3092. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3093. }
  3094. }
  3095. // Delete duplicate period
  3096. if(compositePeriodIdx > 1)
  3097. {
  3098. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3099. {
  3100. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3101. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3102. compositePeriodIdx -= 1;
  3103. }
  3104. }
  3105. }
  3106. else
  3107. {
  3108. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3109. {
  3110. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3111. compositePeriodIdx++;
  3112. }
  3113. else
  3114. {
  3115. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3116. }
  3117. break;
  3118. }
  3119. }
  3120. }
  3121. else
  3122. {
  3123. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3124. {
  3125. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3126. compositePeriodIdx++;
  3127. }
  3128. else
  3129. {
  3130. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3131. }
  3132. }
  3133. }
  3134. }
  3135. }
  3136. }
  3137. }
  3138. }
  3139. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3140. else if(defaultTxProfile.ChargingProfileId != -1)
  3141. {
  3142. compositeProfile->ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3143. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3144. {
  3145. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3146. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3147. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3148. {
  3149. if(maxProfile.ChargingProfileId != -1)
  3150. {
  3151. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3152. {
  3153. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3154. {
  3155. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3156. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3157. if((maxProfile.ChargingSchedule.Duration > 0))
  3158. {
  3159. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3160. }
  3161. else
  3162. {
  3163. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3164. }
  3165. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3166. {
  3167. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3168. {
  3169. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3170. compositePeriodIdx++;
  3171. }
  3172. else
  3173. {
  3174. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3175. }
  3176. }
  3177. // Delete duplicate period
  3178. if(compositePeriodIdx > 1)
  3179. {
  3180. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3181. {
  3182. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3183. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3184. compositePeriodIdx -= 1;
  3185. }
  3186. }
  3187. }
  3188. else
  3189. {
  3190. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3191. {
  3192. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3193. compositePeriodIdx++;
  3194. }
  3195. else
  3196. {
  3197. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3198. }
  3199. break;
  3200. }
  3201. }
  3202. }
  3203. else
  3204. {
  3205. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3206. {
  3207. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3208. compositePeriodIdx++;
  3209. }
  3210. else
  3211. {
  3212. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3213. }
  3214. }
  3215. }
  3216. }
  3217. }
  3218. // Fill other period by MaxProfile
  3219. if(maxProfile.ChargingProfileId != -1)
  3220. {
  3221. if(compositePeriodIdx==0)
  3222. {
  3223. compositeProfile->ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3224. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3225. {
  3226. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3227. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3228. (maxProfile.ChargingSchedule.Duration > 0))
  3229. {
  3230. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3231. {
  3232. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3233. compositePeriodIdx++;
  3234. }
  3235. else
  3236. {
  3237. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3238. }
  3239. }
  3240. }
  3241. }
  3242. else
  3243. {
  3244. int lastCompositePeriodIdx = compositePeriodIdx;
  3245. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3246. {
  3247. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3248. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3249. (maxProfile.ChargingSchedule.Duration > 0))
  3250. {
  3251. if((maxProfile.ChargingSchedule.Duration >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3252. {
  3253. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3254. {
  3255. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3256. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3257. tmpPeriod.Limit = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3258. }
  3259. else
  3260. {
  3261. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3262. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3263. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3264. }
  3265. }
  3266. if(tmpPeriod.Limit != -1)
  3267. {
  3268. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3269. {
  3270. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3271. {
  3272. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3273. compositePeriodIdx++;
  3274. }
  3275. else
  3276. {
  3277. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3278. }
  3279. }
  3280. // Delete duplicate period
  3281. if(compositePeriodIdx > 1)
  3282. {
  3283. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3284. {
  3285. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3286. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3287. compositePeriodIdx -= 1;
  3288. }
  3289. }
  3290. }
  3291. }
  3292. }
  3293. }
  3294. }
  3295. compositeProfile->ChargingSchedule.Duration = durationReq;
  3296. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3297. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3298. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3299. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3300. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3301. {
  3302. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3303. {
  3304. compositeProfile->ChargingProfileId = 1;
  3305. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3306. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3307. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3308. }
  3309. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3310. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3311. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3312. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3313. }
  3314. if(line)
  3315. free(line);
  3316. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3317. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3318. }
  3319. //==========================================
  3320. // Init all share memory
  3321. //==========================================
  3322. int InitShareMemory()
  3323. {
  3324. int result = PASS;
  3325. int MeterSMId;
  3326. //creat ShmSysConfigAndInfo
  3327. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3328. {
  3329. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3330. result = FAIL;
  3331. }
  3332. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3333. {
  3334. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3335. result = FAIL;
  3336. }
  3337. else
  3338. {}
  3339. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3340. {
  3341. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3342. result = FAIL;
  3343. }
  3344. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3345. {
  3346. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3347. result = FAIL;
  3348. }
  3349. else
  3350. {}
  3351. //creat ShmPsuData
  3352. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3353. {
  3354. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3355. result = FAIL;
  3356. }
  3357. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3358. {
  3359. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3360. result = FAIL;
  3361. }
  3362. else
  3363. {}
  3364. //creat ShmOCPP16Data
  3365. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3366. {
  3367. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3368. result = FAIL;
  3369. }
  3370. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3371. {
  3372. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3373. result = FAIL;
  3374. }
  3375. else
  3376. {}
  3377. /****************************** For Initial Settings************************************************/
  3378. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3379. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3380. // allocate Configuration memory address
  3381. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3382. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3383. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3384. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3385. //offline MeterValue Interval
  3386. TempMeterValueInterval = 0;
  3387. return result;
  3388. }
  3389. int ProcessShareMemory()
  3390. {
  3391. int result = PASS;
  3392. ParsingRatedCur modelnameInfo={0};
  3393. if(InitShareMemory() == FAIL)
  3394. {
  3395. DEBUG_ERROR("InitShareMemory NG\n");
  3396. if(ShmStatusCodeData!=NULL)
  3397. {
  3398. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3399. }
  3400. result = FAIL;
  3401. }
  3402. // Model name parsing
  3403. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3404. {
  3405. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3406. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3407. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3408. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3409. ) // 'D' means DC
  3410. {
  3411. // DO series
  3412. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3413. {
  3414. SystemInitial += 1;
  3415. gunTotalNumber += 1;
  3416. gunType[gun_index] = GUN_TYPE_DO;
  3417. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3418. {
  3419. case Gun_Type_Chademo:
  3420. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3421. break;
  3422. case Gun_Type_CCS_2:
  3423. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3424. break;
  3425. case Gun_Type_GB:
  3426. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3427. break;
  3428. case Gun_Type_AC:
  3429. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3430. break;
  3431. default:
  3432. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3433. break;
  3434. }
  3435. }
  3436. }
  3437. else
  3438. {
  3439. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3440. {
  3441. SystemInitial += 1;
  3442. gunTotalNumber += 1;
  3443. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3444. {
  3445. case Gun_Type_Chademo:
  3446. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3447. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3448. break;
  3449. case Gun_Type_CCS_2:
  3450. gunType[gun_index] = GUN_TYPE_CCS;
  3451. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3452. break;
  3453. case Gun_Type_GB:
  3454. gunType[gun_index] = GUN_TYPE_GBT;
  3455. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3456. break;
  3457. case Gun_Type_AC:
  3458. gunType[gun_index] = GUN_TYPE_AC;
  3459. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3460. break;
  3461. default:
  3462. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3463. break;
  3464. }
  3465. }
  3466. }
  3467. }
  3468. else
  3469. {
  3470. DEBUG_ERROR("Model name parsing fail.\n");
  3471. result = FAIL;
  3472. }
  3473. if(result != PASS)sleep(5);
  3474. return result;
  3475. }
  3476. void checkRemoteStart(uint8_t connectorIdInt)
  3477. {
  3478. uint8_t tempIndex;
  3479. int result = PASS;
  3480. char cmdBuf[512];
  3481. //check Transaction active
  3482. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3483. {
  3484. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3485. {
  3486. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3487. }
  3488. else
  3489. {
  3490. tempIndex = connectorIdInt -1;
  3491. }
  3492. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3493. {
  3494. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3495. {
  3496. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3497. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3498. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3499. {
  3500. //Reserved
  3501. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3502. }
  3503. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3504. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3505. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3506. {
  3507. //Reserved
  3508. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3509. result = FAIL;
  3510. goto end;
  3511. }
  3512. else
  3513. {
  3514. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3515. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3516. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3517. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3518. {
  3519. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  3520. result = FAIL;
  3521. goto end;
  3522. }
  3523. }//END FOR ELSE
  3524. }
  3525. }// END FOR CHAdeMO_QUANTITY
  3526. }
  3527. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3528. {
  3529. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3530. {
  3531. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3532. }
  3533. else
  3534. {
  3535. tempIndex = connectorIdInt -1;
  3536. }
  3537. for (int index = 0; index < CCS_QUANTITY; index++)
  3538. {
  3539. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3540. {
  3541. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3542. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3543. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3544. {
  3545. //Reserved
  3546. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3547. }
  3548. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3549. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3550. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3551. {
  3552. //Reserved
  3553. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3554. result = FAIL;
  3555. goto end;
  3556. }
  3557. else
  3558. {
  3559. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3560. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3561. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3562. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3563. {
  3564. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3565. result = FAIL;
  3566. goto end;
  3567. }
  3568. }// END FOR ELSE
  3569. }
  3570. }// END FOR CCS_QUANTITY
  3571. }
  3572. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3573. {
  3574. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3575. {
  3576. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3577. }
  3578. else
  3579. {
  3580. tempIndex = connectorIdInt -1;
  3581. }
  3582. for (int index = 0; index < GB_QUANTITY; index++)
  3583. {
  3584. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3585. {
  3586. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3587. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3588. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3589. {
  3590. //Reserved
  3591. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3592. }
  3593. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3594. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3595. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3596. {
  3597. //Reserved
  3598. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3599. result = FAIL;
  3600. goto end;
  3601. }
  3602. else
  3603. {
  3604. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3605. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3606. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3607. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3608. {
  3609. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  3610. result = FAIL;
  3611. goto end;
  3612. }
  3613. }// END FOR ELSE
  3614. }
  3615. } // END FOR GB_QUANTITY
  3616. }
  3617. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3618. {
  3619. tempIndex = connectorIdInt -1;
  3620. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3621. {
  3622. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3623. {
  3624. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3625. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3626. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3627. {
  3628. //Reserved
  3629. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3630. }
  3631. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3632. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3633. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3634. {
  3635. //Reserved
  3636. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3637. result = FAIL;
  3638. goto end;
  3639. }
  3640. else
  3641. {
  3642. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3643. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3644. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3645. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3646. {
  3647. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  3648. result = FAIL;
  3649. goto end;
  3650. }
  3651. }// END FOR ELSE
  3652. }
  3653. } // END FOR GB_QUANTITY
  3654. }
  3655. else
  3656. {
  3657. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3658. {
  3659. tempIndex = 2;
  3660. }
  3661. else
  3662. {
  3663. tempIndex = connectorIdInt -1;
  3664. }
  3665. for (int index = 0; index < AC_QUANTITY; index++)
  3666. {
  3667. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3668. {
  3669. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3670. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3671. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3672. {
  3673. //Reserved
  3674. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3675. }
  3676. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3677. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3678. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3679. {
  3680. //Reserved
  3681. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3682. result = FAIL;
  3683. goto end;
  3684. }
  3685. else
  3686. {
  3687. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3688. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3689. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3690. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3691. {
  3692. DEBUG_WARN("AC connector not allow start cause busy.\n");
  3693. result = FAIL;
  3694. goto end;
  3695. }
  3696. }//END FOR ELSE
  3697. }
  3698. }// END FOR AC_QUANTITY
  3699. }
  3700. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3701. {
  3702. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3703. {
  3704. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  3705. {
  3706. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3707. system(cmdBuf);
  3708. }
  3709. }
  3710. else
  3711. {
  3712. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3713. result = FAIL;
  3714. }
  3715. }
  3716. end:
  3717. if(result == PASS)
  3718. {
  3719. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3720. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3721. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3722. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3723. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3724. }
  3725. }
  3726. void CheckSystemValue(void)
  3727. {
  3728. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  3729. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  3730. char filenmae[100]={0};
  3731. char str[100]={0};
  3732. int tempIndex = 0;
  3733. //===============================
  3734. // send Heartbeat
  3735. //===============================
  3736. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3737. {
  3738. //parameter for test
  3739. sendHeartbeatRequest(0);
  3740. //==============================================
  3741. // Reset Waiting Time
  3742. //==============================================
  3743. HeartBeatWithNOResponse += 1;
  3744. }
  3745. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3746. {
  3747. //==========================================
  3748. // Check remote start without connector id
  3749. //==========================================
  3750. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  3751. {
  3752. int connectorIdInt = -1;
  3753. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  3754. {
  3755. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  3756. {
  3757. connectorIdInt = (gun_index+1);
  3758. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  3759. checkRemoteStart(connectorIdInt);
  3760. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  3761. break;
  3762. }
  3763. }
  3764. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  3765. {
  3766. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  3767. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  3768. }
  3769. }
  3770. //==========================================
  3771. // csu trigger DataTransferReq
  3772. //==========================================
  3773. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  3774. {
  3775. sendDataTransferRequest(gun_index);
  3776. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  3777. }
  3778. //==========================================
  3779. // CSU Trigger Authorize Request
  3780. //==========================================
  3781. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3782. {
  3783. sendAuthorizeRequest(0);
  3784. authorizeRetryTimes = authorizeRetryTimes + 1;
  3785. if(authorizeRetryTimes < 3)
  3786. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3787. }
  3788. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3789. {
  3790. authorizeRetryTimes = 0;
  3791. SetOcppConnStatus(FALSE);
  3792. server_sign = FALSE;
  3793. }
  3794. 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))
  3795. {
  3796. sendAuthorizeRequest(0);
  3797. }
  3798. //==========================================
  3799. // Charger start transaction
  3800. //==========================================
  3801. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3802. {
  3803. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3804. sendStartTransactionRequest(gun_index);
  3805. refreshStartTimer(&clientTime.StartTransaction);
  3806. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  3807. storeTempStopTransaction(gun_index);
  3808. }
  3809. //==========================================
  3810. // Charger stop transaction
  3811. //==========================================
  3812. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3813. {
  3814. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3815. sendStopTransactionRequest(gun_index);
  3816. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  3817. refreshStartTimer(&clientTime.StopTransaction);
  3818. }
  3819. //==========================================
  3820. // Charger status report
  3821. //==========================================
  3822. //--- Check Mode Change ---//
  3823. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3824. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3825. {
  3826. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3827. {
  3828. tempIndex = ((gun_index==2) ? 1: 0);
  3829. }
  3830. else
  3831. {
  3832. tempIndex = gun_index;
  3833. }
  3834. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3835. {
  3836. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3837. {
  3838. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3839. {
  3840. // Sent unplug message for California pricing logic
  3841. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3842. {
  3843. uint8_t ts[20];
  3844. getNowDatetime(ts);
  3845. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3846. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3847. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3848. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3849. }
  3850. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3851. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3852. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3853. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3854. {
  3855. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3856. if((access(filenmae,F_OK))!=-1)
  3857. {
  3858. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3859. sprintf(str,"rm -f %s",filenmae);
  3860. system(str);
  3861. }
  3862. }
  3863. }
  3864. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3865. #if 1 // for TempStopTransaction
  3866. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3867. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3868. {
  3869. checkTempStopTransaction(gun_index);
  3870. }
  3871. #endif
  3872. }
  3873. }
  3874. }
  3875. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3876. {
  3877. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3878. {
  3879. tempIndex = ((gun_index==2) ? 1: 0);
  3880. }
  3881. else
  3882. {
  3883. tempIndex = gun_index;
  3884. }
  3885. for (int index = 0; index < CCS_QUANTITY; index++)
  3886. {
  3887. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3888. {
  3889. 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]*/ )
  3890. {
  3891. // Sent unplug message for California pricing logic
  3892. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3893. {
  3894. uint8_t ts[20];
  3895. getNowDatetime(ts);
  3896. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3897. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3898. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3899. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3900. }
  3901. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3902. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3903. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3904. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3905. {
  3906. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3907. if((access(filenmae,F_OK))!=-1)
  3908. {
  3909. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3910. sprintf(str,"rm -f %s",filenmae);
  3911. system(str);
  3912. }
  3913. }
  3914. }
  3915. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3916. #if 1 // for TempStopTransaction
  3917. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3918. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3919. {
  3920. checkTempStopTransaction(gun_index);
  3921. }
  3922. #endif
  3923. }
  3924. }
  3925. }
  3926. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3927. {
  3928. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3929. {
  3930. tempIndex = ((gun_index==2) ? 1: 0);
  3931. }
  3932. else
  3933. {
  3934. tempIndex = gun_index;
  3935. }
  3936. for (int index = 0; index < GB_QUANTITY; index++)
  3937. {
  3938. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3939. {
  3940. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3941. {
  3942. // Sent unplug message for California pricing logic
  3943. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3944. {
  3945. uint8_t ts[20];
  3946. getNowDatetime(ts);
  3947. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3948. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3949. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3950. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3951. }
  3952. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3953. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3954. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3955. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3956. {
  3957. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3958. if((access(filenmae,F_OK))!=-1)
  3959. {
  3960. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3961. sprintf(str,"rm -f %s",filenmae);
  3962. system(str);
  3963. }
  3964. }
  3965. }
  3966. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3967. #if 1 // for TempStopTransaction
  3968. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3969. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3970. {
  3971. checkTempStopTransaction(gun_index);
  3972. }
  3973. #endif
  3974. }
  3975. }
  3976. }
  3977. else if(gunType[gun_index] == GUN_TYPE_DO)
  3978. {
  3979. tempIndex = gun_index;
  3980. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3981. {
  3982. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3983. {
  3984. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3985. {
  3986. // Sent unplug message for California pricing logic
  3987. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3988. {
  3989. uint8_t ts[20];
  3990. getNowDatetime(ts);
  3991. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3992. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3993. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3994. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3995. }
  3996. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3997. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3998. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3999. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_IDLE))) // complete
  4000. {
  4001. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4002. if((access(filenmae,F_OK))!=-1)
  4003. {
  4004. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4005. sprintf(str,"rm -f %s",filenmae);
  4006. system(str);
  4007. }
  4008. }
  4009. }
  4010. 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);
  4011. #if 1 // for TempStopTransaction
  4012. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4013. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4014. {
  4015. checkTempStopTransaction(gun_index);
  4016. }
  4017. #endif
  4018. }
  4019. }
  4020. }
  4021. else
  4022. {
  4023. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4024. {
  4025. tempIndex = 2;
  4026. }
  4027. else
  4028. {
  4029. tempIndex = gun_index;
  4030. }
  4031. for (int index = 0; index < AC_QUANTITY; index++)
  4032. {
  4033. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4034. {
  4035. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4036. {
  4037. // Sent unplug message for California pricing logic
  4038. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  4039. {
  4040. uint8_t ts[20];
  4041. getNowDatetime(ts);
  4042. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4043. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4044. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4045. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4046. }
  4047. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4048. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4049. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4050. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4051. {
  4052. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4053. if((access(filenmae,F_OK))!=-1)
  4054. {
  4055. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4056. sprintf(str,"rm -f %s",filenmae);
  4057. system(str);
  4058. }
  4059. }
  4060. }
  4061. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4062. #if 1 // for TempStopTransaction
  4063. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4064. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4065. {
  4066. checkTempStopTransaction(gun_index);
  4067. }
  4068. #endif
  4069. }
  4070. }// END
  4071. }
  4072. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) &&
  4073. (
  4074. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  4075. )
  4076. )
  4077. {
  4078. if(SystemInitial > 0)
  4079. SystemInitial -= 1;
  4080. sendStatusNotificationRequest(gun_index);
  4081. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4082. }
  4083. //==============================================
  4084. // CSU Trigger Smart Charging Profilw
  4085. //==============================================
  4086. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4087. {
  4088. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  4089. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4090. }
  4091. //==============================================
  4092. // Meter report
  4093. //==============================================
  4094. // Trigger MeterValue
  4095. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4096. {
  4097. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4098. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4099. }
  4100. // ClockAlign MeterValue
  4101. 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))
  4102. {
  4103. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4104. {
  4105. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4106. {
  4107. tempIndex = ((gun_index==2) ? 1: 0);
  4108. }
  4109. else
  4110. {
  4111. tempIndex = gun_index;
  4112. }
  4113. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4114. {
  4115. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4116. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4117. {
  4118. reqClockAlignMeter[gun_index] = 1;
  4119. }
  4120. }// End for CHAdeMO
  4121. }
  4122. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4123. {
  4124. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4125. {
  4126. tempIndex = ((gun_index==2) ? 1: 0);
  4127. }
  4128. else
  4129. {
  4130. tempIndex = gun_index;
  4131. }
  4132. for (int index = 0; index < CCS_QUANTITY; index++)
  4133. {
  4134. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4135. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4136. {
  4137. reqClockAlignMeter[gun_index] = 1;
  4138. }
  4139. } // End for CCS
  4140. }
  4141. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4142. {
  4143. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4144. {
  4145. tempIndex = ((gun_index==2) ? 1: 0);
  4146. }
  4147. else
  4148. {
  4149. tempIndex = gun_index;
  4150. }
  4151. for (int index = 0; index < GB_QUANTITY; index++)
  4152. {
  4153. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4154. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4155. {
  4156. reqClockAlignMeter[gun_index] = 1;
  4157. }
  4158. }// End for GB
  4159. }
  4160. else if(gunType[gun_index] == GUN_TYPE_DO)
  4161. {
  4162. tempIndex = gun_index;
  4163. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4164. {
  4165. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4166. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4167. {
  4168. reqClockAlignMeter[gun_index] = 1;
  4169. }
  4170. }
  4171. }
  4172. else
  4173. {
  4174. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4175. {
  4176. tempIndex = 2;
  4177. }
  4178. else
  4179. {
  4180. tempIndex = gun_index;
  4181. }
  4182. for (int index = 0; index < AC_QUANTITY; index++)
  4183. {
  4184. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4185. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4186. {
  4187. reqClockAlignMeter[gun_index] = 1;
  4188. }
  4189. }//End for AC
  4190. }
  4191. if(reqClockAlignMeter[gun_index] == 1)
  4192. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4193. }
  4194. // Sample period MeterValue
  4195. if(((getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>5?(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):5))))
  4196. {
  4197. //check Transaction active
  4198. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4199. {
  4200. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4201. {
  4202. tempIndex = ((gun_index==2) ? 1: 0);
  4203. }
  4204. else
  4205. {
  4206. tempIndex = gun_index;
  4207. }
  4208. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4209. {
  4210. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4211. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4212. {
  4213. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4214. {
  4215. reqSampleMeter[gun_index] = 1;
  4216. }
  4217. }
  4218. }// End for CHAdeMO
  4219. }
  4220. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4221. {
  4222. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4223. {
  4224. tempIndex = ((gun_index==2) ? 1: 0);
  4225. }
  4226. else
  4227. {
  4228. tempIndex = gun_index;
  4229. }
  4230. for (int index = 0; index < CCS_QUANTITY; index++)
  4231. {
  4232. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4233. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4234. {
  4235. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4236. {
  4237. reqSampleMeter[gun_index] = 1;
  4238. }
  4239. }
  4240. } // End for CCS
  4241. }
  4242. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4243. {
  4244. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4245. {
  4246. tempIndex = ((gun_index==2) ? 1: 0);
  4247. }
  4248. else
  4249. {
  4250. tempIndex = gun_index;
  4251. }
  4252. for (int index = 0; index < GB_QUANTITY; index++)
  4253. {
  4254. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4255. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4256. {
  4257. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4258. {
  4259. reqSampleMeter[gun_index] = 1;
  4260. }
  4261. }
  4262. }// End for GB
  4263. }
  4264. else if(gunType[gun_index] == GUN_TYPE_DO)
  4265. {
  4266. tempIndex = gun_index;
  4267. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4268. {
  4269. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4270. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4271. {
  4272. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4273. {
  4274. reqSampleMeter[gun_index] = 1;
  4275. }
  4276. }
  4277. }
  4278. }
  4279. else
  4280. {
  4281. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4282. {
  4283. tempIndex = 2;
  4284. }
  4285. else
  4286. {
  4287. tempIndex = gun_index;
  4288. }
  4289. for (int index = 0; index < AC_QUANTITY; index++)
  4290. {
  4291. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4292. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4293. {
  4294. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4295. {
  4296. reqSampleMeter[gun_index] = 1;
  4297. }
  4298. }
  4299. }//End for AC
  4300. }
  4301. if(reqSampleMeter[gun_index] == 1)
  4302. {
  4303. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4304. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4305. storeTempStopTransaction(gun_index);
  4306. }
  4307. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4308. }
  4309. //==============================================
  4310. // Check Connector reserved
  4311. //==============================================
  4312. //===============================
  4313. // Check if Reserve is expired
  4314. //===============================
  4315. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  4316. {
  4317. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  4318. {
  4319. DEBUG_INFO("reserve expired.\n");
  4320. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  4321. }
  4322. }//END OF Check if Reserve is expired
  4323. //==========================================
  4324. // csu trigger FirmwareStatusNotificationReq
  4325. //==========================================
  4326. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4327. {
  4328. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  4329. }
  4330. //==========================================
  4331. // csu trigger DiagnosticsStatusNotificationReq
  4332. //==========================================
  4333. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4334. {
  4335. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  4336. }
  4337. //==========================================
  4338. // csu trigger CancelReservationConf
  4339. //==========================================
  4340. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4341. {
  4342. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  4343. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4344. }
  4345. //==========================================
  4346. // csu trigger ChangeAvailabilityConf
  4347. //==========================================
  4348. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4349. {
  4350. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  4351. }
  4352. //==========================================
  4353. // csu trigger UnlockConnectorConf
  4354. //==========================================
  4355. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4356. {
  4357. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  4358. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4359. }
  4360. //==========================================
  4361. // csu trigger ReserveNowConf
  4362. //==========================================
  4363. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4364. {
  4365. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  4366. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4367. }
  4368. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  4369. {
  4370. sendSignCertificateRequest();
  4371. }
  4372. }
  4373. }
  4374. //==========================================
  4375. // send request routine
  4376. //==========================================
  4377. int sendAuthorizeRequest(int gun_index)
  4378. {
  4379. mtrace();
  4380. int result = FAIL;
  4381. char message[100]={0};
  4382. char guid[37];
  4383. char tempdata[65]={0};
  4384. DEBUG_INFO("sendAuthorizeRequest...\n");
  4385. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4386. //Local Authorize
  4387. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  4388. {
  4389. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4390. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4391. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4392. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4393. result = PASS;
  4394. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4395. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4396. authorizeRetryTimes = 0;
  4397. return result;
  4398. }
  4399. 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))||
  4400. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4401. {
  4402. // Query from cache
  4403. DEBUG_INFO("Authorize from cache.\n");
  4404. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4405. // Query from list
  4406. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4407. {
  4408. DEBUG_INFO("Authorize from list.\n");
  4409. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4410. }
  4411. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4412. {
  4413. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4414. {
  4415. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4416. }
  4417. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4418. {
  4419. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4420. }
  4421. if(!GetOcppConnStatus())
  4422. {
  4423. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4424. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4425. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4426. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4427. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4428. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4429. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4430. authorizeRetryTimes = 0;
  4431. return result;
  4432. }
  4433. }
  4434. else
  4435. {
  4436. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4437. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4438. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4439. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4440. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  4441. else
  4442. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4443. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4444. result = PASS;
  4445. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4446. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4447. authorizeRetryTimes = 0;
  4448. return result;
  4449. }
  4450. }
  4451. //initialize struct Authorize
  4452. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  4453. //get data from shared memory
  4454. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4455. random_uuid(guid);
  4456. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  4457. LWS_Send(message);
  4458. sprintf(tempdata, "Authorize,%d", gun_index);
  4459. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4460. {
  4461. result = PASS;
  4462. DEBUG_INFO("Authorize mapItem pass\n");
  4463. }
  4464. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4465. return result;
  4466. }
  4467. int sendBootNotificationRequest(void)
  4468. {
  4469. mtrace();
  4470. int result = FAIL;
  4471. char message[500]={0}, payload[700]={0};
  4472. char guid[37]={0};
  4473. char tempdata[65]={0};
  4474. // Fill BootNotification fields
  4475. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  4476. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4477. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4478. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4479. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4480. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4481. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4482. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4483. ShmOCPP16Data->ChargeBoxId
  4484. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4485. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4486. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4487. ,ShmOCPP16Data->BootNotification.CpFwVersion
  4488. ,ShmOCPP16Data->BootNotification.CpIccid
  4489. ,ShmOCPP16Data->BootNotification.CpImsi);
  4490. random_uuid(guid);
  4491. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4492. LWS_Send(message);
  4493. sprintf(tempdata, "BootNotification,0");
  4494. 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*/)
  4495. {
  4496. result = PASS;
  4497. }
  4498. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4499. strcpy(queuedata,message);
  4500. return result;
  4501. }
  4502. int sendDataTransferRequest(int gun_index)
  4503. {
  4504. mtrace();
  4505. char message[1000]={0};
  4506. char guid[37]={0};
  4507. char tempdata[65]={0};
  4508. int result = FAIL;
  4509. random_uuid(guid);
  4510. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4511. MESSAGE_TYPE_CALL,
  4512. guid,
  4513. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  4514. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  4515. ShmOCPP16Data->DataTransfer[gun_index].Data);
  4516. LWS_Send(message);
  4517. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4518. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4519. {
  4520. result = PASS;
  4521. DEBUG_INFO("DataTransfer mapItem pass\n");
  4522. }
  4523. return result;
  4524. }
  4525. int sendDiagnosticsStatusNotificationRequest(char *status)
  4526. {
  4527. mtrace();
  4528. int result = FAIL;
  4529. char message[110]={0};
  4530. char guid[37]={0};
  4531. char tempdata[65]={0};
  4532. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4533. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4534. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4535. random_uuid(guid);
  4536. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4537. LWS_SendNow(message);
  4538. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4539. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4540. {
  4541. result = PASS;
  4542. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4543. }
  4544. //#ifdef SystemLogMessage
  4545. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4546. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4547. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4548. //#endif
  4549. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4550. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4551. //record status
  4552. if(strcmp(status,"Idle")==0)
  4553. {
  4554. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4555. }
  4556. else if(strcmp(status,"Uploaded")==0)
  4557. {
  4558. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4559. }
  4560. else if(strcmp(status,"UploadFailed")==0)
  4561. {
  4562. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4563. }
  4564. else if(strcmp(status,"Uploading")==0)
  4565. {
  4566. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4567. }
  4568. return result;
  4569. }
  4570. int sendFirmwareStatusNotificationRequest(char *status)
  4571. {
  4572. mtrace();
  4573. int result = FAIL;
  4574. char message[110]={0};
  4575. char guid[37]={0};
  4576. char tempdata[65]={0};
  4577. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4578. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4579. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4580. random_uuid(guid);
  4581. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4582. LWS_SendNow(message);
  4583. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4584. 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*/)
  4585. {
  4586. result = PASS;
  4587. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4588. }
  4589. //#ifdef SystemLogMessage
  4590. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4591. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4592. //#endif
  4593. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4594. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4595. //record status
  4596. if(strcmp(status,"Downloaded")==0)
  4597. {
  4598. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4599. }
  4600. else if(strcmp(status,"DownloadFailed")==0)
  4601. {
  4602. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4603. }
  4604. else if(strcmp(status,"Downloading")==0)
  4605. {
  4606. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4607. }
  4608. else if(strcmp(status,"Idle")==0)
  4609. {
  4610. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4611. }
  4612. else if(strcmp(status,"InstallationFailed")==0)
  4613. {
  4614. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4615. }
  4616. else if(strcmp(status,"Installing")==0)
  4617. {
  4618. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4619. }
  4620. else if(strcmp(status,"Installed")==0)
  4621. {
  4622. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4623. }
  4624. return result;
  4625. }
  4626. int sendHeartbeatRequest(int gun_index)
  4627. {
  4628. mtrace();
  4629. int result = FAIL;
  4630. char message[80]={0};
  4631. char guid[37]={0};
  4632. char tempdata[65]={0};
  4633. random_uuid(guid);
  4634. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4635. , MESSAGE_TYPE_CALL
  4636. , guid );
  4637. LWS_Send(message);
  4638. sprintf(tempdata, "Heartbeat,%d", 0);
  4639. 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*/)
  4640. {
  4641. result = PASS;
  4642. }
  4643. return result;
  4644. }
  4645. int sendStartTransactionRequest(int gun_index)
  4646. {
  4647. mtrace();
  4648. int result = FAIL;
  4649. char message[250]={0};
  4650. char guid[37]={0};
  4651. struct timeval tmnow;
  4652. struct tm *tm;
  4653. char buf[28];//, usec_buf[6];
  4654. char tempdata[65]={0};
  4655. int tempIndex = 0;
  4656. DEBUG_INFO("sendStartTransactionRequest...\n");
  4657. gettimeofday(&tmnow, NULL);
  4658. time_t t;
  4659. t = time(NULL);
  4660. /*UTC time and date*/
  4661. tm = gmtime(&t);
  4662. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4663. #if 0 // remove temporally
  4664. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4665. strcat(buf,".");
  4666. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4667. strcat(buf,usec_buf);
  4668. #endif
  4669. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4670. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  4671. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4672. // clear StartTransaction Response
  4673. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4674. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4675. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4676. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  4677. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4678. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4679. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4680. {
  4681. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4682. {
  4683. tempIndex = ((gun_index==2) ? 1: 0);
  4684. }
  4685. else
  4686. {
  4687. tempIndex = gun_index;
  4688. }
  4689. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4690. {
  4691. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4692. {
  4693. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4694. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4695. }
  4696. }
  4697. }
  4698. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4699. {
  4700. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4701. {
  4702. tempIndex = ((gun_index==2) ? 1: 0);
  4703. }
  4704. else
  4705. {
  4706. tempIndex = gun_index;
  4707. }
  4708. for (int index = 0; index < CCS_QUANTITY; index++)
  4709. {
  4710. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4711. {
  4712. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4713. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4714. }
  4715. }
  4716. }
  4717. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4718. {
  4719. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4720. {
  4721. tempIndex = ((gun_index==2) ? 1: 0);
  4722. }
  4723. else
  4724. {
  4725. tempIndex = gun_index;
  4726. }
  4727. for (int index = 0; index < GB_QUANTITY; index++)
  4728. {
  4729. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4730. {
  4731. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4732. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4733. }
  4734. }
  4735. }
  4736. else if(gunType[gun_index] == GUN_TYPE_DO)
  4737. {
  4738. tempIndex = gun_index;
  4739. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4740. {
  4741. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4742. {
  4743. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4744. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4745. }
  4746. }
  4747. }
  4748. else
  4749. {
  4750. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4751. {
  4752. tempIndex = 2;
  4753. }
  4754. else
  4755. {
  4756. tempIndex = gun_index;
  4757. }
  4758. for (int index = 0; index < AC_QUANTITY; index++)
  4759. {
  4760. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4761. {
  4762. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4763. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4764. }
  4765. }
  4766. }
  4767. random_uuid(guid);
  4768. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4769. {
  4770. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4771. , gun_index +1
  4772. , MESSAGE_TYPE_CALL
  4773. , guid
  4774. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4775. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4776. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4777. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4778. }
  4779. else
  4780. {
  4781. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4782. , gun_index +1
  4783. , MESSAGE_TYPE_CALL
  4784. , guid
  4785. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4786. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4787. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4788. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  4789. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4790. }
  4791. #if 1
  4792. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4793. 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*/)
  4794. {
  4795. result = PASS;
  4796. }
  4797. #endif
  4798. strcpy(queuedata, message);
  4799. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4800. OCPP_insert_transaction_msg(YES, queuedata);
  4801. return result;
  4802. }
  4803. int sendStatusNotificationRequest(int gun_index)
  4804. {
  4805. mtrace();
  4806. int result = FAIL;
  4807. char message[600]={0};
  4808. char guid[37];
  4809. int currentStatus = 0;
  4810. struct timeval tmnow;
  4811. struct tm *tm;
  4812. char buf[28];//, usec_buf[6];
  4813. char tempdata[65]={0};
  4814. int tempIndex = 0;
  4815. uint8_t isStateChanged = TRUE;
  4816. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4817. gettimeofday(&tmnow, NULL);
  4818. time_t t;
  4819. t = time(NULL);
  4820. /*UTC time and date*/
  4821. tm = gmtime(&t);
  4822. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4823. #if 0 // remove temporally
  4824. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4825. strcat(buf,".");
  4826. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4827. strcat(buf,usec_buf);
  4828. #endif
  4829. //printf("%s",buf);
  4830. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4831. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4832. // it's option
  4833. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  4834. /*
  4835. enum _SYSTEM_STATUS
  4836. {
  4837. S_BOOTING = 0,
  4838. S_IDLE, = 1
  4839. S_AUTHORIZING, =2
  4840. S_REASSIGN_CHECK, =3
  4841. S_REASSIGN, =4
  4842. S_PRECHARGE, =5
  4843. S_PREPARING_FOR_EV, =6
  4844. S_PREPARING_FOR_EVSE, =7
  4845. S_CHARGING, =8
  4846. S_TERMINATING, =9
  4847. S_COMPLETE, =10
  4848. S_ALARM, =11
  4849. S_FAULT =12
  4850. }
  4851. */
  4852. //check Transaction active
  4853. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4854. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4855. {
  4856. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4857. {
  4858. tempIndex = ((gun_index==2) ? 1: 0);
  4859. }
  4860. else
  4861. {
  4862. tempIndex = gun_index;
  4863. }
  4864. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4865. {
  4866. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4867. {
  4868. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4869. {
  4870. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4871. {
  4872. currentStatus = Preparing; //OCPP Status: Preparing
  4873. }
  4874. else
  4875. {
  4876. currentStatus = Available; //OCPP Status: Available
  4877. }
  4878. }
  4879. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4880. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4881. ) //S_PRECHARGE
  4882. {
  4883. currentStatus = Preparing; //OCPP Status: Preparing
  4884. }
  4885. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4886. {
  4887. currentStatus = Charging; //OCPP Status: Charging
  4888. }
  4889. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4890. {
  4891. currentStatus = Finishing; //OCPP Status: Finishing
  4892. }
  4893. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4894. {
  4895. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4896. }
  4897. 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
  4898. {
  4899. currentStatus = Unavailable; //OCPP Status: Unavailable
  4900. }
  4901. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4902. {
  4903. currentStatus = Faulted; //OCPP Status: Faulted
  4904. }
  4905. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4906. {
  4907. currentStatus = Reserved; //OCPP Status: Reserved
  4908. }
  4909. } //end of the same index
  4910. }//end of for CHAdeMO_QUANTITY
  4911. }
  4912. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4913. {
  4914. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4915. {
  4916. tempIndex = ((gun_index==2) ? 1: 0);
  4917. }
  4918. else
  4919. {
  4920. tempIndex = gun_index;
  4921. }
  4922. for (int index = 0; index < CCS_QUANTITY; index++)
  4923. {
  4924. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4925. {
  4926. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4927. {
  4928. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4929. {
  4930. currentStatus = Preparing; //OCPP Status: Preparing
  4931. }
  4932. else
  4933. {
  4934. currentStatus = Available; //OCPP Status: Available
  4935. }
  4936. }
  4937. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4938. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4939. ) //S_PRECHARGE
  4940. {
  4941. currentStatus = Preparing; //OCPP Status: Preparing
  4942. }
  4943. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4944. {
  4945. currentStatus = Charging; //OCPP Status: Charging
  4946. }
  4947. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4948. {
  4949. currentStatus = Finishing; //OCPP Status: Finishing
  4950. }
  4951. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4952. {
  4953. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4954. }
  4955. 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
  4956. {
  4957. currentStatus = Unavailable; //OCPP Status : Unavailable
  4958. }
  4959. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4960. {
  4961. currentStatus = Faulted; //OCPP Status: Faulted
  4962. }
  4963. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4964. {
  4965. currentStatus = Reserved; //OCPP Status: Reserved
  4966. }
  4967. } //end of the same index
  4968. } // end of for CCS_QUANTITY
  4969. }
  4970. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4971. {
  4972. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4973. {
  4974. tempIndex = ((gun_index==2) ? 1: 0);
  4975. }
  4976. else
  4977. {
  4978. tempIndex = gun_index;
  4979. }
  4980. for (int index = 0; index < GB_QUANTITY; index++)
  4981. {
  4982. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4983. {
  4984. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4985. {
  4986. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4987. {
  4988. currentStatus = Preparing; //OCPP Status: Preparing
  4989. }
  4990. else
  4991. {
  4992. currentStatus = Available; //OCPP Status: Available
  4993. }
  4994. }
  4995. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4996. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4997. ) //S_PRECHARGE
  4998. {
  4999. currentStatus = Preparing; //OCPP Status: Preparing
  5000. }
  5001. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5002. {
  5003. currentStatus = Charging; //OCPP Status: Charging
  5004. }
  5005. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5006. {
  5007. currentStatus = Finishing; //OCPP Status: Finishing
  5008. }
  5009. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5010. {
  5011. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5012. }
  5013. 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
  5014. {
  5015. currentStatus = Unavailable; //OCPP Status: Unavailable
  5016. }
  5017. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5018. {
  5019. currentStatus = Faulted; //OCPP Status: Faulted
  5020. }
  5021. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5022. {
  5023. currentStatus = Reserved; //OCPP Status: Reserved
  5024. }
  5025. } //end of the same index
  5026. } // end of for GB_QUANTITY
  5027. }
  5028. else if(gunType[gun_index] == GUN_TYPE_DO)
  5029. {
  5030. tempIndex = gun_index;
  5031. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5032. {
  5033. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5034. {
  5035. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5036. {
  5037. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5038. {
  5039. currentStatus = Preparing; //OCPP Status: Preparing
  5040. }
  5041. else
  5042. {
  5043. currentStatus = Available; //OCPP Status: Available
  5044. }
  5045. }
  5046. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5047. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5048. ) //S_PRECHARGE
  5049. {
  5050. currentStatus = Preparing; //OCPP Status: Preparing
  5051. }
  5052. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5053. {
  5054. currentStatus = Charging; //OCPP Status: Charging
  5055. }
  5056. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5057. {
  5058. currentStatus = Finishing; //OCPP Status: Finishing
  5059. }
  5060. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5061. {
  5062. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5063. }
  5064. 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
  5065. {
  5066. currentStatus = Unavailable; //OCPP Status: Unavailable
  5067. }
  5068. 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
  5069. {
  5070. currentStatus = Faulted; //OCPP Status: Faulted
  5071. }
  5072. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5073. {
  5074. currentStatus = Reserved; //OCPP Status: Reserved
  5075. }
  5076. } //end of the same index
  5077. }
  5078. }
  5079. else
  5080. {
  5081. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5082. {
  5083. tempIndex = 2;
  5084. }
  5085. else
  5086. {
  5087. tempIndex = gun_index;
  5088. }
  5089. for (int index = 0; index < AC_QUANTITY; index++)
  5090. {
  5091. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5092. {
  5093. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5094. {
  5095. 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))
  5096. {
  5097. currentStatus = Preparing; //OCPP Status: Preparing
  5098. }
  5099. else
  5100. {
  5101. currentStatus = Available; //OCPP Status: Available
  5102. }
  5103. }
  5104. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5105. {
  5106. currentStatus = Preparing; //OCPP Status: Preparing
  5107. }
  5108. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5109. {
  5110. currentStatus = Charging; //OCPP Status: Charging
  5111. }
  5112. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5113. {
  5114. currentStatus = Finishing; //OCPP Status: Finishing
  5115. }
  5116. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5117. {
  5118. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5119. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5120. else
  5121. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5122. }
  5123. 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
  5124. {
  5125. currentStatus = Unavailable; //OCPP Status: Unavailable
  5126. }
  5127. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5128. {
  5129. currentStatus = Faulted; //OCPP Status: Faulted
  5130. }
  5131. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5132. {
  5133. currentStatus = Reserved; //OCPP Status: Reserved
  5134. }
  5135. }//end of the same index
  5136. }//end of for AC_QUANTITY
  5137. }
  5138. //it's option
  5139. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5140. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  5141. {
  5142. isStateChanged = FALSE;
  5143. }
  5144. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5145. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  5146. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5147. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5148. random_uuid(guid);
  5149. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5150. , MESSAGE_TYPE_CALL
  5151. , guid
  5152. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  5153. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  5154. , ShmOCPP16Data->StatusNotification[gun_index].Info
  5155. , ShmOCPP16Data->StatusNotification[gun_index].Status
  5156. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  5157. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  5158. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  5159. if((server_sign == TRUE) && isStateChanged)
  5160. {
  5161. LWS_Send(message);
  5162. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5163. 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*/)
  5164. {
  5165. //DEBUG_ERROR("statusNotification mapitem pass");
  5166. result = PASS;
  5167. }
  5168. }
  5169. else
  5170. {
  5171. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5172. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5173. result = PASS;
  5174. }
  5175. return result;
  5176. }
  5177. int sendStopTransactionRequest(int gun_index)
  5178. {
  5179. mtrace();
  5180. int result = FAIL;
  5181. //char message[1500]={0};
  5182. char guid[37]={0};
  5183. char tempdata[65]={0};
  5184. int tempIndex = 0;
  5185. char TempStopTransaction[256];
  5186. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  5187. //int idx_sample=0;
  5188. DEBUG_INFO("sendStopTransactionRequest \n");
  5189. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5190. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  5191. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5192. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5193. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5194. {
  5195. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5196. {
  5197. tempIndex = ((gun_index==2) ? 1: 0);
  5198. }
  5199. else
  5200. {
  5201. tempIndex = gun_index;
  5202. }
  5203. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5204. {
  5205. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5206. {
  5207. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5208. }
  5209. }// END OF CHAdeMO_QUANTITY
  5210. }
  5211. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5212. {
  5213. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5214. {
  5215. tempIndex = ((gun_index==2) ? 1: 0);
  5216. }
  5217. else
  5218. {
  5219. tempIndex = gun_index;
  5220. }
  5221. for (int index = 0; index < CCS_QUANTITY; index++)
  5222. {
  5223. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5224. {
  5225. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5226. }
  5227. }// END OF CCS_QUANTITY
  5228. }
  5229. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5230. {
  5231. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5232. {
  5233. tempIndex = ((gun_index==2) ? 1: 0);
  5234. }
  5235. else
  5236. {
  5237. tempIndex = gun_index;
  5238. }
  5239. for (int index = 0; index < GB_QUANTITY; index++)
  5240. {
  5241. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5242. {
  5243. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5244. }
  5245. }// END OF GB_QUANTITY
  5246. }
  5247. else if(gunType[gun_index] == GUN_TYPE_DO)
  5248. {
  5249. tempIndex = gun_index;
  5250. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5251. {
  5252. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5253. {
  5254. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5255. }
  5256. }// END OF GB_QUANTITY
  5257. }
  5258. else
  5259. {
  5260. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5261. {
  5262. tempIndex = 2;
  5263. }
  5264. else
  5265. {
  5266. tempIndex = gun_index;
  5267. }
  5268. for (int index = 0; index < AC_QUANTITY; index++)
  5269. {
  5270. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5271. {
  5272. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5273. }
  5274. }// END OF AC_QUANTITY
  5275. }
  5276. //====================================== Stop Transaction Time =====================================================
  5277. struct timeval tmnow;
  5278. struct tm *tm;
  5279. char buf[28];//, usec_buf[6];
  5280. gettimeofday(&tmnow, NULL);
  5281. time_t t;
  5282. t = time(NULL);
  5283. /*UTC time and date*/
  5284. tm = gmtime(&t);
  5285. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5286. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  5287. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  5288. random_uuid(guid);
  5289. /***********************************transactionData******************************************************/
  5290. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5291. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5292. //=================================
  5293. // Transaction_Begin
  5294. //=================================
  5295. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5296. {
  5297. //============================================ Energy.Active.Import.Interval ================================
  5298. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5299. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5300. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5301. 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*/]);
  5302. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5303. 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))
  5304. {
  5305. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5306. }
  5307. else
  5308. {
  5309. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5310. }
  5311. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5312. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5313. }
  5314. //=================================
  5315. // Transaction_End
  5316. //=================================
  5317. // ================================= Current.Import L1 ===============================================
  5318. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5319. {
  5320. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5321. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5322. {
  5323. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5324. {
  5325. tempIndex = ((gun_index==2) ? 1: 0);
  5326. }
  5327. else
  5328. {
  5329. tempIndex = gun_index;
  5330. }
  5331. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5332. {
  5333. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5334. {
  5335. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5336. }
  5337. }// End of for CHAdeMO_QUANTITY
  5338. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5339. }
  5340. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5341. {
  5342. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5343. {
  5344. tempIndex = ((gun_index==2) ? 1: 0);
  5345. }
  5346. else
  5347. {
  5348. tempIndex = gun_index;
  5349. }
  5350. for (int index = 0; index < CCS_QUANTITY; index++)
  5351. {
  5352. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5353. {
  5354. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5355. }
  5356. }// End of for CCS_QUANTITY
  5357. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5358. }
  5359. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5360. {
  5361. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5362. {
  5363. tempIndex = ((gun_index==2) ? 1: 0);
  5364. }
  5365. else
  5366. {
  5367. tempIndex = gun_index;
  5368. }
  5369. for (int index = 0; index < GB_QUANTITY; index++)
  5370. {
  5371. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5372. {
  5373. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5374. }
  5375. }// End of for GB_QUANTITY
  5376. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5377. }
  5378. else if(gunType[gun_index] == GUN_TYPE_DO)
  5379. {
  5380. tempIndex = gun_index;
  5381. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5382. {
  5383. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5384. {
  5385. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5386. }
  5387. }
  5388. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5389. }
  5390. else
  5391. {
  5392. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5393. {
  5394. tempIndex = 2;
  5395. }
  5396. else
  5397. {
  5398. tempIndex = gun_index;
  5399. }
  5400. for (int index = 0; index < AC_QUANTITY; index++)
  5401. {
  5402. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5403. {
  5404. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5405. }
  5406. }// End of for AC_QUANTITY
  5407. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5408. }
  5409. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5410. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5411. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5412. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5413. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5414. }
  5415. // ================================= Energy.Active.Import.Interval ==============================================
  5416. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5417. {
  5418. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5419. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5420. {
  5421. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5422. {
  5423. tempIndex = ((gun_index==2) ? 1: 0);
  5424. }
  5425. else
  5426. {
  5427. tempIndex = gun_index;
  5428. }
  5429. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5430. {
  5431. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5432. {
  5433. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5434. }
  5435. }// END OF CHAdeMO_QUANTITY
  5436. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5437. }
  5438. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5439. {
  5440. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5441. {
  5442. tempIndex = ((gun_index==2) ? 1: 0);
  5443. }
  5444. else
  5445. {
  5446. tempIndex = gun_index;
  5447. }
  5448. for (int index = 0; index < CCS_QUANTITY; index++)
  5449. {
  5450. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5451. {
  5452. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5453. }
  5454. }// END OF CCS_QUANTITY
  5455. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5456. }
  5457. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5458. {
  5459. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5460. {
  5461. tempIndex = ((gun_index==2) ? 1: 0);
  5462. }
  5463. else
  5464. {
  5465. tempIndex = gun_index;
  5466. }
  5467. for (int index = 0; index < GB_QUANTITY; index++)
  5468. {
  5469. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5470. {
  5471. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5472. }
  5473. }// END OF GB_QUANTITY
  5474. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5475. }
  5476. else if(gunType[gun_index] == GUN_TYPE_DO)
  5477. {
  5478. tempIndex = gun_index;
  5479. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5480. {
  5481. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5482. {
  5483. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5484. }
  5485. }
  5486. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5487. }
  5488. else
  5489. {
  5490. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5491. {
  5492. tempIndex = 2;
  5493. }
  5494. else
  5495. {
  5496. tempIndex = gun_index;
  5497. }
  5498. for (int index = 0; index < AC_QUANTITY; index++)
  5499. {
  5500. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5501. {
  5502. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5503. }
  5504. }// END OF AC_QUANTITY
  5505. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5506. }
  5507. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5508. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5509. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5510. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5511. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5512. }
  5513. //=================================== Power.Active.Import ==================================================
  5514. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5515. {
  5516. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5517. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5518. {
  5519. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5520. {
  5521. tempIndex = ((gun_index==2) ? 1: 0);
  5522. }
  5523. else
  5524. {
  5525. tempIndex = gun_index;
  5526. }
  5527. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5528. {
  5529. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5530. {
  5531. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5532. }
  5533. } // End for CHAdeMO_QUANTITY
  5534. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5535. }
  5536. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5537. {
  5538. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5539. {
  5540. tempIndex = ((gun_index==2) ? 1: 0);
  5541. }
  5542. else
  5543. {
  5544. tempIndex = gun_index;
  5545. }
  5546. for (int index = 0; index < CCS_QUANTITY; index++)
  5547. {
  5548. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5549. {
  5550. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5551. }
  5552. } // END for CCS_QUANTITY
  5553. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5554. }
  5555. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5556. {
  5557. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5558. {
  5559. tempIndex = ((gun_index==2) ? 1: 0);
  5560. }
  5561. else
  5562. {
  5563. tempIndex = gun_index;
  5564. }
  5565. for (int index = 0; index < GB_QUANTITY; index++)
  5566. {
  5567. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5568. {
  5569. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5570. }
  5571. }// END for GB_QUANTITY
  5572. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5573. }
  5574. else if(gunType[gun_index] == GUN_TYPE_DO)
  5575. {
  5576. tempIndex = gun_index;
  5577. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5578. {
  5579. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5580. {
  5581. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5582. }
  5583. }
  5584. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5585. }
  5586. else
  5587. {
  5588. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5589. {
  5590. tempIndex = 2;
  5591. }
  5592. else
  5593. {
  5594. tempIndex = gun_index;
  5595. }
  5596. for (int index = 0; index < AC_QUANTITY; index++)
  5597. {
  5598. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5599. {
  5600. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5601. }
  5602. } // END for AC_QUANTITY
  5603. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5604. }
  5605. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5606. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5607. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5608. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5609. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5610. }
  5611. //============================ Voltage L1 ====================================
  5612. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5613. {
  5614. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5615. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5616. {
  5617. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5618. {
  5619. tempIndex = ((gun_index==2) ? 1: 0);
  5620. }
  5621. else
  5622. {
  5623. tempIndex = gun_index;
  5624. }
  5625. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5626. {
  5627. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5628. {
  5629. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5630. }
  5631. } // END OF FOR CHAdeMO_QUANTITY
  5632. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5633. }
  5634. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5635. {
  5636. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5637. {
  5638. tempIndex = ((gun_index==2) ? 1: 0);
  5639. }
  5640. else
  5641. {
  5642. tempIndex = gun_index;
  5643. }
  5644. for (int index = 0; index < CCS_QUANTITY; index++)
  5645. {
  5646. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5647. {
  5648. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5649. }
  5650. } // END OF FOR CCS_QUANTITY
  5651. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5652. }
  5653. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5654. {
  5655. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5656. {
  5657. tempIndex = ((gun_index==2) ? 1: 0);
  5658. }
  5659. else
  5660. {
  5661. tempIndex = gun_index;
  5662. }
  5663. for (int index = 0; index < GB_QUANTITY; index++)
  5664. {
  5665. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5666. {
  5667. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5668. }
  5669. } // END OF FOR GB_QUANTITY
  5670. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5671. }
  5672. else if(gunType[gun_index] == GUN_TYPE_DO)
  5673. {
  5674. tempIndex = gun_index;
  5675. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5676. {
  5677. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5678. {
  5679. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5680. }
  5681. }
  5682. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5683. }
  5684. else
  5685. {
  5686. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5687. {
  5688. tempIndex = 2;
  5689. }
  5690. else
  5691. {
  5692. tempIndex = gun_index;
  5693. }
  5694. for (int index = 0; index < AC_QUANTITY; index++)
  5695. {
  5696. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5697. {
  5698. 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
  5699. }
  5700. } // END OF FOR AC_QUANTITY
  5701. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5702. }
  5703. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5704. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5705. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5706. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5707. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5708. }
  5709. //====================== End SoC ================================
  5710. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5711. {
  5712. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5713. 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))
  5714. {
  5715. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5716. {
  5717. tempIndex = ((gun_index==2) ? 1: 0);
  5718. }
  5719. else
  5720. {
  5721. tempIndex = gun_index;
  5722. }
  5723. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5724. {
  5725. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5726. {
  5727. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5728. {
  5729. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5730. }
  5731. }
  5732. }
  5733. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5734. {
  5735. for (int index = 0; index < CCS_QUANTITY; index++)
  5736. {
  5737. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5738. {
  5739. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5740. }
  5741. }
  5742. }
  5743. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5744. {
  5745. for (int index = 0; index < GB_QUANTITY; index++)
  5746. {
  5747. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5748. {
  5749. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5750. }
  5751. }
  5752. }
  5753. else if(gunType[gun_index] == GUN_TYPE_DO)
  5754. {
  5755. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5756. {
  5757. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5758. {
  5759. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5760. }
  5761. }
  5762. }
  5763. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5764. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5765. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5766. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5767. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5768. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5769. } // END FOR DC CASE
  5770. }
  5771. // ================================= Current.Import L2 ===============================================
  5772. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5773. {
  5774. // AC 3 phse L2 current
  5775. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5776. {
  5777. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5778. {
  5779. tempIndex = 2;
  5780. }
  5781. else
  5782. {
  5783. tempIndex = gun_index;
  5784. }
  5785. for (int index = 0; index < AC_QUANTITY; index++)
  5786. {
  5787. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5788. {
  5789. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5790. }
  5791. }// End of for AC_QUANTITY
  5792. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5793. }
  5794. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5795. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5796. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5797. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5798. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5799. }
  5800. // ================================= Current.Import L3 ===============================================
  5801. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5802. {
  5803. // AC 3 phse L3 current
  5804. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5805. {
  5806. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5807. {
  5808. tempIndex = 2;
  5809. }
  5810. else
  5811. {
  5812. tempIndex = gun_index;
  5813. }
  5814. for (int index = 0; index < AC_QUANTITY; index++)
  5815. {
  5816. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5817. {
  5818. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5819. }
  5820. }// End of for AC_QUANTITY
  5821. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5822. }
  5823. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5824. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5825. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5826. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5827. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5828. }
  5829. //============================ Voltage L2 ====================================
  5830. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5831. {
  5832. // AC 3 phse L2 voltage
  5833. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5834. {
  5835. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5836. {
  5837. tempIndex = 2;
  5838. }
  5839. else
  5840. {
  5841. tempIndex = gun_index;
  5842. }
  5843. for (int index = 0; index < AC_QUANTITY; index++)
  5844. {
  5845. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5846. {
  5847. 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
  5848. }
  5849. } // END OF FOR AC_QUANTITY
  5850. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5851. }
  5852. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5853. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5854. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5855. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5856. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5857. }
  5858. //============================ Voltage L3 ====================================
  5859. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5860. {
  5861. // AC 3 phse L3 voltage
  5862. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5863. {
  5864. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5865. {
  5866. tempIndex = 2;
  5867. }
  5868. else
  5869. {
  5870. tempIndex = gun_index;
  5871. }
  5872. for (int index = 0; index < AC_QUANTITY; index++)
  5873. {
  5874. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5875. {
  5876. 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
  5877. }
  5878. } // END OF FOR AC_QUANTITY
  5879. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5880. }
  5881. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5882. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5883. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5884. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5885. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5886. }
  5887. //====================== Start SoC ================================
  5888. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5889. {
  5890. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5891. 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))
  5892. {
  5893. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5894. {
  5895. tempIndex = ((gun_index==2) ? 1: 0);
  5896. }
  5897. else
  5898. {
  5899. tempIndex = gun_index;
  5900. }
  5901. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5902. {
  5903. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5904. {
  5905. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5906. {
  5907. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5908. }
  5909. }
  5910. }
  5911. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5912. {
  5913. for (int index = 0; index < CCS_QUANTITY; index++)
  5914. {
  5915. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5916. {
  5917. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5918. }
  5919. }
  5920. }
  5921. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5922. {
  5923. for (int index = 0; index < GB_QUANTITY; index++)
  5924. {
  5925. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5926. {
  5927. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5928. }
  5929. }
  5930. }
  5931. else if(gunType[gun_index] == GUN_TYPE_DO)
  5932. {
  5933. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5934. {
  5935. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5936. {
  5937. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5938. }
  5939. }
  5940. }
  5941. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5942. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5943. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5944. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5945. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5946. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5947. } // END FOR DC CASE
  5948. }
  5949. //================================================ Message create ====================================================
  5950. json_object *StopTransaction = json_object_new_object();
  5951. json_object *transactionDatas = json_object_new_array();
  5952. json_object *sampledValues = json_object_new_array();
  5953. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  5954. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  5955. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  5956. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  5957. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  5958. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  5959. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  5960. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  5961. {
  5962. json_object *transactionData = json_object_new_object();
  5963. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5964. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5965. {
  5966. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5967. {
  5968. json_object *sampledValue = json_object_new_object();
  5969. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5970. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5971. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5972. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5973. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5974. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5975. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5976. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5977. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5978. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5979. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5980. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5981. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5982. json_object_array_add(sampledValues, sampledValue);
  5983. }
  5984. }
  5985. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5986. json_object_array_add(transactionDatas, transactionData);
  5987. }
  5988. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5989. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5990. ,MESSAGE_TYPE_CALL
  5991. ,guid
  5992. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5993. json_object_put(StopTransaction);
  5994. #if 1 // for TempStopTransaction
  5995. //Delete TempStopTransaction
  5996. if((access(TempStopTransaction,F_OK))!=-1)
  5997. {
  5998. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5999. }
  6000. #endif
  6001. #if 1
  6002. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6003. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6004. {
  6005. result = PASS;
  6006. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6007. }
  6008. #endif
  6009. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6010. OCPP_insert_transaction_msg(NO, queuedata);
  6011. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6012. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6013. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6014. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6015. {
  6016. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6017. }
  6018. //for test
  6019. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6020. return result;
  6021. }
  6022. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6023. {
  6024. mtrace();
  6025. int result = FAIL;
  6026. char guid[37]={0};
  6027. char tempdata[65]={0};
  6028. int tempIndex = 0;
  6029. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6030. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6031. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6032. //set value
  6033. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6034. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6035. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6036. -1);
  6037. random_uuid(guid);
  6038. //UTC Date time
  6039. struct timeval tmnow;
  6040. struct tm *tm;
  6041. char buf[28];//, usec_buf[6];
  6042. gettimeofday(&tmnow, NULL);
  6043. time_t t;
  6044. t = time(NULL);
  6045. /*UTC time and date*/
  6046. tm = gmtime(&t);
  6047. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6048. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6049. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6050. //********************************(1)Current.Import L1************************************************/
  6051. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6052. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6053. (dataType == ReadingContext_Trigger))
  6054. {
  6055. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6056. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6057. {
  6058. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6059. {
  6060. tempIndex = ((gun_index==2) ? 1: 0);
  6061. }
  6062. else
  6063. {
  6064. tempIndex = gun_index;
  6065. }
  6066. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6067. {
  6068. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6069. {
  6070. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6071. }
  6072. }
  6073. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6074. }
  6075. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6076. {
  6077. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6078. {
  6079. tempIndex = ((gun_index==2) ? 1: 0);
  6080. }
  6081. else
  6082. {
  6083. tempIndex = gun_index;
  6084. }
  6085. for (int index = 0; index < CCS_QUANTITY; index++)
  6086. {
  6087. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6088. {
  6089. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6090. }
  6091. }
  6092. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6093. }
  6094. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6095. {
  6096. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6097. {
  6098. tempIndex = ((gun_index==2) ? 1: 0);
  6099. }
  6100. else
  6101. {
  6102. tempIndex = gun_index;
  6103. }
  6104. for (int index = 0; index < GB_QUANTITY; index++)
  6105. {
  6106. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6107. {
  6108. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6109. }
  6110. }
  6111. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6112. }
  6113. else if(gunType[gun_index] == GUN_TYPE_DO)
  6114. {
  6115. tempIndex = gun_index;
  6116. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6117. {
  6118. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6119. {
  6120. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6121. }
  6122. }
  6123. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6124. }
  6125. else
  6126. {
  6127. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6128. {
  6129. tempIndex = 2;
  6130. }
  6131. else
  6132. {
  6133. tempIndex = gun_index;
  6134. }
  6135. for (int index = 0; index < AC_QUANTITY; index++)
  6136. {
  6137. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6138. {
  6139. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6140. }
  6141. }
  6142. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6143. }
  6144. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6145. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6146. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6147. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6148. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6149. }
  6150. //********************************(2)Energy.Active.Import.Register ************************************************/
  6151. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6152. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6153. (dataType == ReadingContext_Trigger))
  6154. {
  6155. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6156. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6157. {
  6158. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6159. {
  6160. tempIndex = ((gun_index==2) ? 1: 0);
  6161. }
  6162. else
  6163. {
  6164. tempIndex = gun_index;
  6165. }
  6166. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6167. {
  6168. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6169. {
  6170. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6171. }
  6172. }
  6173. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6174. }
  6175. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6176. {
  6177. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6178. {
  6179. tempIndex = ((gun_index==2) ? 1: 0);
  6180. }
  6181. else
  6182. {
  6183. tempIndex = gun_index;
  6184. }
  6185. for (int index = 0; index < CCS_QUANTITY; index++)
  6186. {
  6187. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6188. {
  6189. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6190. }
  6191. }
  6192. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6193. }
  6194. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6195. {
  6196. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6197. {
  6198. tempIndex = ((gun_index==2) ? 1: 0);
  6199. }
  6200. else
  6201. {
  6202. tempIndex = gun_index;
  6203. }
  6204. for (int index = 0; index < GB_QUANTITY; index++)
  6205. {
  6206. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6207. {
  6208. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6209. }
  6210. }
  6211. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6212. }
  6213. else if(gunType[gun_index] == GUN_TYPE_DO)
  6214. {
  6215. tempIndex = gun_index;
  6216. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6217. {
  6218. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6219. {
  6220. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6221. }
  6222. }
  6223. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6224. }
  6225. else
  6226. {
  6227. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6228. {
  6229. tempIndex = 2;
  6230. }
  6231. else
  6232. {
  6233. tempIndex = gun_index;
  6234. }
  6235. for (int index = 0; index < AC_QUANTITY; index++)
  6236. {
  6237. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6238. {
  6239. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6240. }
  6241. }
  6242. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6243. }
  6244. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6245. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6246. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6247. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6248. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6249. }
  6250. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6251. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6252. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6253. (dataType == ReadingContext_Trigger))
  6254. {
  6255. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6256. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6257. {
  6258. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6259. {
  6260. tempIndex = ((gun_index==2) ? 1: 0);
  6261. }
  6262. else
  6263. {
  6264. tempIndex = gun_index;
  6265. }
  6266. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6267. {
  6268. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6269. {
  6270. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6271. }
  6272. } // END OF FOR CHAdeMO_QUANTITY
  6273. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6274. }
  6275. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6276. {
  6277. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6278. {
  6279. tempIndex = ((gun_index==2) ? 1: 0);
  6280. }
  6281. else
  6282. {
  6283. tempIndex = gun_index;
  6284. }
  6285. for (int index = 0; index < CCS_QUANTITY; index++)
  6286. {
  6287. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6288. {
  6289. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6290. }
  6291. } // END OF CCS_QUANTITY
  6292. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6293. }
  6294. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6295. {
  6296. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6297. {
  6298. tempIndex = ((gun_index==2) ? 1: 0);
  6299. }
  6300. else
  6301. {
  6302. tempIndex = gun_index;
  6303. }
  6304. for (int index = 0; index < GB_QUANTITY; index++)
  6305. {
  6306. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6307. {
  6308. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6309. }
  6310. } // END OF GB_QUANTITY
  6311. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6312. }
  6313. else if(gunType[gun_index] == GUN_TYPE_DO)
  6314. {
  6315. tempIndex = gun_index;
  6316. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6317. {
  6318. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6319. {
  6320. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6321. }
  6322. }
  6323. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6324. }
  6325. else
  6326. {
  6327. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6328. {
  6329. tempIndex = 2;
  6330. }
  6331. else
  6332. {
  6333. tempIndex = gun_index;
  6334. }
  6335. for (int index = 0; index < AC_QUANTITY; index++)
  6336. {
  6337. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6338. {
  6339. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6340. }
  6341. }
  6342. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6343. }
  6344. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6345. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6346. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6347. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6348. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6349. }
  6350. //********************************(4)Power.Active.Import************************************************/
  6351. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6352. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6353. (dataType == ReadingContext_Trigger))
  6354. {
  6355. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6356. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6357. {
  6358. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6359. {
  6360. tempIndex = ((gun_index==2) ? 1: 0);
  6361. }
  6362. else
  6363. {
  6364. tempIndex = gun_index;
  6365. }
  6366. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6367. {
  6368. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6369. {
  6370. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6371. }
  6372. } // END OF FOR
  6373. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6374. }
  6375. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6376. {
  6377. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6378. {
  6379. tempIndex = ((gun_index==2) ? 1: 0);
  6380. }
  6381. else
  6382. {
  6383. tempIndex = gun_index;
  6384. }
  6385. for (int index = 0; index < CCS_QUANTITY; index++)
  6386. {
  6387. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6388. {
  6389. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6390. }
  6391. }
  6392. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6393. }
  6394. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6395. {
  6396. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6397. {
  6398. tempIndex = ((gun_index==2) ? 1: 0);
  6399. }
  6400. else
  6401. {
  6402. tempIndex = gun_index;
  6403. }
  6404. for (int index = 0; index < GB_QUANTITY; index++)
  6405. {
  6406. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6407. {
  6408. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6409. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6410. }
  6411. }
  6412. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6413. }
  6414. else if(gunType[gun_index] == GUN_TYPE_DO)
  6415. {
  6416. tempIndex = gun_index;
  6417. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6418. {
  6419. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6420. {
  6421. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6422. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6423. }
  6424. }
  6425. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6426. }
  6427. else
  6428. {
  6429. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6430. {
  6431. tempIndex = 2;
  6432. }
  6433. else
  6434. {
  6435. tempIndex = gun_index;
  6436. }
  6437. for (int index = 0; index < AC_QUANTITY; index++)
  6438. {
  6439. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6440. {
  6441. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6442. }
  6443. }
  6444. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6445. }
  6446. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6447. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6448. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6449. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6450. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6451. }
  6452. //***********************************************(5)VOLTAGE L1******************************************************/
  6453. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6454. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6455. (dataType == ReadingContext_Trigger))
  6456. {
  6457. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6458. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6459. {
  6460. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6461. {
  6462. tempIndex = ((gun_index==2) ? 1: 0);
  6463. }
  6464. else
  6465. {
  6466. tempIndex = gun_index;
  6467. }
  6468. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6469. {
  6470. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6471. {
  6472. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6473. }
  6474. }
  6475. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6476. }
  6477. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6478. {
  6479. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6480. {
  6481. tempIndex = ((gun_index==2) ? 1: 0);
  6482. }
  6483. else
  6484. {
  6485. tempIndex = gun_index;
  6486. }
  6487. for (int index = 0; index < CCS_QUANTITY; index++)
  6488. {
  6489. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6490. {
  6491. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6492. }
  6493. }
  6494. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6495. }
  6496. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6497. {
  6498. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6499. {
  6500. tempIndex = ((gun_index==2) ? 1: 0);
  6501. }
  6502. else
  6503. {
  6504. tempIndex = gun_index;
  6505. }
  6506. for (int index = 0; index < GB_QUANTITY; index++)
  6507. {
  6508. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6509. {
  6510. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6511. }
  6512. }
  6513. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6514. }
  6515. else if(gunType[gun_index] == GUN_TYPE_DO)
  6516. {
  6517. tempIndex = gun_index;
  6518. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6519. {
  6520. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6521. {
  6522. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6523. }
  6524. }
  6525. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6526. }
  6527. else
  6528. {
  6529. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6530. {
  6531. tempIndex = 2;
  6532. }
  6533. else
  6534. {
  6535. tempIndex = gun_index;
  6536. }
  6537. for (int index = 0; index < AC_QUANTITY; index++)
  6538. {
  6539. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6540. {
  6541. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6542. }
  6543. }
  6544. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6545. }
  6546. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6547. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6548. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6549. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6550. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6551. }
  6552. //***********************************************(6)SOC******************************************************/
  6553. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6554. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6555. (dataType == ReadingContext_Trigger))
  6556. {
  6557. 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))
  6558. {
  6559. //idx_sample=5;
  6560. //sampledValue = NULL;
  6561. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6562. {
  6563. tempIndex = ((gun_index==2) ? 1: 0);
  6564. }
  6565. else
  6566. {
  6567. tempIndex = gun_index;
  6568. }
  6569. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6570. {
  6571. //tempIndex = ((gun_index==2) ? 1: 0);
  6572. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6573. {
  6574. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6575. {
  6576. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6577. }
  6578. }
  6579. }
  6580. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6581. {
  6582. //tempIndex = ((gun_index==2) ? 1: 0);
  6583. for (int index = 0; index < CCS_QUANTITY; index++)
  6584. {
  6585. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6586. {
  6587. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6588. }
  6589. }
  6590. }
  6591. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6592. {
  6593. //tempIndex = ((gun_index==2) ? 1: 0);
  6594. for (int index = 0; index < GB_QUANTITY; index++)
  6595. {
  6596. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6597. {
  6598. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6599. }
  6600. }
  6601. }
  6602. else if(gunType[gun_index] == GUN_TYPE_DO)
  6603. {
  6604. //tempIndex = ((gun_index==2) ? 1: 0);
  6605. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6606. {
  6607. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6608. {
  6609. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6610. }
  6611. }
  6612. }
  6613. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6614. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6615. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6616. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6617. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6618. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6619. }
  6620. }
  6621. //********************************(7)Current.Import L2************************************************/
  6622. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6623. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6624. (dataType == ReadingContext_Trigger))
  6625. {
  6626. // Only for AC 3 phase
  6627. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6628. {
  6629. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6630. {
  6631. tempIndex = 2;
  6632. }
  6633. else
  6634. {
  6635. tempIndex = gun_index;
  6636. }
  6637. for (int index = 0; index < AC_QUANTITY; index++)
  6638. {
  6639. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6640. {
  6641. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6642. }
  6643. }
  6644. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6645. }
  6646. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6647. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6648. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6649. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6650. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6651. }
  6652. //********************************(8)Current.Import L3************************************************/
  6653. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6654. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6655. (dataType == ReadingContext_Trigger))
  6656. {
  6657. // Only for AC 3 phase
  6658. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6659. {
  6660. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6661. {
  6662. tempIndex = 2;
  6663. }
  6664. else
  6665. {
  6666. tempIndex = gun_index;
  6667. }
  6668. for (int index = 0; index < AC_QUANTITY; index++)
  6669. {
  6670. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6671. {
  6672. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6673. }
  6674. }
  6675. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6676. }
  6677. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6678. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6679. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6680. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6681. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6682. }
  6683. //***********************************************(9)VOLTAGE L2******************************************************/
  6684. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6685. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6686. (dataType == ReadingContext_Trigger))
  6687. {
  6688. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6689. {
  6690. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6691. {
  6692. tempIndex = 2;
  6693. }
  6694. else
  6695. {
  6696. tempIndex = gun_index;
  6697. }
  6698. for (int index = 0; index < AC_QUANTITY; index++)
  6699. {
  6700. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6701. {
  6702. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6703. }
  6704. }
  6705. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6706. }
  6707. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6708. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6709. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6710. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6711. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6712. }
  6713. //***********************************************(10)VOLTAGE L3******************************************************/
  6714. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6715. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6716. (dataType == ReadingContext_Trigger))
  6717. {
  6718. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6719. {
  6720. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6721. {
  6722. tempIndex = 2;
  6723. }
  6724. else
  6725. {
  6726. tempIndex = gun_index;
  6727. }
  6728. for (int index = 0; index < AC_QUANTITY; index++)
  6729. {
  6730. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6731. {
  6732. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6733. }
  6734. }
  6735. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6736. }
  6737. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6738. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6739. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6740. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6741. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6742. }
  6743. //***********************************************(11)Current.Offered******************************************************/
  6744. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6745. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6746. (dataType == ReadingContext_Trigger))
  6747. {
  6748. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6749. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6750. {
  6751. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6752. {
  6753. tempIndex = ((gun_index==2) ? 1: 0);
  6754. }
  6755. else
  6756. {
  6757. tempIndex = gun_index;
  6758. }
  6759. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6760. {
  6761. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6762. {
  6763. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  6764. }
  6765. } // END OF FOR CHAdeMO_QUANTITY
  6766. }
  6767. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6768. {
  6769. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6770. {
  6771. tempIndex = ((gun_index==2) ? 1: 0);
  6772. }
  6773. else
  6774. {
  6775. tempIndex = gun_index;
  6776. }
  6777. for (int index = 0; index < CCS_QUANTITY; index++)
  6778. {
  6779. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6780. {
  6781. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  6782. }
  6783. } // END OF CCS_QUANTITY
  6784. }
  6785. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6786. {
  6787. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6788. {
  6789. tempIndex = ((gun_index==2) ? 1: 0);
  6790. }
  6791. else
  6792. {
  6793. tempIndex = gun_index;
  6794. }
  6795. for (int index = 0; index < GB_QUANTITY; index++)
  6796. {
  6797. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6798. {
  6799. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  6800. }
  6801. } // END OF GB_QUANTITY
  6802. }
  6803. else if(gunType[gun_index] == GUN_TYPE_DO)
  6804. {
  6805. tempIndex = gun_index;
  6806. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6807. {
  6808. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6809. {
  6810. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  6811. }
  6812. }
  6813. }
  6814. else
  6815. {
  6816. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6817. {
  6818. tempIndex = 2;
  6819. }
  6820. else
  6821. {
  6822. tempIndex = gun_index;
  6823. }
  6824. for (int index = 0; index < AC_QUANTITY; index++)
  6825. {
  6826. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6827. {
  6828. uint16_t currentOffer;
  6829. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  6830. {
  6831. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  6832. }
  6833. else
  6834. {
  6835. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  6836. }
  6837. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  6838. }
  6839. }
  6840. }
  6841. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6842. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6843. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  6844. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6845. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6846. }
  6847. //***********************************************(12)Power.Offered******************************************************/
  6848. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6849. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6850. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  6851. {
  6852. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6853. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6854. {
  6855. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6856. {
  6857. tempIndex = ((gun_index==2) ? 1: 0);
  6858. }
  6859. else
  6860. {
  6861. tempIndex = gun_index;
  6862. }
  6863. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6864. {
  6865. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6866. {
  6867. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  6868. }
  6869. } // END OF FOR CHAdeMO_QUANTITY
  6870. }
  6871. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6872. {
  6873. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6874. {
  6875. tempIndex = ((gun_index==2) ? 1: 0);
  6876. }
  6877. else
  6878. {
  6879. tempIndex = gun_index;
  6880. }
  6881. for (int index = 0; index < CCS_QUANTITY; index++)
  6882. {
  6883. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6884. {
  6885. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  6886. }
  6887. } // END OF CCS_QUANTITY
  6888. }
  6889. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6890. {
  6891. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6892. {
  6893. tempIndex = ((gun_index==2) ? 1: 0);
  6894. }
  6895. else
  6896. {
  6897. tempIndex = gun_index;
  6898. }
  6899. for (int index = 0; index < GB_QUANTITY; index++)
  6900. {
  6901. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6902. {
  6903. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  6904. }
  6905. } // END OF GB_QUANTITY
  6906. }
  6907. else if(gunType[gun_index] == GUN_TYPE_DO)
  6908. {
  6909. tempIndex = gun_index;
  6910. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6911. {
  6912. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6913. {
  6914. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  6915. }
  6916. }
  6917. }
  6918. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  6919. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  6920. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  6921. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  6922. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  6923. }
  6924. // Message create ====================================================================================================
  6925. if(TRUE)
  6926. {
  6927. json_object *MeterValueReq = json_object_new_object();
  6928. json_object *MeterValues = json_object_new_array();
  6929. json_object *sampledValues = json_object_new_array();
  6930. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  6931. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  6932. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  6933. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  6934. {
  6935. json_object *MeterValue = json_object_new_object();
  6936. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6937. {
  6938. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6939. {
  6940. json_object *sampledValue = json_object_new_object();
  6941. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6942. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6943. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6944. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6945. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6946. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6947. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6948. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6949. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6950. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6951. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6952. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6953. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6954. json_object_array_add(sampledValues, sampledValue);
  6955. }
  6956. }
  6957. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6958. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6959. json_object_array_add(MeterValues, MeterValue);
  6960. }
  6961. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6962. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6963. ,gun_index + 1
  6964. ,MESSAGE_TYPE_CALL
  6965. ,guid
  6966. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6967. json_object_put(MeterValueReq);
  6968. }
  6969. // Put request guid to hash map
  6970. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6971. 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*/)
  6972. {
  6973. result = PASS;
  6974. //DEBUG_INFO("MeterValues mapitem pass\n");
  6975. }
  6976. if((dataType != ReadingContext_Trigger) &&
  6977. (dataType != ReadingContext_Sample_Clock) &&
  6978. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  6979. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6980. else
  6981. {
  6982. if(FirstHeartBeat)
  6983. LWS_Send(queuedata +2);
  6984. }
  6985. return result;
  6986. }
  6987. int sendLogStatusNotificationRequest(char *status)
  6988. {
  6989. mtrace();
  6990. int result = PASS;
  6991. char message[4096]={0};
  6992. char guid[37]={0};
  6993. char tempdata[128]={0};
  6994. json_object *LogStatusNotification = json_object_new_object();
  6995. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6996. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  6997. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  6998. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  6999. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7000. random_uuid(guid);
  7001. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7002. json_object_put(LogStatusNotification);
  7003. LWS_Send(message);
  7004. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7005. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7006. {
  7007. result = PASS;
  7008. }
  7009. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7010. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7011. return result;
  7012. }
  7013. int sendSecurityEventNotificationRequest()
  7014. {
  7015. mtrace();
  7016. int result = PASS;
  7017. char message[4096]={0};
  7018. char guid[37]={0};
  7019. char tempdata[128]={0};
  7020. json_object *SecurityEventNotification = json_object_new_object();
  7021. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7022. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7023. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7024. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7025. random_uuid(guid);
  7026. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7027. json_object_put(SecurityEventNotification);
  7028. LWS_Send(message);
  7029. sprintf(tempdata, "SecurityEventNotification,0");
  7030. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7031. {
  7032. result = PASS;
  7033. }
  7034. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7035. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7036. return result;
  7037. }
  7038. int sendSignCertificateRequest()
  7039. {
  7040. mtrace();
  7041. int result = PASS;
  7042. char message[4096]={0};
  7043. char guid[37]={0};
  7044. char tempdata[128]={0};
  7045. json_object *SignCertificate = json_object_new_object();
  7046. DEBUG_INFO("sendSignCertificateRequest...\n");
  7047. // Read csr file content
  7048. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7049. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  7050. char *line = NULL;
  7051. size_t len = 0;
  7052. while(getline(&line, &len, fp) != -1)
  7053. {
  7054. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7055. {
  7056. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7057. }
  7058. }
  7059. fclose(fp);
  7060. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7061. random_uuid(guid);
  7062. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7063. json_object_put(SignCertificate);
  7064. LWS_Send(message);
  7065. sprintf(tempdata, "SignCertificate,0");
  7066. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7067. {
  7068. result = PASS;
  7069. }
  7070. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7071. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7072. return result;
  7073. }
  7074. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7075. {
  7076. mtrace();
  7077. int result = PASS;
  7078. char message[110]={0};
  7079. char guid[37]={0};
  7080. char tempdata[65]={0};
  7081. json_object *FirmwareStatusNotification = json_object_new_object();
  7082. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7083. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7084. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7085. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7086. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7087. random_uuid(guid);
  7088. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7089. json_object_put(FirmwareStatusNotification);
  7090. LWS_Send(message);
  7091. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7092. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7093. {
  7094. result = PASS;
  7095. }
  7096. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7097. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7098. return result;
  7099. }
  7100. //==========================================
  7101. // send confirm routine
  7102. //==========================================
  7103. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7104. {
  7105. mtrace();
  7106. int result = FAIL;
  7107. char message[100]={0};
  7108. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7109. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7110. LWS_Send(message);
  7111. result = TRUE;
  7112. return result;
  7113. }
  7114. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7115. {
  7116. mtrace();
  7117. int result = FAIL;
  7118. char message[100]={0};
  7119. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7120. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7121. LWS_Send(message);
  7122. result = TRUE;
  7123. return result;
  7124. }
  7125. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7126. {
  7127. mtrace();
  7128. int result = FAIL;
  7129. char message[100]={0};
  7130. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7131. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7132. LWS_Send(message);
  7133. result = TRUE;
  7134. return result;
  7135. }
  7136. int sendClearCacheConfirmation(char *uuid,char *payload)
  7137. {
  7138. mtrace();
  7139. int result = FAIL;
  7140. char message[500]={0};
  7141. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7142. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7143. LWS_Send(message);
  7144. return result;
  7145. }
  7146. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7147. {
  7148. mtrace();
  7149. int result = FAIL;
  7150. char message[500]={0};
  7151. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7152. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7153. LWS_Send(message);
  7154. return result;
  7155. }
  7156. int sendDataTransferConfirmation(char *uuid,char *payload)
  7157. {
  7158. mtrace();
  7159. char statusStr[20]={0};
  7160. char dataStr[10]={0};
  7161. char sstr[20]={0};
  7162. int c = 0;
  7163. char *loc;
  7164. int result = FAIL;
  7165. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7166. /**********************status**************************/
  7167. loc = strstr(payload, "status");
  7168. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7169. c = 0;
  7170. while (loc[3+strlen("status")+c] != '\"')
  7171. {
  7172. sstr[c] = loc[3+strlen("status")+c];
  7173. c++;
  7174. }
  7175. sstr[c] = '\0';
  7176. strcpy(statusStr, sstr);
  7177. /**********************data**************************/
  7178. loc = strstr(payload, "data");
  7179. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7180. c = 0;
  7181. while (loc[3+strlen("data")+c] != '\"')
  7182. {
  7183. sstr[c] = loc[3+strlen("data")+c];
  7184. c++;
  7185. }
  7186. sstr[c] = '\0';
  7187. strcpy(dataStr, sstr);
  7188. return result;
  7189. }
  7190. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7191. {
  7192. mtrace();
  7193. int result = FAIL;
  7194. char message[1000]={0};
  7195. int CompositeScheduleIndex = 0;
  7196. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7197. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7198. if(nPeriod == 0)
  7199. {
  7200. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7201. {
  7202. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7203. ,MESSAGE_TYPE_CALLRESULT
  7204. ,uuid
  7205. ,payload
  7206. ,connectorIdInt);
  7207. }
  7208. else
  7209. {
  7210. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7211. ,MESSAGE_TYPE_CALLRESULT
  7212. ,uuid
  7213. ,payload
  7214. ,connectorIdInt
  7215. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7216. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7217. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7218. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7219. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7220. }
  7221. }
  7222. else
  7223. {
  7224. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7225. ,MESSAGE_TYPE_CALLRESULT
  7226. ,uuid
  7227. ,payload
  7228. ,connectorIdInt
  7229. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7230. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7231. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7232. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7233. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7234. {
  7235. if (idx_sample == 0)
  7236. {
  7237. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7238. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7239. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7240. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7241. }
  7242. else
  7243. {
  7244. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7245. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7246. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7247. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7248. }
  7249. }
  7250. sprintf(message + strlen(message), "]}}]");
  7251. }
  7252. LWS_Send(message);
  7253. result = TRUE;
  7254. return result;
  7255. }
  7256. int sendGetConfigurationConfirmation(char *uuid)
  7257. {
  7258. mtrace();
  7259. int result = FAIL;
  7260. int MaxKeySupported = 0;
  7261. int sentConfigurationNumber= 0;
  7262. int sentunConfigurationNumber= 0;
  7263. char message[1024*10]={0};
  7264. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7265. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7266. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7267. ,MESSAGE_TYPE_CALLRESULT
  7268. ,uuid );
  7269. //configuration key
  7270. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7271. {
  7272. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7273. {
  7274. if (sentConfigurationNumber == 0)
  7275. {
  7276. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7277. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7278. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7279. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7280. }
  7281. else
  7282. {
  7283. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7284. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7285. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7286. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7287. }
  7288. sentConfigurationNumber = sentConfigurationNumber + 1;
  7289. }
  7290. }
  7291. sprintf(message + strlen(message), "]");
  7292. if(UnknownKeynum != 0)
  7293. {
  7294. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7295. //unkown key
  7296. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7297. {
  7298. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7299. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7300. if(sentunConfigurationNumber == 0)
  7301. {
  7302. sprintf(message + strlen(message), "\"%s\""
  7303. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7304. }
  7305. else
  7306. {
  7307. sprintf(message + strlen(message), ",\"%s\""
  7308. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7309. }
  7310. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7311. }
  7312. sprintf(message + strlen(message), "]");
  7313. }
  7314. sprintf(message + strlen(message), "}]");
  7315. LWS_Send(message);
  7316. return result;
  7317. }
  7318. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7319. {
  7320. mtrace();
  7321. int result = FAIL;
  7322. char message[400]={0};
  7323. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7324. if(strcmp(payload,"")==0)
  7325. {
  7326. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7327. }
  7328. else
  7329. {
  7330. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7331. }
  7332. LWS_Send(message);
  7333. result = TRUE;
  7334. return result;
  7335. }
  7336. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7337. {
  7338. mtrace();
  7339. int result = FAIL;
  7340. char message[80]={0};
  7341. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7342. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  7343. LWS_Send(message);
  7344. result = TRUE;
  7345. return result;
  7346. }
  7347. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7348. {
  7349. mtrace();
  7350. int result = FAIL;
  7351. char message[80]={0};
  7352. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7353. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7354. LWS_Send(message);
  7355. result = TRUE;
  7356. return result;
  7357. }
  7358. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7359. {
  7360. mtrace();
  7361. int result = FAIL;
  7362. char message[80]={0};
  7363. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7364. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7365. LWS_Send(message);
  7366. result = TRUE;
  7367. return result;
  7368. }
  7369. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7370. {
  7371. mtrace();
  7372. int result = FAIL;
  7373. char message[80]={0};
  7374. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7375. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7376. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7377. LWS_Send(message);
  7378. result = TRUE;
  7379. return result;
  7380. }
  7381. int sendResetConfirmation(char *uuid,char *payload)
  7382. {
  7383. mtrace();
  7384. int result = FAIL;
  7385. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7386. char message[80]={0};
  7387. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  7388. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7389. LWS_Send(message);
  7390. result = TRUE;
  7391. return result;
  7392. }
  7393. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7394. {
  7395. mtrace();
  7396. int result = FAIL;
  7397. char message[500]={0};
  7398. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7399. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7400. LWS_Send(message);
  7401. result = TRUE;
  7402. return result;
  7403. }
  7404. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7405. {
  7406. mtrace();
  7407. int result = FAIL;
  7408. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7409. char message[80]={0};
  7410. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7411. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7412. LWS_Send(message);
  7413. result = TRUE;
  7414. return result;
  7415. }
  7416. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7417. {
  7418. mtrace();
  7419. int result = FAIL;
  7420. char message[80]={0};
  7421. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7422. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7423. LWS_Send(message);
  7424. result = TRUE;
  7425. return result;
  7426. }
  7427. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7428. {
  7429. mtrace();
  7430. int result = FAIL;
  7431. char message[80]={0};
  7432. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7433. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7434. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7435. LWS_Send(message);
  7436. result = TRUE;
  7437. return result;
  7438. }
  7439. int sendUpdateFirmwareConfirmation(char *uuid)
  7440. {
  7441. mtrace();
  7442. int result = FAIL;
  7443. char message[60]={0};
  7444. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7445. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7446. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7447. LWS_Send(message);
  7448. result = TRUE;
  7449. return result;
  7450. }
  7451. int sendCertificateSignedConfirmation(char *uuid)
  7452. {
  7453. mtrace();
  7454. int result = PASS;
  7455. char message[4096]={0};
  7456. json_object *CertificateSigned = json_object_new_object();
  7457. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7458. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  7459. sprintf(message,"[%d,\"%s\",%s]"
  7460. ,MESSAGE_TYPE_CALLRESULT
  7461. ,uuid
  7462. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7463. json_object_put(CertificateSigned);
  7464. LWS_Send(message);
  7465. return result;
  7466. }
  7467. int sendDeleteCertificateConfirmation(char *uuid)
  7468. {
  7469. mtrace();
  7470. int result = PASS;
  7471. char message[4096]={0};
  7472. json_object *DeleteCertificate = json_object_new_object();
  7473. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7474. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  7475. sprintf(message,"[%d,\"%s\",%s]"
  7476. ,MESSAGE_TYPE_CALLRESULT
  7477. ,uuid
  7478. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7479. json_object_put(DeleteCertificate);
  7480. LWS_Send(message);
  7481. return result;
  7482. }
  7483. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7484. {
  7485. mtrace();
  7486. int result = PASS;
  7487. char message[4096]={0};
  7488. json_object *ExtendedTriggerMessage = json_object_new_object();
  7489. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7490. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  7491. sprintf(message,"[%d,\"%s\",%s]"
  7492. ,MESSAGE_TYPE_CALLRESULT
  7493. ,uuid
  7494. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7495. json_object_put(ExtendedTriggerMessage);
  7496. LWS_Send(message);
  7497. return result;
  7498. }
  7499. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7500. {
  7501. mtrace();
  7502. int result = PASS;
  7503. char message[4096]={0};
  7504. json_object *GetInstalledCertificateIds = json_object_new_object();
  7505. json_object *certificateHashDataDatas = json_object_new_array();
  7506. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7507. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  7508. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7509. {
  7510. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7511. {
  7512. json_object *certificateHashData = json_object_new_object();
  7513. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7514. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7515. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7516. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7517. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7518. }
  7519. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7520. }
  7521. else
  7522. {
  7523. json_object_put(certificateHashDataDatas);
  7524. }
  7525. sprintf(message,"[%d,\"%s\",%s]"
  7526. ,MESSAGE_TYPE_CALLRESULT
  7527. ,uuid
  7528. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7529. json_object_put(GetInstalledCertificateIds);
  7530. LWS_Send(message);
  7531. return result;
  7532. }
  7533. int sendGetLogConfirmation(char *uuid)
  7534. {
  7535. mtrace();
  7536. int result = PASS;
  7537. char message[4096]={0};
  7538. json_object *GetLog = json_object_new_object();
  7539. DEBUG_INFO("sendGetLogConfirmation...\n");
  7540. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  7541. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  7542. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  7543. sprintf(message,"[%d,\"%s\",%s]"
  7544. ,MESSAGE_TYPE_CALLRESULT
  7545. ,uuid
  7546. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7547. json_object_put(GetLog);
  7548. LWS_Send(message);
  7549. return result;
  7550. }
  7551. int sendInstallCertificateConfirmation(char *uuid)
  7552. {
  7553. mtrace();
  7554. int result = PASS;
  7555. char message[4096]={0};
  7556. json_object *InstallCertificate = json_object_new_object();
  7557. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7558. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  7559. sprintf(message,"[%d,\"%s\",%s]"
  7560. ,MESSAGE_TYPE_CALLRESULT
  7561. ,uuid
  7562. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7563. json_object_put(InstallCertificate);
  7564. LWS_Send(message);
  7565. return result;
  7566. }
  7567. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7568. {
  7569. mtrace();
  7570. int result = PASS;
  7571. char message[4096]={0};
  7572. json_object *SignedUpdateFirmware = json_object_new_object();
  7573. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7574. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  7575. sprintf(message,"[%d,\"%s\",%s]"
  7576. ,MESSAGE_TYPE_CALLRESULT
  7577. ,uuid
  7578. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7579. json_object_put(SignedUpdateFirmware);
  7580. LWS_Send(message);
  7581. return result;
  7582. }
  7583. int sendUnknownConfirmation(char *uuid)
  7584. {
  7585. mtrace();
  7586. int result = PASS;
  7587. char message[256]={0};
  7588. DEBUG_INFO("sendUnknownConfirmation...\n");
  7589. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7590. LWS_Send(message);
  7591. return result;
  7592. }
  7593. //==========================================
  7594. // Handle server request routine Start
  7595. //==========================================
  7596. int handleCancelReservationRequest(char *uuid, char *payload)
  7597. {
  7598. mtrace();
  7599. int result = FAIL;
  7600. int gunNO = 0;
  7601. int reservationIdInt = -1;
  7602. char comfirmstr[20];
  7603. DEBUG_INFO("handleCancelReservationRequest...\n");
  7604. json_object *CancelReservation;
  7605. CancelReservation = json_tokener_parse(payload);
  7606. if(!is_error(CancelReservation))
  7607. {
  7608. // Required data
  7609. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7610. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7611. }
  7612. json_object_put(CancelReservation);
  7613. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7614. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7615. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7616. if(reservationIdInt != -1)
  7617. {
  7618. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7619. //check Transaction active
  7620. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7621. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7622. {
  7623. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7624. {
  7625. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7626. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7627. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7628. {
  7629. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7630. }
  7631. else
  7632. {
  7633. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7634. }
  7635. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7636. goto end;
  7637. }
  7638. }
  7639. for (int index = 0; index < CCS_QUANTITY; index++)
  7640. {
  7641. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7642. {
  7643. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7644. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7645. if(gunType[2] == GUN_TYPE_CCS)
  7646. {
  7647. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7648. }
  7649. else
  7650. {
  7651. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7652. }
  7653. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7654. goto end;
  7655. }
  7656. }
  7657. for (int index = 0; index < GB_QUANTITY; index++)
  7658. {
  7659. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7660. {
  7661. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7662. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7663. if(gunType[2] == GUN_TYPE_GBT)
  7664. {
  7665. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7666. }
  7667. else
  7668. {
  7669. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7670. }
  7671. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7672. goto end;
  7673. }
  7674. }
  7675. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7676. {
  7677. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7678. {
  7679. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7680. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7681. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7682. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7683. goto end;
  7684. }
  7685. }
  7686. for (int index = 0; index < AC_QUANTITY; index++)
  7687. {
  7688. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7689. {
  7690. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7691. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7692. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7693. {
  7694. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7695. }
  7696. else
  7697. {
  7698. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7699. }
  7700. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7701. goto end;
  7702. }
  7703. }
  7704. }
  7705. //The reservationId does NOT match the reservationId
  7706. sendCancelReservationConfirmation(uuid, comfirmstr);
  7707. end:
  7708. // Fill in ocpp packet uuid
  7709. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  7710. return result;
  7711. }
  7712. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7713. {
  7714. mtrace();
  7715. int result = FAIL;
  7716. int gunIndex = -1;
  7717. char typeStr[16]={0};
  7718. char comfirmstr[20];
  7719. int specificId = FALSE;
  7720. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7721. json_object *ChangeAvailability;
  7722. ChangeAvailability = json_tokener_parse(payload);
  7723. if(!is_error(ChangeAvailability))
  7724. {
  7725. // Required data
  7726. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7727. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7728. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7729. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7730. }
  7731. json_object_put(ChangeAvailability);
  7732. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7733. {
  7734. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7735. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7736. }
  7737. else if(gunIndex == 0)
  7738. {
  7739. for(int i=0; i < gunTotalNumber; i++)
  7740. {
  7741. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  7742. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  7743. }
  7744. }
  7745. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7746. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7747. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  7748. {
  7749. specificId = TRUE;
  7750. }
  7751. if(specificId == FALSE)
  7752. goto end;
  7753. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7754. {
  7755. //----------------------gunIndex is 0 ------------------------------------------------//
  7756. if(gunIndex == 0)
  7757. {
  7758. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7759. {
  7760. for(int i=0; i < gunTotalNumber; i++)
  7761. {
  7762. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7763. {
  7764. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7765. {
  7766. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7767. {
  7768. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7769. goto end;
  7770. }
  7771. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7772. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7773. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7774. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7775. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7776. {
  7777. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7778. goto end;
  7779. }
  7780. }
  7781. }//END FOR CHAdeMO_QUANTITY
  7782. for (int index = 0; index < CCS_QUANTITY; index++)
  7783. {
  7784. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7785. {
  7786. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7787. {
  7788. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7789. goto end;
  7790. }
  7791. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7792. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7793. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7794. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7795. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7796. {
  7797. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7798. goto end;
  7799. }
  7800. }
  7801. }//END FOR CCS_QUANTITY
  7802. for (int index = 0; index < GB_QUANTITY; index++)
  7803. {
  7804. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7805. {
  7806. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7807. {
  7808. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7809. goto end;
  7810. }
  7811. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7812. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7813. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7814. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7815. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7816. {
  7817. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7818. goto end;
  7819. }
  7820. }
  7821. }// END FOR GB_QUANTITY
  7822. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7823. {
  7824. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7825. {
  7826. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7827. {
  7828. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7829. goto end;
  7830. }
  7831. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7832. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7833. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7834. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7835. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7836. {
  7837. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7838. goto end;
  7839. }
  7840. }
  7841. }// END FOR GENERAL_GUN_QUANTITY
  7842. for (int index = 0; index < AC_QUANTITY; index++)
  7843. {
  7844. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7845. {
  7846. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7847. {
  7848. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7849. goto end;
  7850. }
  7851. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7852. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7853. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7854. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7855. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7856. {
  7857. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7858. goto end;
  7859. }
  7860. }
  7861. }//END FOR AC_QUANTITY
  7862. }// END FOR gunTotalNumber
  7863. }
  7864. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7865. {
  7866. for(int i=0; i < gunTotalNumber; i++)
  7867. {
  7868. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7869. {
  7870. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7871. goto end;
  7872. }
  7873. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7874. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7875. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7876. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7877. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7878. {
  7879. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7880. goto end;
  7881. }
  7882. }
  7883. }
  7884. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7885. goto end;
  7886. }
  7887. //----------------------gunIndex is not 0 ------------------------------------------------//
  7888. //check Transaction active
  7889. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7890. {
  7891. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7892. {
  7893. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7894. {
  7895. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7896. goto end;
  7897. }
  7898. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7899. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7900. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7901. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7902. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7903. {
  7904. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7905. goto end;
  7906. }
  7907. else
  7908. {
  7909. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7910. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7911. goto end;
  7912. }
  7913. }
  7914. }//END FOR CHAdeMO_QUANTITY
  7915. for (int index = 0; index < CCS_QUANTITY; index++)
  7916. {
  7917. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7918. {
  7919. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7920. {
  7921. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7922. goto end;
  7923. }
  7924. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7925. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7926. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7927. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7928. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7929. {
  7930. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7931. goto end;
  7932. }
  7933. else
  7934. {
  7935. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7936. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7937. goto end;
  7938. }
  7939. }
  7940. }//END FOR CCS_QUANTITY
  7941. for (int index = 0; index < GB_QUANTITY; index++)
  7942. {
  7943. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7944. {
  7945. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7946. {
  7947. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7948. goto end;
  7949. }
  7950. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7951. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7952. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7953. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7954. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7955. {
  7956. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7957. goto end;
  7958. }
  7959. else
  7960. {
  7961. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7962. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7963. goto end;
  7964. }
  7965. }
  7966. }// END FOR GB_QUANTITY
  7967. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7968. {
  7969. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7970. {
  7971. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7972. {
  7973. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7974. goto end;
  7975. }
  7976. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7977. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7978. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7979. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7980. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7981. {
  7982. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7983. goto end;
  7984. }
  7985. else
  7986. {
  7987. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7988. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7989. goto end;
  7990. }
  7991. }
  7992. }// END FOR GENERAL_GUN_QUANTITY
  7993. for (int index = 0; index < AC_QUANTITY; index++)
  7994. {
  7995. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7996. {
  7997. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7998. {
  7999. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8000. goto end;
  8001. }
  8002. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8003. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8004. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8005. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8006. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8007. {
  8008. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8009. goto end;
  8010. }
  8011. else
  8012. {
  8013. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8014. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8015. goto end;
  8016. }
  8017. }
  8018. }//END FOR AC_QUANTITY
  8019. }//END FOR AvailabilityTypeStr[Inoperative]
  8020. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8021. {
  8022. //----------------------gunIndex is 0 ------------------------------------------------//
  8023. if(gunIndex == 0)
  8024. {
  8025. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8026. {
  8027. for(int i=0; i < gunTotalNumber; i++)
  8028. {
  8029. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8030. {
  8031. 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
  8032. {
  8033. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8034. goto end;
  8035. }
  8036. }//END FOR CHAdeMO_QUANTITY
  8037. for (int index = 0; index < CCS_QUANTITY; index++)
  8038. {
  8039. 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
  8040. {
  8041. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8042. goto end;
  8043. }
  8044. }//END FOR CCS_QUANTITY
  8045. for (int index = 0; index < GB_QUANTITY; index++)
  8046. {
  8047. 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
  8048. {
  8049. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8050. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8051. goto end;
  8052. }
  8053. }// END FOR GB_QUANTITY
  8054. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8055. {
  8056. 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
  8057. {
  8058. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8059. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8060. goto end;
  8061. }
  8062. }// END FOR GENERAL_GUN_QUANTITY
  8063. for (int index = 0; index < AC_QUANTITY; index++)
  8064. {
  8065. 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
  8066. {
  8067. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8068. goto end;
  8069. }
  8070. }//END FOR CHAdeMO_QUANTITY
  8071. }// END FOR gunTotalNumber
  8072. }
  8073. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8074. {
  8075. for(int i=0; i < gunTotalNumber; i++)
  8076. {
  8077. for (int index = 0; index < AC_QUANTITY; index++)
  8078. {
  8079. 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
  8080. {
  8081. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8082. goto end;
  8083. }
  8084. }//END FOR CHAdeMO_QUANTITY
  8085. } // END FOR gunTotalNumber
  8086. }
  8087. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8088. goto end;
  8089. }
  8090. //----------------------gunIndex is not 0 ------------------------------------------------//
  8091. //check Transaction active
  8092. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8093. {
  8094. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8095. {
  8096. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8097. goto end;
  8098. }
  8099. }//END FOR CHAdeMO_QUANTITY
  8100. for (int index = 0; index < CCS_QUANTITY; index++)
  8101. {
  8102. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8103. {
  8104. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8105. goto end;
  8106. }
  8107. }//END FOR CCS_QUANTITY
  8108. for (int index = 0; index < GB_QUANTITY; index++)
  8109. {
  8110. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8111. {
  8112. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8113. goto end;
  8114. }
  8115. }// END FOR GB_QUANTITY
  8116. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8117. {
  8118. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8119. {
  8120. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8121. goto end;
  8122. }
  8123. }// END FOR GENERAL_GUN_QUANTITY
  8124. for (int index = 0; index < AC_QUANTITY; index++)
  8125. {
  8126. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8127. {
  8128. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8129. goto end;
  8130. }
  8131. }//END FOR AC_QUANTITY
  8132. }//END FOR AvailabilityTypeStr[Operative]
  8133. end:
  8134. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8135. {
  8136. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8137. }
  8138. else
  8139. {
  8140. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8141. }
  8142. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8143. {
  8144. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8145. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8146. }
  8147. else if(gunIndex == 0)
  8148. {
  8149. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8150. {
  8151. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8152. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8153. }
  8154. }
  8155. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8156. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8157. return result;
  8158. }
  8159. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8160. {
  8161. mtrace();
  8162. int result = FAIL;
  8163. char keystr[40]={0};
  8164. char valuestr[256]={0};
  8165. char comfirmstr[20]={0};
  8166. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8167. json_object *ChangeConfiguration;
  8168. ChangeConfiguration = json_tokener_parse(payload);
  8169. if(!is_error(ChangeConfiguration))
  8170. {
  8171. // Required data
  8172. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8173. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8174. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  8175. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8176. }
  8177. json_object_put(ChangeConfiguration);
  8178. if((uuid==NULL) || (payload ==NULL) )
  8179. {
  8180. DEBUG_ERROR("Payload is null\n");
  8181. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8182. }
  8183. else
  8184. {
  8185. int status = setKeyValue(keystr, valuestr);
  8186. switch(status)
  8187. {
  8188. case ConfigurationStatus_Accepted:
  8189. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8190. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  8191. StoreConfigurationTable();
  8192. break;
  8193. case RebootRequired:
  8194. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8195. StoreConfigurationTable();
  8196. break;
  8197. case NotSupported:
  8198. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8199. break;
  8200. case ConfigurationStatus_Rejected:
  8201. default:
  8202. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8203. break;
  8204. }
  8205. }
  8206. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8207. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  8208. if((strcmp(keystr,"WebSocketPingInterval")==0) && (strcmp(comfirmstr,"Accepted")==0))
  8209. {
  8210. ChageWebSocketPingInterval(atoi(valuestr));
  8211. }
  8212. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8213. {
  8214. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8215. SetOcppConnStatus(FALSE);
  8216. }
  8217. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8218. {
  8219. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8220. }
  8221. return result;
  8222. }
  8223. int handleClearCacheRequest(char *uuid, char *payload)
  8224. {
  8225. mtrace();
  8226. int result = FAIL;
  8227. char comfirmstr[20];
  8228. char rmFileCmd[100]={0};
  8229. struct stat stats;
  8230. DEBUG_INFO("handleClearCacheRequest...\n");
  8231. stat("/Storage/OCPP", &stats);
  8232. // Check for directory existence
  8233. if (S_ISDIR(stats.st_mode) == 1)
  8234. {}
  8235. else
  8236. {
  8237. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8238. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  8239. system(rmFileCmd);
  8240. }
  8241. if(OCPP_cleanLocalCache())
  8242. {
  8243. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8244. }
  8245. else
  8246. {
  8247. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8248. }
  8249. sendClearCacheConfirmation(uuid, comfirmstr);
  8250. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8251. return result;
  8252. }
  8253. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8254. {
  8255. mtrace();
  8256. int result = FAIL;
  8257. int resultRename;
  8258. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8259. char chargingProfilePurposeStr[26]={0};
  8260. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8261. char tempchargingProfilePurposeStr[26]={0};
  8262. char str[100]={0};
  8263. char fname[200]={0};
  8264. char comfirmstr[20]={0};
  8265. char word[1600]={0};
  8266. int clearflag = FALSE;
  8267. int chargingProfileIdIsNULL = FALSE;
  8268. int connectorIsNULL = FALSE;
  8269. int chargingProfilePurposeIsNULL = FALSE;
  8270. int stackLevelIsNULL = FALSE;
  8271. //int GotoEnd = FALSE;
  8272. FILE *fptr1, *fptr2;
  8273. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  8274. int n_chargingProfile=0;
  8275. int isEmptyFile = FALSE;
  8276. char sLineWord[1600]={0};
  8277. char chargingProfiles[10][100]={0};
  8278. int ChargeProfileCount = 0;
  8279. int ch;
  8280. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8281. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8282. json_object *ClearChargingProfile;
  8283. ClearChargingProfile = json_tokener_parse(payload);
  8284. if(!is_error(ClearChargingProfile))
  8285. {
  8286. // Optional data
  8287. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8288. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8289. else
  8290. chargingProfileIdIsNULL = TRUE;
  8291. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8292. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8293. else
  8294. connectorIsNULL = TRUE;
  8295. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8296. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8297. else
  8298. chargingProfilePurposeIsNULL = TRUE;
  8299. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8300. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8301. else
  8302. stackLevelIsNULL = TRUE;
  8303. }
  8304. json_object_put(ClearChargingProfile);
  8305. if(connectorIsNULL == FALSE)
  8306. {
  8307. switch(connectorIdInt)
  8308. {
  8309. case 0:
  8310. if(chargingProfilePurposeIsNULL == TRUE)
  8311. {
  8312. int l = 0;
  8313. strcpy(fname, ChargePointMaxProfile_JSON);
  8314. if((access(fname,F_OK))!=-1)
  8315. {
  8316. strcpy(chargingProfiles[l], fname);
  8317. l = l + 1;
  8318. }
  8319. strcpy(fname, TxDefaultProfile_0_JSON);
  8320. if((access(fname,F_OK))!=-1)
  8321. {
  8322. strcpy(chargingProfiles[l], fname);
  8323. l = l + 1;
  8324. }
  8325. ChargeProfileCount = l;
  8326. }
  8327. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8328. {
  8329. strcpy(fname, ChargePointMaxProfile_JSON);
  8330. if((access(fname,F_OK))!=-1)
  8331. {
  8332. strcpy(chargingProfiles[0], fname);
  8333. ChargeProfileCount = 1;
  8334. }
  8335. }
  8336. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8337. {
  8338. strcpy(fname, TxDefaultProfile_0_JSON);
  8339. if((access(fname,F_OK))!=-1)
  8340. {
  8341. strcpy(chargingProfiles[0], fname);
  8342. ChargeProfileCount = 1;
  8343. }
  8344. }
  8345. break;
  8346. default:
  8347. if(chargingProfilePurposeIsNULL == TRUE)
  8348. {
  8349. int m = 0;
  8350. memset(fname, 0, ARRAY_SIZE(fname));
  8351. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8352. if((access(fname,F_OK))!=-1)
  8353. {
  8354. strcpy(chargingProfiles[m], fname);
  8355. m = m + 1;
  8356. }
  8357. memset(fname, 0, ARRAY_SIZE(fname));
  8358. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8359. if((access(fname,F_OK))!=-1)
  8360. {
  8361. strcpy(chargingProfiles[m], fname);
  8362. m = m + 1;
  8363. }
  8364. ChargeProfileCount = m;
  8365. }
  8366. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8367. {
  8368. //strcpy(fname, TxDefaultProfile_1_JSON);
  8369. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8370. if((access(fname,F_OK))!=-1)
  8371. {
  8372. strcpy(chargingProfiles[0], fname);
  8373. ChargeProfileCount = 1;
  8374. }
  8375. }
  8376. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8377. {
  8378. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8379. if((access(fname,F_OK))!=-1)
  8380. {
  8381. strcpy(chargingProfiles[0], fname);
  8382. ChargeProfileCount = 1;
  8383. }
  8384. //strcpy(fname, TxProfile_1_JSON);
  8385. }
  8386. //strcpy(fname, ChargePointMaxProfile_JSON );
  8387. break;
  8388. }
  8389. }
  8390. else // Check all Charging Profiles
  8391. {
  8392. int i = 0;
  8393. char fnametemp[200]={0};
  8394. ChargeProfileCount = 0;
  8395. //Check ChargePointMaxProfile.json exit
  8396. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8397. {
  8398. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  8399. i = i + 1;
  8400. }
  8401. //Check TxDefaultProfile_0.json exit
  8402. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8403. {
  8404. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  8405. i = i + 1;
  8406. }
  8407. //Check TxDefaultProfile_%d.json
  8408. for(int j=1; j <= gunTotalNumber; j++)
  8409. {
  8410. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8411. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8412. if((access(fnametemp,F_OK))!=-1)
  8413. {
  8414. strcpy(chargingProfiles[i], fnametemp);
  8415. i = i + 1;
  8416. }
  8417. }
  8418. //Check TxProfile_%d.json
  8419. for(int j=1; j <= gunTotalNumber; j++)
  8420. {
  8421. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8422. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8423. if((access(fnametemp,F_OK))!=-1)
  8424. {
  8425. strcpy(chargingProfiles[i], fnametemp);
  8426. i = i + 1;
  8427. }
  8428. }
  8429. ChargeProfileCount = i;
  8430. }// End connectorIsNULL is TRUE
  8431. if(ChargeProfileCount == 0)
  8432. {
  8433. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8434. goto end;
  8435. }
  8436. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8437. {
  8438. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8439. goto end;
  8440. }
  8441. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8442. {
  8443. memset(str, 0, ARRAY_SIZE(str));
  8444. // clear temp file
  8445. sprintf(str,"rm -f %s",temp);
  8446. system(str);
  8447. for(int k=0; k < ChargeProfileCount; k++)
  8448. {
  8449. memset(str, 0, ARRAY_SIZE(str));
  8450. //clear file in C
  8451. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8452. system(str);
  8453. }
  8454. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8455. goto end;
  8456. }
  8457. else if(connectorIsNULL == TRUE)
  8458. {
  8459. for(int k=0; k < ChargeProfileCount; k++)
  8460. {
  8461. fptr1 = fopen(chargingProfiles[k], "r");
  8462. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  8463. //Check Charging Profile Count
  8464. while(fscanf(fptr1, "%s", word) != EOF)
  8465. {
  8466. //DEBUG_INFO("word=%s\n",word);
  8467. if(strstr(word, "chargingProfileId")!= NULL)
  8468. {
  8469. //DEBUG_INFO("test chargingProfileId \n");
  8470. n_chargingProfile = n_chargingProfile + 1;
  8471. //DEBUG_INFO("chargingProfileId Found\n");
  8472. }
  8473. }
  8474. rewind(fptr1);
  8475. //search Charging Profile Element
  8476. //int i= 0;
  8477. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8478. {
  8479. json_object *tmpProfilee;
  8480. tmpProfilee = json_tokener_parse(sLineWord);
  8481. if(!is_error(tmpProfilee))
  8482. {
  8483. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8484. {
  8485. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8486. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8487. }
  8488. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8489. {
  8490. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8491. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8492. }
  8493. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8494. {
  8495. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8496. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8497. }
  8498. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8499. {
  8500. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8501. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8502. }
  8503. }
  8504. json_object_put(tmpProfilee);
  8505. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8506. {
  8507. //------- not write to fptr2-------//
  8508. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8509. //clearflag = TRUE;
  8510. }
  8511. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8512. {
  8513. //------- not write to fptr2-------//
  8514. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8515. }
  8516. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8517. {
  8518. //------- not write to fptr2-------//
  8519. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8520. }
  8521. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8522. {
  8523. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8524. }
  8525. else
  8526. {
  8527. fprintf(fptr2, sLineWord);//writing data into file
  8528. }
  8529. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8530. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8531. if(clearflag == TRUE)
  8532. {
  8533. fclose(fptr1);
  8534. fclose(fptr2);
  8535. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8536. system(str);
  8537. // clear temp file
  8538. sprintf(str,"rm -f %s",temp);
  8539. system(str);
  8540. }
  8541. else
  8542. {
  8543. fclose(fptr1);
  8544. fclose(fptr2);
  8545. memset(str, 0, ARRAY_SIZE(str));
  8546. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8547. system(str);
  8548. resultRename = rename(temp, chargingProfiles[k]);
  8549. if(resultRename == 0)
  8550. {
  8551. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8552. }
  8553. else
  8554. {
  8555. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8556. }
  8557. if(comfirmstr[0]== 0)
  8558. {
  8559. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8560. }
  8561. //Check chargingProfile is empty file
  8562. /*------ Read the file ----------------*/
  8563. fptr1=fopen(chargingProfiles[k],"r");
  8564. ch=fgetc(fptr1);
  8565. rewind(fptr1);
  8566. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8567. if(ch!=EOF)
  8568. {
  8569. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8570. {
  8571. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8572. if(sLineWord[0]=='\0')
  8573. {
  8574. isEmptyFile = TRUE;
  8575. break;
  8576. }
  8577. else
  8578. {
  8579. isEmptyFile = FALSE;
  8580. break;
  8581. }
  8582. }
  8583. }
  8584. else
  8585. isEmptyFile = TRUE;
  8586. fclose(fptr1);
  8587. if(isEmptyFile == TRUE)
  8588. {
  8589. memset(str, 0, ARRAY_SIZE(str));
  8590. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8591. system(str);
  8592. }
  8593. }
  8594. }// End of while(int k=0; k < ChargePointCount; k++)
  8595. }
  8596. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8597. {
  8598. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8599. for(int k=0; k < ChargeProfileCount; k++)
  8600. {
  8601. fptr1 = fopen(chargingProfiles[k], "r");
  8602. fptr2 = fopen(temp, "w+");
  8603. //Check Charging Profile Count
  8604. while(fscanf(fptr1, "%s", word) != EOF)
  8605. {
  8606. //DEBUG_INFO("word=%s\n",word);
  8607. if(strstr(word, "chargingProfileId")!= NULL)
  8608. {
  8609. n_chargingProfile = n_chargingProfile + 1;
  8610. }
  8611. }
  8612. rewind(fptr1);
  8613. //search Charging Profile Element
  8614. //int i= 0;
  8615. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8616. {
  8617. json_object *tmpProfilee;
  8618. tmpProfilee = json_tokener_parse(sLineWord);
  8619. if(!is_error(tmpProfilee))
  8620. {
  8621. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8622. {
  8623. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8624. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8625. }
  8626. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8627. {
  8628. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8629. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8630. }
  8631. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8632. {
  8633. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8634. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8635. }
  8636. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8637. {
  8638. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8639. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8640. }
  8641. }
  8642. json_object_put(tmpProfilee);
  8643. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8644. {
  8645. //------- not write to fptr2-------//
  8646. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8647. //clearflag = TRUE;
  8648. }
  8649. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8650. {
  8651. //------- not write to fptr2-------//
  8652. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8653. }
  8654. else if(stackLevelIsNULL == TRUE)
  8655. {
  8656. //Clear Whole File
  8657. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8658. clearflag = TRUE;
  8659. break;
  8660. }
  8661. else
  8662. {
  8663. fprintf(fptr2, sLineWord);//writing data into file
  8664. }
  8665. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8666. }
  8667. if(clearflag == TRUE)
  8668. {
  8669. fclose(fptr1);
  8670. fclose(fptr2);
  8671. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8672. system(str);
  8673. // clear temp file
  8674. sprintf(str,"rm -f %s",temp);
  8675. system(str);
  8676. }
  8677. else
  8678. {
  8679. fclose(fptr1);
  8680. fclose(fptr2);
  8681. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8682. system(str);
  8683. resultRename = rename(temp, chargingProfiles[k]);
  8684. if(resultRename == 0)
  8685. {
  8686. DEBUG_INFO("File ChargingProfile renamed successfully");
  8687. }
  8688. else
  8689. {
  8690. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8691. }
  8692. if(comfirmstr[0]== 0)
  8693. {
  8694. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8695. }
  8696. //Check chargingProfile is empty file
  8697. /*------ Read the file ----------------*/
  8698. fptr1=fopen(chargingProfiles[k],"r");
  8699. ch=fgetc(fptr1);
  8700. rewind(fptr1);
  8701. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8702. if(ch!=EOF)
  8703. {
  8704. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8705. {
  8706. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8707. if(sLineWord[0]=='\0')
  8708. {
  8709. isEmptyFile = TRUE;
  8710. break;
  8711. }
  8712. else
  8713. {
  8714. isEmptyFile = FALSE;
  8715. break;
  8716. }
  8717. }
  8718. }
  8719. else
  8720. isEmptyFile = TRUE;
  8721. fclose(fptr1);
  8722. if(isEmptyFile == TRUE)
  8723. {
  8724. memset(str, 0, ARRAY_SIZE(str));
  8725. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8726. system(str);
  8727. }
  8728. /*------- End of reading ---------------*/
  8729. }
  8730. } // while(int k=0; k < ChargeProfileCount; k++)
  8731. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8732. end:
  8733. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8734. {
  8735. if(connectorIdInt == 0)
  8736. {
  8737. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8738. {
  8739. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  8740. }
  8741. }
  8742. else
  8743. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  8744. }
  8745. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8746. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8747. return result;
  8748. }
  8749. void createFirmwareVersionByDataTransfer(void)
  8750. {
  8751. json_object *FirmwareDataTransfer = json_object_new_object();
  8752. // AC & DC model
  8753. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8754. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8755. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8756. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8757. // DC model
  8758. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8759. {
  8760. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8761. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8762. (gunType[3] != GUN_TYPE_UNKNOWN))
  8763. {
  8764. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8765. }
  8766. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8767. {
  8768. // DS DM DW
  8769. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8770. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8771. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8772. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8773. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8774. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8775. }
  8776. else
  8777. {
  8778. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8779. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8780. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8781. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8782. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8783. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8784. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8785. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8786. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8787. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8788. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8789. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8790. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8791. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8792. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8793. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8794. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8795. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8796. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8797. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8798. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8799. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8800. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8801. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8802. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8803. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8804. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8805. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8806. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8807. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8808. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8809. }
  8810. }
  8811. // 4G model
  8812. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8813. {
  8814. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8815. }
  8816. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  8817. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  8818. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8819. json_object_put(FirmwareDataTransfer);
  8820. }
  8821. int handleDataTransferRequest(char *uuid, char *payload)
  8822. {
  8823. mtrace();
  8824. json_object *response = json_object_new_object();
  8825. int result = FAIL;
  8826. char tempvendorId[255]={0};
  8827. char tempmessageId[50]={0};
  8828. char tempdata[512]={0};
  8829. char message[2048]={0};
  8830. DEBUG_INFO("handleDataTransferRequest...\n");
  8831. if((uuid != NULL) && (payload != NULL))
  8832. {
  8833. json_object *DataTransfer;
  8834. DataTransfer = json_tokener_parse(payload);
  8835. if(!is_error(DataTransfer))
  8836. {
  8837. // Required data
  8838. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8839. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8840. // Optional data
  8841. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8842. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8843. if(json_object_object_get(DataTransfer, "data") != NULL)
  8844. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8845. result = PASS;
  8846. }
  8847. json_object_put(DataTransfer);
  8848. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8849. {
  8850. // Send all moudle firmware version on EVSE
  8851. createFirmwareVersionByDataTransfer();
  8852. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8853. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  8854. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8855. json_object_put(response);
  8856. }
  8857. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8858. {
  8859. system("/usr/bin/run_tmate_restart.sh &");
  8860. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8861. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8862. json_object_put(response);
  8863. }
  8864. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8865. {
  8866. json_object *data;
  8867. data = json_tokener_parse(tempdata);
  8868. if(!is_error(data))
  8869. {
  8870. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8871. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8872. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8873. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8874. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8875. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8876. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8877. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8878. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8879. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8880. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8881. }
  8882. else
  8883. {
  8884. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8885. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8886. }
  8887. json_object_put(data);
  8888. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8889. json_object_put(response);
  8890. }
  8891. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8892. {
  8893. json_object *data;
  8894. data = json_tokener_parse(tempdata);
  8895. if(!is_error(data))
  8896. {
  8897. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8898. if(json_object_object_get(data, "idToken") != NULL)
  8899. {
  8900. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8901. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8902. }
  8903. if(json_object_object_get(data, "price") != NULL)
  8904. {
  8905. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8906. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8907. }
  8908. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8909. }
  8910. else
  8911. {
  8912. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8913. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8914. }
  8915. json_object_put(data);
  8916. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8917. json_object_put(response);
  8918. }
  8919. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8920. {
  8921. json_object *data;
  8922. data = json_tokener_parse(tempdata);
  8923. if(!is_error(data))
  8924. {
  8925. if(json_object_object_get(data, "txId") != NULL)
  8926. {
  8927. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8928. for(int idx = 0;idx<gunTotalNumber;idx++)
  8929. {
  8930. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8931. {
  8932. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8933. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8934. if(json_object_object_get(data, "description") != NULL)
  8935. {
  8936. // California pricing V1.0
  8937. DEBUG_INFO("California pricing V1.0\n");
  8938. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8939. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8940. }
  8941. else
  8942. {
  8943. // California pricing V1.1
  8944. DEBUG_INFO("California pricing V1.1\n");
  8945. if(json_object_object_get(data, "timestamp") != NULL)
  8946. {
  8947. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8948. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8949. }
  8950. if(json_object_object_get(data, "meterValue") != NULL)
  8951. {
  8952. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8953. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8954. }
  8955. if(json_object_object_get(data, "cost") != NULL)
  8956. {
  8957. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8958. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8959. }
  8960. if(json_object_object_get(data, "state") != NULL)
  8961. {
  8962. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8963. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8964. }
  8965. if(json_object_object_get(data, "chargingPrice") != NULL)
  8966. {
  8967. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8968. {
  8969. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8970. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8971. }
  8972. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8973. {
  8974. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8975. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8976. }
  8977. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8978. {
  8979. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8980. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8981. }
  8982. }
  8983. if(json_object_object_get(data, "idlePrice") != NULL)
  8984. {
  8985. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8986. {
  8987. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8988. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8989. }
  8990. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8991. {
  8992. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8993. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8994. }
  8995. }
  8996. if(json_object_object_get(data, "nextPeriod") != NULL)
  8997. {
  8998. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8999. {
  9000. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9001. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9002. }
  9003. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9004. {
  9005. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9006. {
  9007. 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")));
  9008. 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"));
  9009. }
  9010. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9011. {
  9012. 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")));
  9013. 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"));
  9014. }
  9015. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9016. {
  9017. 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")));
  9018. 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"));
  9019. }
  9020. }
  9021. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9022. {
  9023. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9024. {
  9025. 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")));
  9026. 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"));
  9027. }
  9028. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9029. {
  9030. 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")));
  9031. 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"));
  9032. }
  9033. }
  9034. }
  9035. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9036. {
  9037. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9038. {
  9039. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9040. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9041. }
  9042. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9043. {
  9044. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9045. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9046. }
  9047. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9048. {
  9049. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9050. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9051. }
  9052. }
  9053. }
  9054. }
  9055. }
  9056. }
  9057. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9058. }
  9059. else
  9060. {
  9061. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9062. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9063. }
  9064. json_object_put(data);
  9065. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9066. json_object_put(response);
  9067. }
  9068. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9069. {
  9070. json_object *data;
  9071. data = json_tokener_parse(tempdata);
  9072. if(!is_error(data))
  9073. {
  9074. if(json_object_object_get(data, "txId") != NULL)
  9075. {
  9076. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9077. for(int idx = 0;idx<gunTotalNumber;idx++)
  9078. {
  9079. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9080. {
  9081. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9082. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9083. if(json_object_object_get(data, "description") != NULL)
  9084. {
  9085. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9086. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9087. }
  9088. }
  9089. }
  9090. }
  9091. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9092. }
  9093. else
  9094. {
  9095. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9096. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9097. }
  9098. json_object_put(data);
  9099. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9100. json_object_put(response);
  9101. }
  9102. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9103. {
  9104. json_object *data;
  9105. data = json_tokener_parse(tempdata);
  9106. if(!is_error(data))
  9107. {
  9108. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9109. if(json_object_object_get(data, "Content_Type") != NULL)
  9110. {
  9111. 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))
  9112. {
  9113. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9114. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9115. {
  9116. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9117. }
  9118. }
  9119. else
  9120. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9121. }
  9122. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9123. }
  9124. else
  9125. {
  9126. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9127. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9128. }
  9129. json_object_put(data);
  9130. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9131. json_object_put(response);
  9132. }
  9133. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  9134. {
  9135. json_object *data;
  9136. data = json_tokener_parse(tempdata);
  9137. if(!is_error(data))
  9138. {
  9139. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9140. if(json_object_object_get(data, "Page_Index") != NULL)
  9141. {
  9142. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9143. }
  9144. if(json_object_object_get(data, "Duration") != NULL)
  9145. {
  9146. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9147. }
  9148. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  9149. }
  9150. else
  9151. {
  9152. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9153. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9154. }
  9155. json_object_put(data);
  9156. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9157. json_object_put(response);
  9158. }
  9159. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9160. {
  9161. json_object *data;
  9162. data = json_tokener_parse(tempdata);
  9163. if(!is_error(data))
  9164. {
  9165. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9166. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9167. {
  9168. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9169. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9170. else
  9171. {
  9172. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9173. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9174. }
  9175. }
  9176. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9177. {
  9178. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9179. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9180. else
  9181. {
  9182. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9183. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9184. }
  9185. }
  9186. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9187. {
  9188. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9189. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9190. else
  9191. {
  9192. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9193. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9194. }
  9195. }
  9196. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9197. {
  9198. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9199. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9200. else
  9201. {
  9202. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9203. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9204. }
  9205. }
  9206. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9207. {
  9208. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9209. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9210. else
  9211. {
  9212. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9213. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9214. }
  9215. }
  9216. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9217. {
  9218. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9219. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9220. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9221. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9222. else
  9223. {
  9224. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9225. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9226. }
  9227. }
  9228. if(json_object_object_get(data, "isAuthentication") != NULL)
  9229. {
  9230. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9231. {
  9232. case 0:
  9233. case 1:
  9234. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9235. break;
  9236. default:
  9237. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9238. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9239. break;
  9240. }
  9241. }
  9242. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9243. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9244. }
  9245. else
  9246. {
  9247. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9248. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9249. }
  9250. json_object_put(data);
  9251. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9252. json_object_put(response);
  9253. }
  9254. else
  9255. {
  9256. // Can not find valid message id
  9257. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9258. }
  9259. }
  9260. else
  9261. {
  9262. // Payload is null
  9263. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9264. }
  9265. LWS_Send(message);
  9266. return result;
  9267. }
  9268. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9269. {
  9270. mtrace();
  9271. int result = FAIL;
  9272. int connectorIdInt, durationInt;
  9273. char chargingRateUnitStr[4]={0};
  9274. char comfirmstr[20];
  9275. int confirmPeriods = 0;
  9276. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9277. json_object *GetCompositeSchedule;
  9278. GetCompositeSchedule = json_tokener_parse(payload);
  9279. if(!is_error(GetCompositeSchedule))
  9280. {
  9281. // Required data
  9282. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9283. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9284. else
  9285. connectorIdInt = -1;
  9286. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9287. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9288. else
  9289. durationInt = 86400;
  9290. // Optional data
  9291. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9292. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9293. }
  9294. json_object_put(GetCompositeSchedule);
  9295. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9296. if((connectorIdInt == 0) ||
  9297. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9298. {
  9299. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9300. struct StructChargingProfile tmpProfile[1];
  9301. if(strstr(chargingRateUnitStr, "W") != NULL)
  9302. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9303. else
  9304. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9305. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9306. {
  9307. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9308. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9309. }
  9310. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9311. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9312. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9313. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9314. {
  9315. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9316. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9317. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9318. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9319. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9320. {
  9321. confirmPeriods = idx;
  9322. break;
  9323. }
  9324. }
  9325. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9326. {
  9327. confirmPeriods += 1;
  9328. }
  9329. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9330. }
  9331. else
  9332. {
  9333. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9334. }
  9335. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9336. return result;
  9337. }
  9338. int handleGetConfigurationRequest(char *uuid, char *payload)
  9339. {
  9340. mtrace();
  9341. int result = FAIL;
  9342. int MaxKeySupported = 0;
  9343. int n_keys = 0;
  9344. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9345. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9346. json_object *GetConfiguration;
  9347. GetConfiguration = json_tokener_parse(payload);
  9348. if(!is_error(GetConfiguration))
  9349. {
  9350. // Optional data
  9351. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9352. {
  9353. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9354. {
  9355. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9356. n_keys = idx + 1;
  9357. }
  9358. }
  9359. }
  9360. json_object_put(GetConfiguration);
  9361. UnknownKeynum = 0;
  9362. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9363. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9364. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9365. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9366. if(n_keys != 0)
  9367. {
  9368. for(int i=0;i<n_keys;i++)
  9369. {
  9370. getKeyValue(requestKey[i]);
  9371. }
  9372. }
  9373. else
  9374. {
  9375. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9376. getKeyValue("");
  9377. }
  9378. processUnkownKey();
  9379. sendGetConfigurationConfirmation(uuid);
  9380. return result;
  9381. }
  9382. static char fnamePlusPath[100]={0};
  9383. static char fnamePWithNoPath[60]={0};
  9384. void checkUploadLog(void)
  9385. {
  9386. FILE *fp;
  9387. /* Open the command for reading. */
  9388. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9389. if (fp == NULL) {
  9390. DEBUG_WARN("Failed to run command\n" );
  9391. exit(1);
  9392. }
  9393. int ftppathlen = 0;
  9394. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9395. int i = 0;
  9396. /* Read the output a line at a time - output it. */
  9397. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9398. if(i==0)
  9399. {
  9400. ftppathlen = strlen(fnamePlusPath);
  9401. DEBUG_INFO("%s\n", fnamePlusPath);
  9402. fnamePlusPath[ftppathlen]='\0';
  9403. break;
  9404. }
  9405. i= i+1;
  9406. }
  9407. /* close */
  9408. pclose(fp);
  9409. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9410. {
  9411. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9412. {
  9413. fnamePlusPath[k]='\0';
  9414. }
  9415. }
  9416. i=1;
  9417. //char fname[60]={0};
  9418. while(i < ftppathlen)
  9419. {
  9420. int len=ftppathlen-i;
  9421. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9422. {
  9423. DEBUG_INFO("compare '/' all right\n");
  9424. break;
  9425. }
  9426. i=i+1;
  9427. }
  9428. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9429. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9430. fnamePWithNoPath[i+1] = '\0';
  9431. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9432. {
  9433. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9434. {
  9435. fnamePWithNoPath[j]='\0';
  9436. }
  9437. }
  9438. FILE* fp1 = fopen(fnamePlusPath, "r");
  9439. if (fp1)
  9440. {
  9441. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9442. // file exists
  9443. fclose(fp1);
  9444. }
  9445. else
  9446. {
  9447. // file doesn't exist
  9448. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9449. }
  9450. }
  9451. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9452. {
  9453. mtrace();
  9454. int result = FAIL;
  9455. time_t CurrentTime;
  9456. struct tm *tm;
  9457. pthread_t th_Status;
  9458. CurrentTime = time(NULL);
  9459. tm = localtime(&CurrentTime);
  9460. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  9461. 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);
  9462. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9463. if(!interLock.isGetDiagnosticGoing)
  9464. {
  9465. interLock.isGetDiagnosticGoing = 1;
  9466. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9467. sleep(1);
  9468. }
  9469. else
  9470. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9471. return result;
  9472. }
  9473. void* GetDiagnosticsProcess(void* data)
  9474. {
  9475. pthread_detach(pthread_self());
  9476. mtrace();
  9477. int retriesInt=0, retryIntervalInt=0;
  9478. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9479. 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};
  9480. int port=0;
  9481. int isSuccess = FALSE;
  9482. char cmdBuf[2048];
  9483. struct tm *tmNow;
  9484. time_t CurrentTime;
  9485. struct tm tmStart;
  9486. struct tm tmStop;
  9487. CurrentTime = time(NULL);
  9488. tmNow=localtime(&CurrentTime);
  9489. uint16_t targetYear, targetMonth;
  9490. json_object *GetDiagnostics;
  9491. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9492. GetDiagnostics = json_tokener_parse(data);
  9493. if(!is_error(GetDiagnostics))
  9494. {
  9495. // Required data
  9496. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9497. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9498. // Optional data
  9499. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9500. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9501. else
  9502. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9503. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9504. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9505. else
  9506. retryIntervalInt = 30;
  9507. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9508. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9509. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9510. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9511. }
  9512. json_object_put(GetDiagnostics);
  9513. // Pack log to compress file
  9514. 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) &&
  9515. (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))
  9516. {
  9517. // Pack system log
  9518. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9519. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9520. targetYear = tmStart.tm_year;
  9521. targetMonth = tmStart.tm_mon;
  9522. do
  9523. {
  9524. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9525. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9526. if(targetMonth+1>=13)
  9527. {
  9528. targetYear += 1;
  9529. targetMonth = 1;
  9530. }
  9531. else
  9532. {
  9533. targetMonth += 1;
  9534. }
  9535. }while((targetYear < (tmNow->tm_year+1900)) ||
  9536. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9537. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9538. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9539. system(cmdBuf);
  9540. // Pack charging & event log
  9541. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9542. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9543. targetYear = tmStart.tm_year;
  9544. targetMonth = tmStart.tm_mon;
  9545. do
  9546. {
  9547. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9548. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9549. if(targetMonth+1>=13)
  9550. {
  9551. targetYear += 1;
  9552. targetMonth = 1;
  9553. }
  9554. else
  9555. {
  9556. targetMonth += 1;
  9557. }
  9558. }while((targetYear < (tmNow->tm_year+1900)) ||
  9559. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9560. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9561. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9562. system(cmdBuf);
  9563. // Combine log file
  9564. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9565. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9566. }
  9567. else
  9568. {
  9569. system("exec /root/logPackTools 'log' 6");
  9570. }
  9571. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9572. system(cmdBuf);
  9573. checkUploadLog();
  9574. //****************location*******************/
  9575. if(strcmp(locationstr,"")==0)
  9576. {
  9577. DEBUG_INFO("location is <Empty>!\n");
  9578. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9579. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9580. goto end;
  9581. }
  9582. memset(protocol, 0, ARRAY_SIZE(protocol));
  9583. memset(user, 0, ARRAY_SIZE(user) );
  9584. memset(password, 0, ARRAY_SIZE(password));
  9585. memset(host, 0, ARRAY_SIZE(host));
  9586. memset(path, 0, ARRAY_SIZE(path));
  9587. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9588. memset(host1, 0, ARRAY_SIZE(host1));
  9589. memset(path1, 0, ARRAY_SIZE(path1));
  9590. /*location: ftp://user:password@host:port/path*/
  9591. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9592. if((access(fnamePlusPath,F_OK))!=-1)
  9593. {
  9594. DEBUG_INFO("fnamePlusPath exist.\n");
  9595. }
  9596. else
  9597. {
  9598. DEBUG_INFO("fnamePlusPath not exist!\n");
  9599. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9600. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9601. goto end;
  9602. }
  9603. if(strchr(locationstr,'@')==NULL)
  9604. {
  9605. sscanf(locationstr,
  9606. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9607. protocol, host, &port, path);
  9608. strcpy(user,"anonymous");
  9609. strcpy(password,"");
  9610. }
  9611. else
  9612. {
  9613. //DEBUG_INFO("pch=%s\n", pch);
  9614. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9615. protocol, user, password, host, &port, path);
  9616. }
  9617. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9618. {
  9619. DEBUG_INFO("protocol is not ftp/http ! \n");
  9620. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9621. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9622. goto end;
  9623. }
  9624. if(strncmp(locationstr,"http", 4) == 0)
  9625. {
  9626. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9627. sprintf(ftppath,"/%s", path);
  9628. do
  9629. {
  9630. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9631. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9632. sleep(3);
  9633. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9634. if(!isSuccess)
  9635. {
  9636. DEBUG_INFO("Diagnostics fail.\n");
  9637. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9638. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9639. sleep(retryIntervalInt);
  9640. }
  9641. else
  9642. {
  9643. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9644. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9645. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9646. }
  9647. retriesInt--;
  9648. }while((isSuccess == 0)&&(retriesInt >= 0));
  9649. }
  9650. else
  9651. {
  9652. sscanf(host,"%[^/]%s",host1, path1);
  9653. if(strlen(path) > 0)
  9654. sprintf(ftppath,"/%s", path);
  9655. else
  9656. sprintf(ftppath,"/%s", path1);
  9657. int ftppathlen=strlen(ftppath);
  9658. int i=1;
  9659. char filenametemp[50];
  9660. while(i < ftppathlen)
  9661. {
  9662. int len=ftppathlen-i;
  9663. if(ftppath[len]== 47) // '/' ascll code: 47
  9664. {
  9665. DEBUG_INFO("find '/' all right\n");
  9666. break;
  9667. }
  9668. i=i+1;
  9669. }
  9670. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9671. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9672. filenametemp[i+1] = 0;
  9673. if(port == 0)
  9674. port = 21;
  9675. do
  9676. {
  9677. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9678. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9679. sleep(3);
  9680. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9681. if(!isSuccess)
  9682. {
  9683. DEBUG_INFO("Diagnostics fail.\n");
  9684. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9685. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9686. sleep(retryIntervalInt);
  9687. }
  9688. else
  9689. {
  9690. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9691. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9692. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9693. }
  9694. retriesInt--;
  9695. }while((!isSuccess)&&(retriesInt >= 0));
  9696. }
  9697. end:
  9698. system("rm -f /mnt/*");
  9699. sleep(5);
  9700. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9701. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9702. interLock.isGetDiagnosticGoing = 0;
  9703. pthread_exit(NULL);
  9704. }
  9705. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9706. {
  9707. mtrace();
  9708. int result = FAIL;
  9709. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9710. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9711. {
  9712. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9713. locallistVersion = -1;
  9714. }
  9715. else
  9716. {
  9717. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9718. OCPP_getListVerion();
  9719. }
  9720. //from db.OCPP_getListVerion
  9721. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9722. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  9723. sendGetLocalListVersionConfirmation(uuid,"");
  9724. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  9725. return result;
  9726. }
  9727. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  9728. {
  9729. mtrace();
  9730. int result = FAIL;
  9731. int connectorIdInt=-1;
  9732. int tempIndex = 0;
  9733. int connectorIdIsNULL, chargingProfileIsNULL;
  9734. char comfirmstr[20]={0};
  9735. char cmdBuf[512];
  9736. json_object *RemoteStartTransaction;
  9737. FILE *fp;
  9738. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9739. if(server_pending == TRUE)
  9740. {
  9741. return 0;
  9742. }
  9743. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9744. RemoteStartTransaction = json_tokener_parse(payload);
  9745. if(!is_error(RemoteStartTransaction))
  9746. {
  9747. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9748. {
  9749. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9750. }
  9751. else
  9752. {
  9753. connectorIdIsNULL = TRUE;
  9754. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9755. {
  9756. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9757. {
  9758. connectorIdIsNULL = FALSE;
  9759. connectorIdInt = (gun_index+1);
  9760. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9761. break;
  9762. }
  9763. }
  9764. }
  9765. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9766. {
  9767. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9768. // Required data
  9769. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9770. // Optional data
  9771. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9772. {
  9773. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9774. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9775. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9776. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9777. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9778. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9779. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9780. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9781. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9782. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9783. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9784. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9785. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9786. {
  9787. 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")));
  9788. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9789. 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"));
  9790. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9791. 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"));
  9792. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9793. 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")));
  9794. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9795. {
  9796. 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++)
  9797. {
  9798. 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"));
  9799. 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"));
  9800. 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)
  9801. 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"));
  9802. }
  9803. }
  9804. }
  9805. }
  9806. else
  9807. {
  9808. chargingProfileIsNULL = TRUE;
  9809. }
  9810. }
  9811. }
  9812. else
  9813. {
  9814. connectorIdIsNULL = TRUE;
  9815. }
  9816. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9817. {
  9818. DEBUG_WARN("Connector id is NULL\n.");
  9819. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9820. goto end;
  9821. }
  9822. /*
  9823. enum _SYSTEM_STATUS
  9824. {
  9825. S_BOOTING = 0,
  9826. S_IDLE, = 1
  9827. S_AUTHORIZING, = 2
  9828. S_REASSIGN_CHECK, = 3
  9829. S_REASSIGN, = 4
  9830. S_PRECHARGE, = 5
  9831. S_PREPARING_FOR_EV, = 6
  9832. S_PREPARING_FOR_EVSE, = 7
  9833. S_CHARGING, = 8
  9834. S_TERMINATING, = 9
  9835. S_COMPLETE, = 10
  9836. S_ALARM, = 11
  9837. S_FAULT = 12
  9838. }
  9839. */
  9840. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9841. {
  9842. //check Transaction active
  9843. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9844. {
  9845. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9846. {
  9847. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9848. }
  9849. else
  9850. {
  9851. tempIndex = connectorIdInt -1;
  9852. }
  9853. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9854. {
  9855. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9856. {
  9857. 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))
  9858. {
  9859. //Reserved
  9860. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9861. }
  9862. 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))
  9863. {
  9864. //Reserved
  9865. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9866. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9867. goto end;
  9868. }
  9869. else
  9870. {
  9871. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9872. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9873. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9874. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9875. {
  9876. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9877. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9878. goto end;
  9879. }
  9880. }//END FOR ELSE
  9881. }
  9882. }// END FOR CHAdeMO_QUANTITY
  9883. }
  9884. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9885. {
  9886. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9887. {
  9888. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9889. }
  9890. else
  9891. {
  9892. tempIndex = connectorIdInt -1;
  9893. }
  9894. for (int index = 0; index < CCS_QUANTITY; index++)
  9895. {
  9896. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9897. {
  9898. 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))
  9899. {
  9900. //Reserved
  9901. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9902. }
  9903. 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))
  9904. {
  9905. //Reserved
  9906. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9907. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9908. goto end;
  9909. }
  9910. else
  9911. {
  9912. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9913. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9914. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9915. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9916. {
  9917. DEBUG_WARN("CCS connector not allow start\n.");
  9918. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9919. goto end;
  9920. }
  9921. }// END FOR ELSE
  9922. }
  9923. }// END FOR CCS_QUANTITY
  9924. }
  9925. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9926. {
  9927. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9928. {
  9929. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9930. }
  9931. else
  9932. {
  9933. tempIndex = connectorIdInt -1;
  9934. }
  9935. for (int index = 0; index < GB_QUANTITY; index++)
  9936. {
  9937. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9938. {
  9939. 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))
  9940. {
  9941. //Reserved
  9942. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9943. }
  9944. 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))
  9945. {
  9946. //Reserved
  9947. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9948. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9949. goto end;
  9950. }
  9951. else
  9952. {
  9953. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9954. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9955. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9956. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9957. {
  9958. DEBUG_WARN("GB connector not allow start\n.");
  9959. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9960. goto end;
  9961. }
  9962. }// END FOR ELSE
  9963. }
  9964. } // END FOR GB_QUANTITY
  9965. }
  9966. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9967. {
  9968. tempIndex = connectorIdInt -1;
  9969. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9970. {
  9971. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9972. {
  9973. 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))
  9974. {
  9975. //Reserved
  9976. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9977. }
  9978. 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))
  9979. {
  9980. //Reserved
  9981. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9982. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9983. goto end;
  9984. }
  9985. else
  9986. {
  9987. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9988. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9989. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9990. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9991. {
  9992. DEBUG_WARN("GB connector not allow start\n.");
  9993. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9994. goto end;
  9995. }
  9996. }// END FOR ELSE
  9997. }
  9998. } // END FOR GB_QUANTITY
  9999. }
  10000. else
  10001. {
  10002. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10003. {
  10004. tempIndex = 2;
  10005. }
  10006. else
  10007. {
  10008. tempIndex = connectorIdInt -1;
  10009. }
  10010. for (int index = 0; index < AC_QUANTITY; index++)
  10011. {
  10012. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10013. {
  10014. 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))
  10015. {
  10016. //Reserved
  10017. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10018. }
  10019. 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))
  10020. {
  10021. //Reserved
  10022. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10023. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10024. goto end;
  10025. }
  10026. else
  10027. {
  10028. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10029. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10030. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10031. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10032. {
  10033. DEBUG_WARN("AC connector not allow start\n.");
  10034. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10035. goto end;
  10036. }
  10037. }//END FOR ELSE
  10038. }
  10039. }// END FOR AC_QUANTITY
  10040. }
  10041. if(chargingProfileIsNULL == FALSE)
  10042. {
  10043. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10044. {
  10045. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10046. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10047. //memset idTag
  10048. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10049. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10050. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10051. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10052. // Save profile to file
  10053. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10054. system(cmdBuf);
  10055. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10056. fp = fopen(cmdBuf, "w");
  10057. 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));
  10058. fclose(fp);
  10059. }
  10060. else
  10061. {
  10062. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10063. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10064. }
  10065. }
  10066. else
  10067. {
  10068. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10069. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10070. //memset idTag
  10071. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10072. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10073. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10074. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10075. }
  10076. }
  10077. else
  10078. {
  10079. DEBUG_WARN("Connector id over\n.");
  10080. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10081. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10082. }
  10083. end:
  10084. json_object_put(RemoteStartTransaction);
  10085. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10086. {
  10087. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10088. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10089. }
  10090. //OCPP send RemoteStartConfirmation by first.
  10091. sendRemoteStartConfirmation(uuid, comfirmstr);
  10092. return result;
  10093. }
  10094. int handleRemoteStartRequest(char *uuid, char *payload)
  10095. {
  10096. mtrace();
  10097. int result = PASS;
  10098. int connectorIdInt=-1;
  10099. int tempIndex = 0;
  10100. char comfirmstr[20]={0};
  10101. char cmdBuf[512];
  10102. json_object *RemoteStartTransaction;
  10103. FILE *fp;
  10104. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10105. if(server_pending == TRUE)
  10106. {
  10107. result = FAIL;
  10108. }
  10109. RemoteStartTransaction = json_tokener_parse(payload);
  10110. if(!is_error(RemoteStartTransaction))
  10111. {
  10112. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10113. {
  10114. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10115. }
  10116. else
  10117. {
  10118. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10119. {
  10120. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10121. {
  10122. connectorIdInt = (gun_index+1);
  10123. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10124. break;
  10125. }
  10126. }
  10127. }
  10128. if(connectorIdInt == 0)
  10129. {
  10130. DEBUG_WARN("Connector id shall not equal 0.\n");
  10131. result = FAIL;
  10132. }
  10133. else if(connectorIdInt == -1)
  10134. {
  10135. DEBUG_INFO("Connector id does not specific.\n");
  10136. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10137. {
  10138. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10139. // Required data
  10140. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10141. // Optional data
  10142. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10143. {
  10144. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10145. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10146. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10147. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10148. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10149. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10150. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10151. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10152. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10153. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10154. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10155. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10156. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10157. {
  10158. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  10159. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10160. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  10161. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10162. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  10163. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10164. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  10165. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10166. {
  10167. 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++)
  10168. {
  10169. ShmOCPP16Data->RemoteStartTransaction[gun_index].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"));
  10170. ShmOCPP16Data->RemoteStartTransaction[gun_index].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"));
  10171. 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)
  10172. ShmOCPP16Data->RemoteStartTransaction[gun_index].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"));
  10173. }
  10174. }
  10175. }
  10176. }
  10177. else
  10178. {
  10179. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10180. }
  10181. }
  10182. }
  10183. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10184. {
  10185. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10186. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10187. // Required data
  10188. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10189. // Optional data
  10190. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10191. {
  10192. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10193. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10194. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10195. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10196. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10197. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10198. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10199. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10200. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10201. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10202. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10203. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10204. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10205. {
  10206. 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")));
  10207. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10208. 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"));
  10209. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10210. 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"));
  10211. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10212. 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")));
  10213. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10214. {
  10215. 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++)
  10216. {
  10217. 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"));
  10218. 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"));
  10219. 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)
  10220. 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"));
  10221. }
  10222. }
  10223. }
  10224. }
  10225. else
  10226. {
  10227. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10228. }
  10229. }
  10230. else
  10231. {
  10232. DEBUG_WARN("Connector id is over maximun value.\n");
  10233. result = FAIL;
  10234. }
  10235. }
  10236. if(result == PASS)
  10237. {
  10238. if(connectorIdInt > 0)
  10239. {
  10240. //check Transaction active
  10241. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10242. {
  10243. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10244. {
  10245. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10246. }
  10247. else
  10248. {
  10249. tempIndex = connectorIdInt -1;
  10250. }
  10251. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10252. {
  10253. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10254. {
  10255. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10256. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10257. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10258. {
  10259. //Reserved
  10260. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10261. }
  10262. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10263. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10264. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10265. {
  10266. //Reserved
  10267. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10268. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10269. goto end;
  10270. }
  10271. else
  10272. {
  10273. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10274. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10275. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10276. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10277. {
  10278. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10279. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10280. goto end;
  10281. }
  10282. }//END FOR ELSE
  10283. }
  10284. }// END FOR CHAdeMO_QUANTITY
  10285. }
  10286. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10287. {
  10288. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10289. {
  10290. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10291. }
  10292. else
  10293. {
  10294. tempIndex = connectorIdInt -1;
  10295. }
  10296. for (int index = 0; index < CCS_QUANTITY; index++)
  10297. {
  10298. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10299. {
  10300. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10301. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10302. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10303. {
  10304. //Reserved
  10305. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10306. }
  10307. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10308. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10309. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10310. {
  10311. //Reserved
  10312. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10313. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10314. goto end;
  10315. }
  10316. else
  10317. {
  10318. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10319. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10320. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10321. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10322. {
  10323. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10324. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10325. goto end;
  10326. }
  10327. }// END FOR ELSE
  10328. }
  10329. }// END FOR CCS_QUANTITY
  10330. }
  10331. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10332. {
  10333. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10334. {
  10335. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10336. }
  10337. else
  10338. {
  10339. tempIndex = connectorIdInt -1;
  10340. }
  10341. for (int index = 0; index < GB_QUANTITY; index++)
  10342. {
  10343. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10344. {
  10345. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10346. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10347. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10348. {
  10349. //Reserved
  10350. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10351. }
  10352. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10353. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10354. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10355. {
  10356. //Reserved
  10357. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10358. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10359. goto end;
  10360. }
  10361. else
  10362. {
  10363. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10364. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10365. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10366. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10367. {
  10368. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10369. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10370. goto end;
  10371. }
  10372. }// END FOR ELSE
  10373. }
  10374. } // END FOR GB_QUANTITY
  10375. }
  10376. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10377. {
  10378. tempIndex = connectorIdInt -1;
  10379. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10380. {
  10381. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10382. {
  10383. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10384. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10385. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10386. {
  10387. //Reserved
  10388. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10389. }
  10390. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10391. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10392. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10393. {
  10394. //Reserved
  10395. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10396. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10397. goto end;
  10398. }
  10399. else
  10400. {
  10401. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10402. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10403. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10404. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10405. {
  10406. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10407. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10408. goto end;
  10409. }
  10410. }// END FOR ELSE
  10411. }
  10412. } // END FOR GB_QUANTITY
  10413. }
  10414. else
  10415. {
  10416. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10417. {
  10418. tempIndex = 2;
  10419. }
  10420. else
  10421. {
  10422. tempIndex = connectorIdInt -1;
  10423. }
  10424. for (int index = 0; index < AC_QUANTITY; index++)
  10425. {
  10426. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10427. {
  10428. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10429. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10430. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10431. {
  10432. //Reserved
  10433. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10434. }
  10435. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10436. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10437. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10438. {
  10439. //Reserved
  10440. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10441. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10442. goto end;
  10443. }
  10444. else
  10445. {
  10446. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10447. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10448. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10449. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10450. {
  10451. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10452. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10453. goto end;
  10454. }
  10455. }//END FOR ELSE
  10456. }
  10457. }// END FOR AC_QUANTITY
  10458. }
  10459. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10460. {
  10461. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10462. {
  10463. // Save profile to file
  10464. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10465. system(cmdBuf);
  10466. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10467. fp = fopen(cmdBuf, "w");
  10468. 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));
  10469. fclose(fp);
  10470. }
  10471. else
  10472. {
  10473. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10474. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10475. goto end;
  10476. }
  10477. }
  10478. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10479. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10480. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10481. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10482. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10483. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10484. }
  10485. else
  10486. {
  10487. uint8_t isHasIdleConnector = FALSE;
  10488. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10489. {
  10490. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10491. {
  10492. isHasIdleConnector = TRUE;
  10493. break;
  10494. }
  10495. }
  10496. if(isHasIdleConnector == TRUE)
  10497. {
  10498. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10499. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10500. {
  10501. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10502. {
  10503. // Save profile to file
  10504. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  10505. system(cmdBuf);
  10506. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  10507. fp = fopen(cmdBuf, "w");
  10508. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10509. fclose(fp);
  10510. refreshStartTimer(&clientTime.RemoteStartWait);
  10511. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  10512. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10513. }
  10514. else
  10515. {
  10516. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10517. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10518. }
  10519. }
  10520. }
  10521. else
  10522. {
  10523. DEBUG_INFO("There is not any connector is idle.\n");
  10524. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10525. }
  10526. }
  10527. }
  10528. else
  10529. {
  10530. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10531. }
  10532. end:
  10533. json_object_put(RemoteStartTransaction);
  10534. sendRemoteStartConfirmation(uuid, comfirmstr);
  10535. return result;
  10536. }
  10537. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10538. {
  10539. mtrace();
  10540. int result = FAIL;
  10541. int match = FALSE;
  10542. int GunNO = 0;
  10543. int tempIndex = 0;
  10544. int transactionIdInt=0;
  10545. int transactionIdIsNULL= TRUE;
  10546. char comfirmstr[20];
  10547. json_object *RemoteStopTransaction;
  10548. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10549. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10550. if(server_pending == TRUE)
  10551. {
  10552. return 0;
  10553. }
  10554. RemoteStopTransaction = json_tokener_parse(payload);
  10555. if(!is_error(RemoteStopTransaction))
  10556. {
  10557. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10558. {
  10559. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10560. transactionIdIsNULL = FALSE;
  10561. }
  10562. }
  10563. json_object_put(RemoteStopTransaction);
  10564. if(transactionIdIsNULL == FALSE)
  10565. {
  10566. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10567. {
  10568. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10569. {
  10570. //check Transaction active
  10571. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10572. {
  10573. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10574. {
  10575. tempIndex = ((gun_index==2) ? 1: 0);
  10576. }
  10577. else
  10578. {
  10579. tempIndex = gun_index;
  10580. }
  10581. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10582. {
  10583. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10584. {
  10585. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10586. {
  10587. match = TRUE;
  10588. GunNO = gun_index;
  10589. }
  10590. }
  10591. }// END FOR CHAdeMO_QUANTITY
  10592. }
  10593. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10594. {
  10595. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10596. {
  10597. tempIndex = ((gun_index==2) ? 1: 0);
  10598. }
  10599. else
  10600. {
  10601. tempIndex = gun_index;
  10602. }
  10603. for (int index = 0; index < CCS_QUANTITY; index++)
  10604. {
  10605. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10606. {
  10607. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10608. {
  10609. match = TRUE;
  10610. GunNO = gun_index;
  10611. }
  10612. }
  10613. }// END FOR CCS_QUANTITY
  10614. }
  10615. else if(gunType[gun_index] == GUN_TYPE_GBT)
  10616. {
  10617. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10618. {
  10619. tempIndex = ((gun_index==2) ? 1: 0);
  10620. }
  10621. else
  10622. {
  10623. tempIndex = gun_index;
  10624. }
  10625. for (int index = 0; index < GB_QUANTITY; index++)
  10626. {
  10627. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10628. {
  10629. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10630. {
  10631. match = TRUE;
  10632. GunNO = gun_index;
  10633. }
  10634. }
  10635. }// END FOR GB_QUANTITY
  10636. }
  10637. else if(gunType[gun_index] == GUN_TYPE_DO)
  10638. {
  10639. tempIndex = gun_index;
  10640. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10641. {
  10642. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10643. {
  10644. 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
  10645. {
  10646. match = TRUE;
  10647. GunNO = gun_index;
  10648. }
  10649. }
  10650. }// END FOR GB_QUANTITY
  10651. }
  10652. else
  10653. {
  10654. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10655. {
  10656. tempIndex = 2;
  10657. }
  10658. else
  10659. {
  10660. tempIndex = gun_index;
  10661. }
  10662. for (int index = 0; index < AC_QUANTITY; index++)
  10663. {
  10664. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10665. {
  10666. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10667. {
  10668. match = TRUE;
  10669. GunNO = gun_index;
  10670. }
  10671. }
  10672. }// END FOR CHAdeMO_QUANTITY
  10673. } // END FOR AC ELSE
  10674. }// CHECK IF ResponseTransactionId == transactionIdInt
  10675. }//END FOR
  10676. if( match == TRUE)
  10677. {
  10678. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  10679. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10680. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  10681. }
  10682. else
  10683. {
  10684. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10685. }
  10686. }
  10687. else
  10688. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10689. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  10690. return result;
  10691. }
  10692. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  10693. {
  10694. mtrace();
  10695. int result = FAIL;
  10696. int connectorIdInt=0, reservationIdInt=0;
  10697. int tempIndex = 0;
  10698. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  10699. char comfirmstr[20]={0};
  10700. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  10701. int c = 0;
  10702. char *loc;
  10703. //char *ptr;
  10704. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  10705. strcpy(sstrtemp, stringtrimspace(payload));
  10706. //***(1)connectorId ****/
  10707. c=0;
  10708. loc = strstr(sstrtemp, "connectorId");
  10709. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10710. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  10711. {
  10712. sstr[c] = loc[strlen("connectorId")+2+c];
  10713. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10714. c++;
  10715. }
  10716. sstr[c] = '\0';
  10717. connectorIdInt = atoi(sstr);
  10718. //***(2)expiryDate ****/
  10719. loc = strstr(sstrtemp, "expiryDate");
  10720. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10721. c = 0;
  10722. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  10723. {
  10724. sstr[c] = loc[3+strlen("expiryDate")+c];
  10725. c++;
  10726. }
  10727. sstr[c] = '\0';
  10728. strcpy(expiryDatestr, sstr);
  10729. //***(3)idTag ****/
  10730. loc = strstr(sstrtemp, "idTag");
  10731. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10732. c = 0;
  10733. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  10734. {
  10735. sstr[c] = loc[3+strlen("idTag")+c];
  10736. c++;
  10737. }
  10738. sstr[c] = '\0';
  10739. strcpy(idTagstr, sstr);
  10740. //***(4)parentIdTag ****/
  10741. loc = strstr(sstrtemp, "parentIdTag");
  10742. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10743. c = 0;
  10744. if(loc == NULL)
  10745. {
  10746. strcpy(parentIdTagstr, "");
  10747. }
  10748. else
  10749. {
  10750. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  10751. {
  10752. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10753. c++;
  10754. }
  10755. sstr[c] = '\0';
  10756. strcpy(parentIdTagstr, sstr);
  10757. }
  10758. //***(5)reservationId ****/
  10759. c=0;
  10760. loc = strstr(sstrtemp, "reservationId");
  10761. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10762. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  10763. {
  10764. sstr[c] = loc[strlen("reservationId")+2+c];
  10765. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10766. c++;
  10767. }
  10768. sstr[c] = '\0';
  10769. reservationIdInt = atoi(sstr);
  10770. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10771. /*
  10772. enum SYSTEM_STATUS
  10773. {
  10774. SYS_MODE_BOOTING = 0,
  10775. SYS_MODE_IDLE = 1,
  10776. SYS_MODE_AUTHORIZING = 2,
  10777. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  10778. SYS_MODE_REASSIGN = 4,
  10779. SYS_MODE_PREPARING = 5,
  10780. SYS_MODE_PREPARE_FOR_EV = 6,
  10781. SYS_MODE_PREPARE_FOR_EVSE = 7,
  10782. SYS_MODE_CHARGING = 8,
  10783. SYS_MODE_TERMINATING = 9,
  10784. SYS_MODE_COMPLETE = 10,
  10785. SYS_MODE_ALARM = 11,
  10786. SYS_MODE_FAULT = 12,
  10787. SYS_MODE_RESERVATION = 13,
  10788. SYS_MODE_BOOKING = 14,
  10789. SYS_MODE_MAINTAIN = 15,
  10790. SYS_MODE_DEBUG = 16,
  10791. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  10792. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  10793. SYS_MODE_UPDATE = 19
  10794. };
  10795. */
  10796. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  10797. {
  10798. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10799. goto end;
  10800. }
  10801. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  10802. {
  10803. //check Transaction active
  10804. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10805. {
  10806. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10807. {
  10808. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10809. }
  10810. else
  10811. {
  10812. tempIndex = connectorIdInt -1;
  10813. }
  10814. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10815. {
  10816. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10817. {
  10818. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10819. {
  10820. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10821. {
  10822. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10823. {
  10824. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10825. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10826. }
  10827. 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'))
  10828. {
  10829. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10830. }
  10831. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10832. {
  10833. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10834. }
  10835. else
  10836. {
  10837. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10838. }
  10839. }
  10840. 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
  10841. {
  10842. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10843. }
  10844. }
  10845. else
  10846. {
  10847. //replace reservation
  10848. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10849. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10850. }
  10851. }
  10852. } // END FOR CHAdeMO_QUANTITY
  10853. }
  10854. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10855. {
  10856. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10857. {
  10858. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10859. }
  10860. else
  10861. {
  10862. tempIndex = connectorIdInt -1;
  10863. }
  10864. for (int index = 0; index < CCS_QUANTITY; index++)
  10865. {
  10866. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10867. {
  10868. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10869. {
  10870. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10871. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10872. {
  10873. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10874. {
  10875. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10876. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10877. }
  10878. 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'))
  10879. {
  10880. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10881. }
  10882. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  10883. {
  10884. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10885. }
  10886. else
  10887. {
  10888. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10889. }
  10890. }
  10891. 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
  10892. {
  10893. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10894. }
  10895. }
  10896. else
  10897. {
  10898. //replace reservation
  10899. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10900. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10901. }
  10902. }
  10903. } // END FOR CCS_QUANTITY
  10904. }
  10905. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10906. {
  10907. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10908. {
  10909. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10910. }
  10911. else
  10912. {
  10913. tempIndex = connectorIdInt -1;
  10914. }
  10915. for (int index = 0; index < GB_QUANTITY; index++)
  10916. {
  10917. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10918. {
  10919. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10920. {
  10921. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10922. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10923. {
  10924. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10925. {
  10926. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10927. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10928. }
  10929. 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'))
  10930. {
  10931. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10932. }
  10933. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10934. {
  10935. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10936. }
  10937. else
  10938. {
  10939. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10940. }
  10941. }
  10942. 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
  10943. {
  10944. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10945. }
  10946. }
  10947. else
  10948. {
  10949. //replace reservation
  10950. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10951. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10952. }
  10953. }
  10954. }// END FOR GB_QUANTITY
  10955. }
  10956. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10957. {
  10958. tempIndex = connectorIdInt -1;
  10959. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10960. {
  10961. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10962. {
  10963. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  10964. {
  10965. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10966. 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
  10967. {
  10968. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10969. {
  10970. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10971. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10972. }
  10973. 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'))
  10974. {
  10975. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10976. }
  10977. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10978. {
  10979. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10980. }
  10981. else
  10982. {
  10983. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10984. }
  10985. }
  10986. 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
  10987. {
  10988. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10989. }
  10990. }
  10991. else
  10992. {
  10993. //replace reservation
  10994. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10995. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10996. }
  10997. }
  10998. }// END FOR GB_QUANTITY
  10999. }
  11000. else
  11001. {
  11002. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11003. {
  11004. tempIndex = 2;
  11005. }
  11006. else
  11007. {
  11008. tempIndex = (connectorIdInt -1);
  11009. }
  11010. for (int index = 0; index < AC_QUANTITY; index++)
  11011. {
  11012. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11013. {
  11014. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11015. {
  11016. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11017. {
  11018. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11019. {
  11020. 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))
  11021. {
  11022. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11023. }
  11024. else
  11025. {
  11026. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11027. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11028. }
  11029. }
  11030. 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'))
  11031. {
  11032. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11033. }
  11034. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11035. {
  11036. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11037. }
  11038. else
  11039. {
  11040. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11041. }
  11042. }
  11043. 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
  11044. {
  11045. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11046. }
  11047. }
  11048. else
  11049. {
  11050. //replace reservation
  11051. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11052. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11053. }
  11054. }
  11055. } // END FOR AC_QUANTITY
  11056. }
  11057. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11058. }
  11059. else if(connectorIdInt == 0)
  11060. {
  11061. //check Transaction active
  11062. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11063. {
  11064. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11065. {
  11066. 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'))
  11067. {
  11068. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11069. goto end;
  11070. }
  11071. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11072. {
  11073. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11074. goto end;
  11075. }
  11076. 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
  11077. {
  11078. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11079. goto end;
  11080. }
  11081. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11082. {
  11083. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11084. goto end;
  11085. }
  11086. }
  11087. }// END FOR CHAdeMO_QUANTITY
  11088. for (int index = 0; index < CCS_QUANTITY; index++)
  11089. {
  11090. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11091. {
  11092. 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'))
  11093. {
  11094. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11095. goto end;
  11096. }
  11097. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11098. {
  11099. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11100. goto end;
  11101. }
  11102. 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
  11103. {
  11104. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11105. goto end;
  11106. }
  11107. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11108. {
  11109. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11110. goto end;
  11111. }
  11112. }
  11113. } // END FOR CCS_QUANTITY
  11114. for (int index = 0; index < GB_QUANTITY; index++)
  11115. {
  11116. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11117. {
  11118. 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'))
  11119. {
  11120. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11121. goto end;
  11122. }
  11123. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11124. {
  11125. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11126. goto end;
  11127. }
  11128. 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
  11129. {
  11130. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11131. goto end;
  11132. }
  11133. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11134. {
  11135. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11136. goto end;
  11137. }
  11138. }
  11139. } // END FOR GB_QUANTITY
  11140. for (int index = 0; index < AC_QUANTITY; index++)
  11141. {
  11142. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11143. {
  11144. 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'))
  11145. {
  11146. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11147. goto end;
  11148. }
  11149. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11150. {
  11151. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11152. goto end;
  11153. }
  11154. 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
  11155. {
  11156. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11157. goto end;
  11158. }
  11159. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11160. {
  11161. 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))
  11162. {
  11163. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11164. goto end;
  11165. }
  11166. }
  11167. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11168. {
  11169. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11170. goto end;
  11171. }
  11172. }
  11173. }// END FOR AC_QUANTITY
  11174. //The connectorId is 0
  11175. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  11176. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11177. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11178. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  11179. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11180. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  11181. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11182. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  11183. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  11184. result = TRUE;
  11185. return result;
  11186. }
  11187. else
  11188. {
  11189. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11190. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11191. }
  11192. if(strcmp(comfirmstr,"Accepted") == 0)
  11193. {
  11194. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11195. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11196. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11197. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11198. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11199. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  11200. result = TRUE;
  11201. return result;
  11202. }
  11203. end:
  11204. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11205. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11206. return result;
  11207. }
  11208. int handleResetRequest(char *uuid, char *payload)
  11209. {
  11210. mtrace();
  11211. int result = FAIL;
  11212. char sstr[10]={0},sstrtemp[30]={ 0 };
  11213. char typestr[10]={0};
  11214. char comfirmstr[20]={0};
  11215. int c = 0;
  11216. char *loc;
  11217. DEBUG_INFO("handleResetRequest...\n");
  11218. strcpy(sstrtemp, stringtrimspace(payload));
  11219. loc = strstr(sstrtemp, "type");
  11220. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11221. c = 0;
  11222. while (loc[3+strlen("type")+c] != '\"')
  11223. {
  11224. sstr[c] = loc[3+strlen("type")+c];
  11225. c++;
  11226. }
  11227. sstr[c] = '\0';
  11228. strcpy(typestr,sstr);
  11229. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11230. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11231. {
  11232. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11233. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  11234. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11235. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11236. }
  11237. else
  11238. {
  11239. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11240. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11241. result = PASS;
  11242. }
  11243. sendResetConfirmation(uuid, comfirmstr);
  11244. return result;
  11245. }
  11246. int handleSendLocalListRequest(char *uuid, char *payload)
  11247. {
  11248. mtrace();
  11249. int result = FAIL;
  11250. char comfirmstr[20];
  11251. int checkState_Faulted = FALSE;
  11252. json_object *SendLocalList;
  11253. DEBUG_INFO("handleSendLocalListRequest...\n");
  11254. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11255. {
  11256. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11257. goto end;
  11258. }
  11259. //check Charge Point state
  11260. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11261. {
  11262. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11263. {
  11264. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11265. }
  11266. }
  11267. for (int index = 0; index < CCS_QUANTITY; index++)
  11268. {
  11269. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11270. {
  11271. checkState_Faulted = TRUE; //OCPP Status
  11272. }
  11273. }
  11274. for (int index = 0; index < GB_QUANTITY; index++)
  11275. {
  11276. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11277. {
  11278. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11279. }
  11280. }
  11281. //check Charge Point state
  11282. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11283. {
  11284. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11285. {
  11286. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11287. }
  11288. }
  11289. //check Charge Point state
  11290. for (int index = 0; index < AC_QUANTITY; index++)
  11291. {
  11292. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11293. {
  11294. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11295. }
  11296. }
  11297. if(checkState_Faulted == TRUE)
  11298. {
  11299. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11300. goto end;
  11301. }
  11302. // Parsing payload
  11303. SendLocalList = json_tokener_parse(payload);
  11304. if(!is_error(SendLocalList))
  11305. {
  11306. // Required data
  11307. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11308. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11309. // Optional data
  11310. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11311. {
  11312. //Check UpdateType
  11313. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11314. {
  11315. //Local list full update
  11316. DEBUG_INFO("Local list full update.\n");
  11317. OCPP_getListVerion();
  11318. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11319. {
  11320. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11321. goto end;
  11322. }
  11323. OCPP_cleanLocalList();
  11324. }
  11325. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11326. {
  11327. //Local list different update
  11328. DEBUG_INFO("Local list different update.\n");
  11329. OCPP_getListVerion();
  11330. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11331. {
  11332. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11333. goto end;
  11334. }
  11335. }
  11336. else
  11337. {
  11338. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11339. goto end;
  11340. }
  11341. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11342. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11343. {
  11344. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag")));
  11345. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11346. {
  11347. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "status")));
  11348. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11349. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate")));
  11350. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11351. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag")));
  11352. }
  11353. // Add to db
  11354. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11355. {
  11356. //Local list full update
  11357. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11358. idx,
  11359. ShmOCPP16Data->SendLocalList.ListVersion,
  11360. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11361. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11362. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11363. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11364. // update list
  11365. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11366. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11367. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11368. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11369. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11370. }
  11371. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11372. {
  11373. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11374. idx,
  11375. ShmOCPP16Data->SendLocalList.ListVersion,
  11376. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11377. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11378. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11379. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11380. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11381. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11382. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11383. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11384. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11385. }
  11386. }
  11387. }
  11388. else
  11389. {
  11390. //Check UpdateType
  11391. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11392. {
  11393. //Local list full update
  11394. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11395. OCPP_cleanLocalList();
  11396. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11397. goto end;
  11398. }
  11399. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11400. {
  11401. //Local list different update
  11402. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11403. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11404. goto end;
  11405. }
  11406. }
  11407. result = PASS;
  11408. }
  11409. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11410. end:
  11411. json_object_put(SendLocalList);
  11412. sendSendLocalListConfirmation(uuid, comfirmstr);
  11413. return result;
  11414. }
  11415. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11416. {
  11417. mtrace();
  11418. int result = FAIL;
  11419. struct StructSetChargingProfile SetProfileReq = {0};
  11420. int tempchargingProfileIdInt;
  11421. int chargingSchedulePeriodCount = 0;
  11422. char comfirmstr[20]={0};
  11423. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  11424. char rmFileCmd[128]={0};
  11425. int profileQuantity = 0;
  11426. json_object *SetChargingProfile;
  11427. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11428. SetChargingProfile = json_tokener_parse(payload);
  11429. if(!is_error(SetChargingProfile))
  11430. {
  11431. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11432. {
  11433. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11434. }
  11435. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11436. {
  11437. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11438. {
  11439. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11440. }
  11441. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11442. {
  11443. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11444. }
  11445. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11446. {
  11447. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11448. }
  11449. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11450. {
  11451. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11452. }
  11453. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11454. {
  11455. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11456. }
  11457. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11458. {
  11459. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11460. }
  11461. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11462. {
  11463. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11464. }
  11465. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11466. {
  11467. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11468. }
  11469. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11470. {
  11471. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11472. {
  11473. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  11474. }
  11475. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11476. {
  11477. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11478. }
  11479. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11480. {
  11481. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11482. }
  11483. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11484. {
  11485. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.StartSchedule, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  11486. }
  11487. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11488. {
  11489. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11490. if(chargingSchedulePeriodCount <= 10)
  11491. {
  11492. 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++)
  11493. {
  11494. 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)
  11495. {
  11496. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  11497. }
  11498. 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)
  11499. {
  11500. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  11501. }
  11502. 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)
  11503. {
  11504. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  11505. }
  11506. }
  11507. }
  11508. }
  11509. }
  11510. }
  11511. }
  11512. // Profile periods quantity check
  11513. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11514. {
  11515. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11516. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11517. goto end;
  11518. }
  11519. // Profile purpose info check
  11520. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11521. {
  11522. FILE *fp;
  11523. char dataLine[4096]={0};
  11524. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11525. if(SetProfileReq.ConnectorId != 0)
  11526. {
  11527. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11528. DEBUG_WARN("Profile connector id is not 0.\n");
  11529. goto end;
  11530. }
  11531. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11532. if (!fp)
  11533. {
  11534. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11535. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11536. }
  11537. else
  11538. {
  11539. while(fscanf(fp, "%s", dataLine) != EOF)
  11540. {
  11541. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11542. {
  11543. profileQuantity += 1;
  11544. }
  11545. }
  11546. }
  11547. fclose(fp);
  11548. }
  11549. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11550. {
  11551. FILE *fp;
  11552. char dataLine[4096]={0};
  11553. char filename[128]={0};
  11554. int tmpProfileQuantity;
  11555. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  11556. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11557. {
  11558. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11559. DEBUG_WARN("Profile connector id is over max gun number.\n");
  11560. goto end;
  11561. }
  11562. if(SetProfileReq.ConnectorId == 0)
  11563. {
  11564. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  11565. {
  11566. tmpProfileQuantity = 0;
  11567. memset(filename, 0, ARRAY_SIZE(filename));
  11568. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  11569. fp = fopen(filename, "r");
  11570. if (!fp)
  11571. {
  11572. DEBUG_INFO("%s does not create.\n", filename);
  11573. fp = fopen(filename, "w+");
  11574. }
  11575. else
  11576. {
  11577. while(fscanf(fp, "%s", dataLine) != EOF)
  11578. {
  11579. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11580. {
  11581. tmpProfileQuantity += 1;
  11582. }
  11583. }
  11584. }
  11585. fclose(fp);
  11586. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  11587. }
  11588. }
  11589. else
  11590. {
  11591. memset(filename, 0, ARRAY_SIZE(filename));
  11592. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11593. fp = fopen(filename, "r");
  11594. if (!fp)
  11595. {
  11596. DEBUG_INFO("%s does not create.\n", filename);
  11597. fp = fopen(filename, "w+");
  11598. }
  11599. else
  11600. {
  11601. while(fscanf(fp, "%s", dataLine) != EOF)
  11602. {
  11603. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11604. {
  11605. profileQuantity += 1;
  11606. }
  11607. }
  11608. }
  11609. fclose(fp);
  11610. }
  11611. }
  11612. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11613. {
  11614. int isMatchTransactiodId= FALSE;
  11615. FILE *fp;
  11616. char dataLine[4096]={0};
  11617. char filename[128]={0};
  11618. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  11619. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  11620. if(SetProfileReq.ConnectorId == 0)
  11621. {
  11622. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11623. DEBUG_WARN("Profile connector id is 0.\n");
  11624. goto end;
  11625. }
  11626. int tempIndex = 0;
  11627. //check Transaction active
  11628. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  11629. {
  11630. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11631. {
  11632. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11633. }
  11634. else
  11635. {
  11636. tempIndex = SetProfileReq.ConnectorId -1;
  11637. }
  11638. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11639. {
  11640. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11641. {
  11642. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11643. {
  11644. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11645. {
  11646. isMatchTransactiodId = TRUE;
  11647. break;
  11648. }
  11649. }
  11650. }
  11651. }
  11652. }
  11653. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  11654. {
  11655. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11656. {
  11657. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11658. }
  11659. else
  11660. {
  11661. tempIndex = SetProfileReq.ConnectorId -1;
  11662. }
  11663. for (int index = 0; index < CCS_QUANTITY; index++)
  11664. {
  11665. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11666. {
  11667. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  11668. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11669. {
  11670. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11671. {
  11672. isMatchTransactiodId = TRUE;
  11673. break;
  11674. }
  11675. }
  11676. }
  11677. }
  11678. }
  11679. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  11680. {
  11681. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11682. {
  11683. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11684. }
  11685. else
  11686. {
  11687. tempIndex = SetProfileReq.ConnectorId -1;
  11688. }
  11689. for (int index = 0; index < GB_QUANTITY; index++)
  11690. {
  11691. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11692. {
  11693. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11694. {
  11695. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11696. {
  11697. isMatchTransactiodId = TRUE;
  11698. break;
  11699. }
  11700. }
  11701. }
  11702. }
  11703. }
  11704. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  11705. {
  11706. tempIndex = SetProfileReq.ConnectorId -1;
  11707. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11708. {
  11709. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11710. {
  11711. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  11712. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11713. {
  11714. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11715. {
  11716. isMatchTransactiodId = TRUE;
  11717. break;
  11718. }
  11719. }
  11720. }
  11721. }
  11722. }
  11723. else
  11724. {
  11725. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11726. {
  11727. tempIndex = 2;
  11728. }
  11729. else
  11730. {
  11731. tempIndex = (SetProfileReq.ConnectorId -1);
  11732. }
  11733. for (int index = 0; index < AC_QUANTITY; index++)
  11734. {
  11735. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11736. {
  11737. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  11738. {
  11739. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11740. {
  11741. isMatchTransactiodId = TRUE;
  11742. break;
  11743. }
  11744. }
  11745. }
  11746. }
  11747. }
  11748. //check Transaction active
  11749. if(isMatchTransactiodId == FALSE)
  11750. {
  11751. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11752. DEBUG_WARN("Tx profile transaction id is not match.\n");
  11753. goto end;
  11754. }
  11755. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11756. {
  11757. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11758. DEBUG_WARN("Connector id is over max gun number.\n");
  11759. goto end;
  11760. }
  11761. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11762. fp = fopen(filename, "r");
  11763. if (!fp)
  11764. {
  11765. DEBUG_INFO("%s does not create.\n", filename);
  11766. fp = fopen(filename, "w+");
  11767. }
  11768. else
  11769. {
  11770. //Check Charging Profile Count
  11771. while(fscanf(fp, "%s", dataLine) != EOF)
  11772. {
  11773. //DEBUG_INFO("word=%s\n",word);
  11774. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11775. {
  11776. profileQuantity += 1;
  11777. }
  11778. }
  11779. }
  11780. fclose(fp);
  11781. }
  11782. // Check ChargeProfileMaxStackLevel
  11783. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  11784. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  11785. {
  11786. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11787. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11788. goto end;
  11789. }
  11790. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11791. {
  11792. FILE *fp;
  11793. char dataLine[4096]={0};
  11794. char fnametemp[128]={0};
  11795. int tmpProfileQuantity;
  11796. //Check ChargePointMaxProfile.json exit
  11797. profileQuantity = 0;
  11798. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  11799. {
  11800. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  11801. //Check Charging Profile Count
  11802. tmpProfileQuantity = 0;
  11803. while(fscanf(fp, "%s", dataLine) != EOF)
  11804. {
  11805. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11806. {
  11807. profileQuantity += 1;
  11808. tmpProfileQuantity += 1;
  11809. }
  11810. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11811. }
  11812. fclose(fp);
  11813. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  11814. }
  11815. //Check TxDefaultProfile_%d.json
  11816. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11817. {
  11818. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11819. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  11820. if((access(fnametemp,F_OK))!=-1)
  11821. {
  11822. fp = fopen(fnametemp, "r");
  11823. //Check Charging Profile Count
  11824. tmpProfileQuantity = 0;
  11825. while(fscanf(fp, "%s", dataLine) != EOF)
  11826. {
  11827. //DEBUG_INFO("word=%s\n",word);
  11828. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11829. {
  11830. profileQuantity += 1;
  11831. tmpProfileQuantity += 1;
  11832. }
  11833. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11834. }
  11835. fclose(fp);
  11836. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11837. }
  11838. }
  11839. //Check TxProfile_%d.json
  11840. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11841. {
  11842. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11843. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  11844. if((access(fnametemp,F_OK))!=-1)
  11845. {
  11846. fp = fopen(fnametemp, "r");
  11847. //Check Charging Profile Count
  11848. tmpProfileQuantity = 0;
  11849. while(fscanf(fp, "%s", dataLine) != EOF)
  11850. {
  11851. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11852. {
  11853. profileQuantity += 1;
  11854. tmpProfileQuantity += 1;
  11855. }
  11856. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11857. }
  11858. fclose(fp);
  11859. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11860. }
  11861. }
  11862. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  11863. if(profileQuantity > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  11864. {
  11865. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11866. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11867. goto end;
  11868. }
  11869. }
  11870. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11871. //**********************************Write to File********************************************************/
  11872. {
  11873. FILE *infile;
  11874. FILE *outfile;
  11875. char dataLine[4096]={0};
  11876. char filename[128]={0};
  11877. int chkChar=0;
  11878. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  11879. {
  11880. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11881. {
  11882. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  11883. }
  11884. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11885. {
  11886. if(SetProfileReq.ConnectorId==0)
  11887. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  11888. else
  11889. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11890. }
  11891. else
  11892. {
  11893. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11894. }
  11895. infile = fopen (filename, "r");
  11896. outfile = fopen (tempfile, "w");
  11897. chkChar = fgetc(infile);
  11898. rewind(infile);
  11899. if(chkChar == EOF)
  11900. {
  11901. // Profile is empty
  11902. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11903. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11904. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11905. fclose(infile);
  11906. fclose(outfile);
  11907. sprintf(rmFileCmd,"rm -f %s",filename);
  11908. system(rmFileCmd);
  11909. rename(tempfile, filename);
  11910. }
  11911. else
  11912. {
  11913. // Profile is not empty
  11914. int ChargingProfileAdded = FALSE;
  11915. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  11916. {
  11917. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  11918. json_object *tmpChargingProfile;
  11919. tmpChargingProfile = json_tokener_parse(dataLine);
  11920. if(!is_error(SetChargingProfile))
  11921. {
  11922. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  11923. {
  11924. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11925. {
  11926. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11927. }
  11928. }
  11929. }
  11930. json_object_put(tmpChargingProfile);
  11931. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  11932. {
  11933. if(ChargingProfileAdded == FALSE)
  11934. {
  11935. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11936. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11937. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11938. ChargingProfileAdded = TRUE;
  11939. }
  11940. }
  11941. else
  11942. {
  11943. fprintf(outfile,"%s\n",dataLine);
  11944. if(ChargingProfileAdded == FALSE)
  11945. {
  11946. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11947. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11948. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11949. ChargingProfileAdded = TRUE;
  11950. }
  11951. }
  11952. } // end of while loop
  11953. fclose(infile);
  11954. fclose(outfile);
  11955. sprintf(rmFileCmd,"rm -f %s",filename);
  11956. system(rmFileCmd);
  11957. rename(tempfile, filename);
  11958. }
  11959. }
  11960. sleep(1);
  11961. result = TRUE;
  11962. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  11963. }
  11964. end:
  11965. json_object_put(SetChargingProfile);
  11966. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  11967. {
  11968. if(SetProfileReq.ConnectorId == 0)
  11969. {
  11970. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  11971. {
  11972. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  11973. }
  11974. }
  11975. else
  11976. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  11977. }
  11978. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  11979. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11980. return result;
  11981. }
  11982. int handleTriggerMessageRequest(char *uuid, char *payload)
  11983. {
  11984. mtrace();
  11985. int result = FAIL;
  11986. int connectorIdIsNULL = FALSE;
  11987. int connectorIdInt =0;
  11988. char sstr[40]={0},sstrtemp[100]={ 0 };
  11989. char requestedMessagestr[40]={0};
  11990. char comfirmstr[20]={0};
  11991. int c = 0;
  11992. char *loc;
  11993. DEBUG_INFO("handleTriggerMessageRequest\n");
  11994. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  11995. strcpy(sstrtemp, stringtrimspace(payload));
  11996. c = 0;
  11997. loc = strstr(sstrtemp, "requestedMessage");
  11998. while (loc[3+strlen("requestedMessage")+c] != '\"')
  11999. {
  12000. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12001. c++;
  12002. }
  12003. sstr[c] = '\0';
  12004. strcpy(requestedMessagestr, sstr);
  12005. c = 0;
  12006. loc = strstr(sstrtemp, "connectorId");
  12007. if(loc == NULL)
  12008. {
  12009. connectorIdIsNULL = TRUE;
  12010. }
  12011. else
  12012. {
  12013. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12014. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12015. {
  12016. sstr[c] = loc[strlen("connectorId")+2+c];
  12017. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12018. c++;
  12019. }
  12020. sstr[c] = '\0';
  12021. connectorIdInt = atoi(sstr);
  12022. }
  12023. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12024. {
  12025. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12026. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12027. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12028. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12029. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12030. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12031. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12032. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12033. {
  12034. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12035. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12036. return TRUE;
  12037. }
  12038. else
  12039. {
  12040. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12041. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12042. }
  12043. }
  12044. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12045. {
  12046. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12047. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12048. return TRUE;
  12049. }
  12050. //==========================
  12051. // Trigger message
  12052. //==========================
  12053. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12054. {
  12055. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  12056. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12057. {
  12058. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12059. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12060. }
  12061. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12062. }
  12063. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12064. {
  12065. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  12066. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12067. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12068. }
  12069. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12070. {
  12071. //sendBootNotificationRequest();
  12072. server_sign = FALSE;
  12073. }
  12074. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12075. {
  12076. refreshStartTimer(&clientTime.Heartbeat);
  12077. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  12078. }
  12079. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12080. {
  12081. if(connectorIdIsNULL == FALSE)
  12082. {
  12083. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12084. {
  12085. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12086. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12087. }
  12088. }
  12089. else
  12090. {
  12091. for(int idx=0;idx< gunTotalNumber;idx++)
  12092. {
  12093. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12094. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12095. }
  12096. }
  12097. }
  12098. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12099. {
  12100. if(connectorIdIsNULL == FALSE)
  12101. {
  12102. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  12103. {
  12104. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12105. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  12106. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12107. }
  12108. }
  12109. else
  12110. {
  12111. for(int idx=0;idx< gunTotalNumber;idx++)
  12112. {
  12113. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  12114. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12115. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12116. }
  12117. }
  12118. }
  12119. return result;
  12120. }
  12121. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12122. {
  12123. mtrace();
  12124. int result = FAIL;
  12125. int connectorIdInt =0;
  12126. char comfirmstr[20]={0};
  12127. int tempIndex = 0;
  12128. json_object *UnlockConnector;
  12129. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12130. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12131. UnlockConnector = json_tokener_parse(payload);
  12132. if(!is_error(UnlockConnector))
  12133. {
  12134. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12135. {
  12136. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12137. }
  12138. }
  12139. json_object_put(UnlockConnector);
  12140. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12141. if(gunTotalNumber == 0)
  12142. {
  12143. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12144. goto end;
  12145. }
  12146. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12147. {
  12148. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12149. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12150. goto end;
  12151. }
  12152. else
  12153. {
  12154. //check Transaction active
  12155. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12156. {
  12157. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12158. {
  12159. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12160. }
  12161. else
  12162. {
  12163. tempIndex = connectorIdInt -1;
  12164. }
  12165. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12166. {
  12167. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12168. {
  12169. //stop Transaction
  12170. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12171. }
  12172. }
  12173. }
  12174. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12175. {
  12176. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12177. {
  12178. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12179. }
  12180. else
  12181. {
  12182. tempIndex = connectorIdInt -1;
  12183. }
  12184. for (int index = 0; index < CCS_QUANTITY; index++)
  12185. {
  12186. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12187. {
  12188. //stop Transaction
  12189. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12190. }
  12191. }
  12192. }
  12193. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12194. {
  12195. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12196. {
  12197. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12198. }
  12199. else
  12200. {
  12201. tempIndex = connectorIdInt -1;
  12202. }
  12203. for (int index = 0; index < GB_QUANTITY; index++)
  12204. {
  12205. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12206. {
  12207. //stop Transaction
  12208. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12209. }
  12210. }
  12211. }
  12212. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12213. {
  12214. tempIndex = connectorIdInt -1;
  12215. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12216. {
  12217. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12218. {
  12219. //stop Transaction
  12220. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12221. }
  12222. }
  12223. }
  12224. else
  12225. {
  12226. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12227. {
  12228. tempIndex = 2;
  12229. }
  12230. else
  12231. {
  12232. tempIndex = connectorIdInt-1;
  12233. }
  12234. for (int index = 0; index < AC_QUANTITY; index++)
  12235. {
  12236. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12237. {
  12238. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12239. }
  12240. }
  12241. }
  12242. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12243. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  12244. result = TRUE;
  12245. return result;
  12246. }
  12247. end:
  12248. //json_object_put(obj); --- remove temporally
  12249. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12250. return result;
  12251. }
  12252. static char UpdateFirmwarepayloadData[300]={0};
  12253. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12254. {
  12255. mtrace();
  12256. int result = FAIL;
  12257. pthread_t t;
  12258. sendUpdateFirmwareConfirmation(uuid);
  12259. memset(UpdateFirmwarepayloadData, 0, 300);
  12260. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12261. if(!interLock.isUpdateFirmwareGoing)
  12262. {
  12263. interLock.isUpdateFirmwareGoing = 1;
  12264. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12265. sleep(1);
  12266. }
  12267. else
  12268. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12269. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  12270. return result;
  12271. }
  12272. void *UpdateFirmwareProcess(void *data)
  12273. {
  12274. pthread_detach(pthread_self());
  12275. mtrace();
  12276. int retriesInt =0, retryIntervalInt=0;
  12277. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  12278. int port=0;
  12279. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  12280. int isSuccess = 0;
  12281. char ftpbuf[1024];
  12282. char temp[1024];
  12283. char * pch;
  12284. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12285. json_object *UpdateFirmware;
  12286. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12287. if(!is_error(UpdateFirmware))
  12288. {
  12289. // Required data
  12290. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12291. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12292. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12293. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12294. // Optional data
  12295. if(json_object_object_get(UpdateFirmware, "retries"))
  12296. {
  12297. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12298. }
  12299. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12300. {
  12301. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12302. }
  12303. }
  12304. json_object_put(UpdateFirmware);
  12305. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12306. memset(path, 0, ARRAY_SIZE(path));
  12307. // Wait retrieveData
  12308. if(strlen(retrieveDatestr) > 10)
  12309. {
  12310. do
  12311. {
  12312. sleep(1);
  12313. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12314. }
  12315. // Ready to download
  12316. system("rm -f /mnt/*");
  12317. if(strncmp(locationstr,"http", 4) == 0)
  12318. {
  12319. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12320. sprintf(ftppath,"/%s", path);
  12321. DEBUG_INFO("locationstr: %s\n", locationstr);
  12322. DEBUG_INFO("protocol: %s\n",protocol);
  12323. DEBUG_INFO("host: %s\n",host);
  12324. DEBUG_INFO("path: %s\n",path);
  12325. DEBUG_INFO("ftppath: %s\n",ftppath);
  12326. int ftppathlen=strlen(ftppath);
  12327. int i=1;
  12328. char filenametemp[50];
  12329. while(i < ftppathlen)
  12330. {
  12331. int len=ftppathlen-i;
  12332. if(ftppath[len]== 47) // '/' ascll code: 47
  12333. {
  12334. DEBUG_INFO("compare '/' all right\n");
  12335. break;
  12336. }
  12337. i=i+1;
  12338. }
  12339. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12340. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12341. filenametemp[i+1] = 0;
  12342. do
  12343. {
  12344. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12345. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12346. sleep(1);
  12347. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12348. if(!isSuccess)
  12349. {
  12350. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12351. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12352. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12353. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12354. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12355. }
  12356. else
  12357. {
  12358. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12359. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12360. }
  12361. retriesInt--;
  12362. }while((isSuccess == 0)&&(retriesInt >= 0));
  12363. }
  12364. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12365. {
  12366. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12367. memset(temp, 0, ARRAY_SIZE(temp));
  12368. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12369. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12370. int ftppathlen=strlen(ftpbuf);
  12371. int i=1;
  12372. char filenametemp[50];
  12373. while(i < ftppathlen)
  12374. {
  12375. int len=ftppathlen-i;
  12376. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12377. {
  12378. DEBUG_INFO(" compare '/' all right\n");
  12379. break;
  12380. }
  12381. i=i+1;
  12382. }
  12383. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12384. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12385. filenametemp[i+1] = 0;
  12386. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12387. pch=strchr(temp,'@');
  12388. if(pch==NULL)
  12389. {
  12390. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12391. protocol, host, &port, path);
  12392. strcpy(user,"anonymous");
  12393. strcpy(password,"");
  12394. }
  12395. else
  12396. {
  12397. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12398. protocol, user, password, host, &port, path);
  12399. }
  12400. sscanf(host,"%[^/]%s",host1, path1);
  12401. sprintf(ftppath,"%s", path1);
  12402. //DEBUG_INFO("protocol =%s\n",protocol);
  12403. //DEBUG_INFO("user =%s\n",user);
  12404. //DEBUG_INFO("password =%s\n",password);
  12405. //DEBUG_INFO("host1 =%s\n",host1);
  12406. //DEBUG_INFO("port =%d\n",port);
  12407. //DEBUG_INFO("path1 =%s\n",path1);
  12408. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12409. //ftpFile(host, user, password, port, ftppath, fname);
  12410. //download firmware pthred
  12411. if(port == 0)
  12412. {
  12413. port = 21;
  12414. }
  12415. do
  12416. {
  12417. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12418. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12419. sleep(1);
  12420. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12421. if(!isSuccess)
  12422. {
  12423. //BulldogUtil.sleepMs(interval*1000);
  12424. DEBUG_INFO("Update firmware request and download file fail.\n");
  12425. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12426. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12427. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12428. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12429. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12430. }
  12431. else
  12432. {
  12433. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12434. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12435. }
  12436. retriesInt--;
  12437. }while((!isSuccess)&&(retriesInt >= 0));
  12438. }
  12439. else
  12440. {
  12441. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12442. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12443. sleep(1);
  12444. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12445. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12446. }
  12447. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12448. interLock.isUpdateFirmwareGoing = 0;
  12449. pthread_exit(NULL);
  12450. }
  12451. int handleCertificateSignedRequest(char *uuid, char *payload)
  12452. {
  12453. mtrace();
  12454. int result = PASS;
  12455. json_object *CertificateSigned;
  12456. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12457. CertificateSigned = json_tokener_parse(payload);
  12458. if(!is_error(CertificateSigned))
  12459. {
  12460. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  12461. }
  12462. json_object_put(CertificateSigned);
  12463. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  12464. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  12465. fclose(fp);
  12466. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12467. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  12468. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  12469. sendCertificateSignedConfirmation(uuid);
  12470. return result;
  12471. }
  12472. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12473. {
  12474. mtrace();
  12475. int result = PASS;
  12476. json_object *DeleteCertificate;
  12477. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12478. DeleteCertificate = json_tokener_parse(payload);
  12479. if(!is_error(DeleteCertificate))
  12480. {
  12481. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12482. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12483. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12484. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12485. }
  12486. json_object_put(DeleteCertificate);
  12487. /*
  12488. * TODO: Delete certificateSigned process
  12489. */
  12490. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  12491. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  12492. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  12493. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  12494. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  12495. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  12496. sendDeleteCertificateConfirmation(uuid);
  12497. return result;
  12498. }
  12499. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  12500. {
  12501. mtrace();
  12502. int result = PASS;
  12503. json_object *ExtendedTriggerMessage;
  12504. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  12505. ExtendedTriggerMessage = json_tokener_parse(payload);
  12506. if(!is_error(ExtendedTriggerMessage))
  12507. {
  12508. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  12509. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  12510. {
  12511. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  12512. }
  12513. else
  12514. {
  12515. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  12516. }
  12517. }
  12518. json_object_put(ExtendedTriggerMessage);
  12519. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  12520. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  12521. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  12522. {
  12523. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  12524. }
  12525. else
  12526. {
  12527. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  12528. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  12529. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12530. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  12531. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  12532. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  12533. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  12534. {
  12535. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12536. }
  12537. else
  12538. {
  12539. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12540. }
  12541. }
  12542. sendExtendedTriggerMessageConfirmation(uuid);
  12543. //==========================
  12544. // Trigger message
  12545. //==========================
  12546. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  12547. {
  12548. //sendBootNotificationRequest();
  12549. server_sign = FALSE;
  12550. }
  12551. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  12552. {
  12553. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  12554. }
  12555. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12556. {
  12557. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  12558. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12559. {
  12560. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12561. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12562. }
  12563. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12564. }
  12565. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  12566. {
  12567. refreshStartTimer(&clientTime.Heartbeat);
  12568. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  12569. }
  12570. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  12571. {
  12572. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12573. {
  12574. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  12575. }
  12576. else
  12577. {
  12578. for(int idx=0;idx< gunTotalNumber;idx++)
  12579. {
  12580. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12581. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12582. }
  12583. }
  12584. }
  12585. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  12586. {
  12587. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  12588. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  12589. {
  12590. 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\" &");
  12591. }
  12592. }
  12593. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  12594. {
  12595. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12596. {
  12597. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  12598. }
  12599. else
  12600. {
  12601. for(int idx=0;idx< gunTotalNumber;idx++)
  12602. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  12603. }
  12604. }
  12605. return result;
  12606. }
  12607. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  12608. {
  12609. mtrace();
  12610. int result = PASS;
  12611. json_object *GetInstalledCertificateIds;
  12612. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  12613. GetInstalledCertificateIds = json_tokener_parse(payload);
  12614. if(!is_error(GetInstalledCertificateIds))
  12615. {
  12616. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  12617. }
  12618. json_object_put(GetInstalledCertificateIds);
  12619. /*
  12620. * TODO: Return installed certificate process
  12621. */
  12622. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  12623. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  12624. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  12625. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  12626. sendGetInstalledCertificateIdsConfirmation(uuid);
  12627. return result;
  12628. }
  12629. int handleGetLogRequest(char *uuid, char *payload)
  12630. {
  12631. mtrace();
  12632. int result = PASS;
  12633. json_object *GetLog;
  12634. DEBUG_INFO("handleGetLogRequest...\n");
  12635. GetLog = json_tokener_parse(payload);
  12636. if(!is_error(GetLog))
  12637. {
  12638. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  12639. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  12640. if(json_object_object_get(GetLog, "retries") != NULL)
  12641. {
  12642. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  12643. }
  12644. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  12645. {
  12646. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  12647. }
  12648. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  12649. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  12650. {
  12651. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  12652. }
  12653. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  12654. {
  12655. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  12656. }
  12657. }
  12658. json_object_put(GetLog);
  12659. /*
  12660. * TODO: Upload log process
  12661. */
  12662. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  12663. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  12664. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  12665. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  12666. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  12667. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  12668. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  12669. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  12670. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  12671. sendGetLogConfirmation(uuid);
  12672. return result;
  12673. }
  12674. int handleInstallCertificateRequest(char *uuid, char *payload)
  12675. {
  12676. mtrace();
  12677. int result = PASS;
  12678. json_object *InstallCertificate;
  12679. DEBUG_INFO("handleInstallCertificateRequest...\n");
  12680. InstallCertificate = json_tokener_parse(payload);
  12681. if(!is_error(InstallCertificate))
  12682. {
  12683. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  12684. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  12685. /*
  12686. * TODO: Install certificate process
  12687. */
  12688. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  12689. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  12690. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  12691. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  12692. sendInstallCertificateConfirmation(uuid);
  12693. }
  12694. json_object_put(InstallCertificate);
  12695. return result;
  12696. }
  12697. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  12698. {
  12699. mtrace();
  12700. int result = PASS;
  12701. json_object *SignedUpdateFirmware;
  12702. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  12703. SignedUpdateFirmware = json_tokener_parse(payload);
  12704. if(!is_error(SignedUpdateFirmware))
  12705. {
  12706. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  12707. {
  12708. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  12709. }
  12710. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  12711. {
  12712. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  12713. }
  12714. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  12715. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  12716. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  12717. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  12718. {
  12719. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  12720. }
  12721. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  12722. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  12723. }
  12724. json_object_put(SignedUpdateFirmware);
  12725. /*
  12726. * TODO: Upgrade firmware process
  12727. */
  12728. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  12729. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  12730. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  12731. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  12732. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  12733. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  12734. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  12735. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  12736. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  12737. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  12738. sendInstallCertificateConfirmation(uuid);
  12739. return result;
  12740. }
  12741. int handleUnknownRequest(char *uuid, char *payload)
  12742. {
  12743. mtrace();
  12744. int result = PASS;
  12745. DEBUG_INFO("handleUnknownRequest...\n");
  12746. sendUnknownConfirmation(uuid);
  12747. result = PASS;
  12748. return result;
  12749. }
  12750. //==========================================
  12751. // Handle server response routine
  12752. //==========================================
  12753. void handleAuthorizeResponse(char *payload, int gun_index)
  12754. {
  12755. mtrace();
  12756. char expiryDatestr[30]={0};
  12757. char parentIdTagstr[20]={0};
  12758. char statusstr[20]={0};
  12759. int expiryDateISNULL=FALSE;
  12760. int parentIdTagISNULL=FALSE;
  12761. DEBUG_INFO("handleAuthorizeResponse...\n");
  12762. json_object *Authorize;
  12763. Authorize = json_tokener_parse(payload);
  12764. if(!is_error(Authorize))
  12765. {
  12766. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  12767. {
  12768. // Required data
  12769. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  12770. // Optional data
  12771. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  12772. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  12773. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  12774. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  12775. }
  12776. }
  12777. json_object_put(Authorize);
  12778. if(expiryDateISNULL == FALSE)
  12779. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  12780. if(parentIdTagISNULL == FALSE)
  12781. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  12782. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  12783. //Update idTag information to authorization cache if supproted
  12784. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  12785. {
  12786. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  12787. }
  12788. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  12789. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  12790. authorizeRetryTimes = 0;
  12791. }
  12792. void handleBootNotificationResponse(char *payload, int gun_index)
  12793. {
  12794. mtrace();
  12795. char statusStr[12]={0};
  12796. char currentTimeStr[30]={0};
  12797. int intervalInt = 0;
  12798. DEBUG_INFO("handleBootNotificationResponse...\n");
  12799. json_object *BootNotification;
  12800. BootNotification = json_tokener_parse(payload);
  12801. if(!is_error(BootNotification))
  12802. {
  12803. // Required data
  12804. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  12805. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  12806. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  12807. }
  12808. json_object_put(BootNotification);
  12809. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12810. BootNotificationInterval = intervalInt;
  12811. HeartBeatWaitTime = intervalInt;
  12812. //write back to ShmOCPP16Data->BootNotification
  12813. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  12814. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12815. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  12816. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  12817. {
  12818. server_sign = TRUE;
  12819. server_pending =FALSE;
  12820. }
  12821. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  12822. {
  12823. server_pending = TRUE;
  12824. }
  12825. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  12826. srand(time(NULL));
  12827. refreshStartTimer(&clientTime.Heartbeat);
  12828. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  12829. SetOcppConnStatus(TRUE);
  12830. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  12831. }
  12832. void handleDataTransferResponse(char *payload, int gun_index)
  12833. {
  12834. char sstr[160]={0};//sstr[200]={ 0 };
  12835. int c = 0;
  12836. char *loc;
  12837. DEBUG_INFO("handleDataTransferResponse ...\n");
  12838. loc = strstr(payload, "status");
  12839. c = 0;
  12840. while (loc[3+strlen("status")+c] != '\"')
  12841. {
  12842. sstr[c] = loc[3+strlen("status")+c];
  12843. c++;
  12844. }
  12845. sstr[c] = '\0';
  12846. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  12847. }
  12848. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  12849. {
  12850. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  12851. //struct json_object *obj;
  12852. // obj = json_tokener_parse(payload);
  12853. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  12854. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  12855. //No fields are defined.
  12856. }
  12857. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12858. {
  12859. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  12860. //struct json_object *obj;
  12861. // obj = json_tokener_parse(payload);
  12862. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  12863. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  12864. //No fields are defined.
  12865. }
  12866. void handleHeartbeatResponse(char *payload, int gun_index)
  12867. {
  12868. mtrace();
  12869. DEBUG_INFO("handleHeartbeatResponse...\n");
  12870. json_object *Heartbeat;
  12871. Heartbeat = json_tokener_parse(payload);
  12872. if(!is_error(Heartbeat))
  12873. {
  12874. // Required data
  12875. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  12876. }
  12877. json_object_put(Heartbeat);
  12878. if(FirstHeartBeat == 0)
  12879. {
  12880. FirstHeartBeat = 1;
  12881. DEBUG_INFO("FirstHeartBeat \n");
  12882. }
  12883. HeartBeatWithNOResponse = 0;
  12884. refreshStartTimer(&clientTime.Heartbeat);
  12885. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  12886. }
  12887. void handleMeterValuesResponse(char *payload, int gun_index)
  12888. {
  12889. mtrace();
  12890. DEBUG_INFO("handleMeterValuesResponse...\n");
  12891. isQueueSendable = 1;
  12892. }
  12893. void handleStartTransactionResponse(char *payload, int gun_index)
  12894. {
  12895. mtrace();
  12896. //int transactionIdInt = 0;
  12897. FILE *outfile;
  12898. char data[100]={0};
  12899. DEBUG_INFO("handleStartTransactionResponse...\n");
  12900. json_object *StartTransaction;
  12901. StartTransaction = json_tokener_parse(payload);
  12902. if(!is_error(StartTransaction))
  12903. {
  12904. // Required data
  12905. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  12906. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  12907. // Optional data
  12908. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  12909. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  12910. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12911. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  12912. }
  12913. json_object_put(StartTransaction);
  12914. isQueueSendable = 1;
  12915. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  12916. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  12917. //-----------Start : write to the Queue TransactionId file -----------------//
  12918. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  12919. {}
  12920. else
  12921. {
  12922. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  12923. if(log == NULL)
  12924. {
  12925. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  12926. return ;
  12927. }
  12928. else
  12929. {
  12930. fclose(log);
  12931. }
  12932. }
  12933. // open file for writing
  12934. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  12935. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  12936. {
  12937. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  12938. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  12939. fputs(data, outfile);
  12940. fclose (outfile);
  12941. }
  12942. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12943. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12944. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  12945. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  12946. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12947. }
  12948. void handleStatusNotificationResponse(char *payload, int gun_index)
  12949. {
  12950. mtrace();
  12951. DEBUG_INFO("handleStatusNotificationResponse...\n");
  12952. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  12953. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  12954. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  12955. }
  12956. void handleStopTransactionnResponse(char *payload, int gun_index)
  12957. {
  12958. mtrace();
  12959. DEBUG_INFO("handleStopTransactionnResponse...\n");
  12960. json_object *StopTransaction;
  12961. StopTransaction = json_tokener_parse(payload);
  12962. if(!is_error(StopTransaction))
  12963. {
  12964. // Optional data
  12965. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  12966. {
  12967. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  12968. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  12969. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  12970. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12971. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  12972. }
  12973. }
  12974. json_object_put(StopTransaction);
  12975. isQueueSendable = 1;
  12976. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  12977. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  12978. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12979. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12980. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  12981. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  12982. }
  12983. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  12984. {
  12985. mtrace();
  12986. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  12987. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  12988. }
  12989. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  12990. {
  12991. mtrace();
  12992. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  12993. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  12994. }
  12995. void handleSignCertificateResponse(char *payload, int gun_index)
  12996. {
  12997. mtrace();
  12998. DEBUG_INFO("handleSignCertificateResponse...\n");
  12999. json_object *SignCertificate;
  13000. SignCertificate = json_tokener_parse(payload);
  13001. if(!is_error(SignCertificate))
  13002. {
  13003. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13004. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  13005. }
  13006. json_object_put(SignCertificate);
  13007. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  13008. }
  13009. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13010. {
  13011. mtrace();
  13012. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13013. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13014. }
  13015. //==========================================
  13016. // Handle Error routine
  13017. //==========================================
  13018. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13019. {
  13020. mtrace();
  13021. #ifdef SystemLogMessage
  13022. DEBUG_INFO("errorCode: %s\n", errorCode);
  13023. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13024. DEBUG_INFO("errorDetails: %s\n", payload);
  13025. #endif
  13026. }
  13027. //===============================================
  13028. // Common routine
  13029. //===============================================
  13030. int initialConfigurationTable(void)
  13031. {
  13032. //clock_t start_t, end_t, total_t;
  13033. FILE *fp;
  13034. FILE *outfile;
  13035. char str[512]={0};
  13036. char sstr[256]={0};
  13037. int c = 0;
  13038. char *loc;
  13039. int confVersion = 10;
  13040. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13041. //start_t = clock();
  13042. //printf("Starting of the program, start_t = %ld\n", start_t);
  13043. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13044. // Check configuration file size is correct
  13045. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  13046. {
  13047. struct stat st;
  13048. stat("/Storage/OCPP/OCPPConfiguration", &st);
  13049. if(st.st_size < 3100)
  13050. {
  13051. system("rm -f /Storage/OCPP/OCPPConfiguration");
  13052. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13053. }
  13054. }
  13055. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  13056. {
  13057. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  13058. if(outfile == NULL)
  13059. {
  13060. DEBUG_INFO("Error opening file\n");
  13061. return FALSE;
  13062. }
  13063. /*Core Profile*/
  13064. //AllowOfflineTxForUnknownId
  13065. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13066. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13067. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13068. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13069. //AuthorizationCacheEnabled
  13070. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13071. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13073. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13074. //AuthorizeRemoteTxRequests
  13075. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13078. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13079. //BlinkRepeat
  13080. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13081. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13083. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13084. //ClockAlignedDataInterval
  13085. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13086. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13088. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13089. //ConnectionTimeOut
  13090. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13093. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13094. //GetConfigurationMaxKeys
  13095. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13097. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13098. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13099. // HeartbeatInterval
  13100. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13103. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13104. // LightIntensity
  13105. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13108. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13109. // LocalAuthorizeOffline
  13110. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13113. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13114. // LocalPreAuthorize
  13115. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13116. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13118. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13119. // MaxEnergyOnInvalidId
  13120. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13123. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13124. // MeterValuesAlignedData
  13125. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13127. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13128. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC,Current.Offered,Power.Offered" );
  13129. else
  13130. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13131. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13132. // MeterValuesAlignedDataMaxLength
  13133. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13135. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13137. else
  13138. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13139. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13140. // MeterValuesSampledData
  13141. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13143. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13144. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC,Current.Offered,Power.Offered" );
  13145. else
  13146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13147. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13148. // MeterValuesSampledDataMaxLength
  13149. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13150. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13151. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13152. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13153. else
  13154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13155. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13156. // MeterValueSampleInterval
  13157. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13158. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13159. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13160. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13161. // MinimumStatusDuration
  13162. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13164. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13165. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13166. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13167. // NumberOfConnectors
  13168. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13170. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13171. {
  13172. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13173. }
  13174. else
  13175. {
  13176. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13177. }
  13178. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13179. // ResetRetries
  13180. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13181. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13182. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13183. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13184. // ConnectorPhaseRotation
  13185. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13186. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13187. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13188. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13189. // ConnectorPhaseRotationMaxLength
  13190. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13192. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13193. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13194. // StopTransactionOnEVSideDisconnect
  13195. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13197. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13198. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13199. // StopTransactionOnInvalidId
  13200. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13201. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13202. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13203. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13204. // StopTxnAlignedData
  13205. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13206. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13207. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13208. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13209. // StopTxnAlignedDataMaxLength
  13210. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13211. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13212. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13213. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13214. // StopTxnSampledData
  13215. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13216. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13217. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13219. else
  13220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13221. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13222. // StopTxnSampledDataMaxLength
  13223. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13225. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13226. {
  13227. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13228. }
  13229. else
  13230. {
  13231. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13232. }
  13233. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13234. // SupportedFeatureProfiles
  13235. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13236. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13238. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13239. // SupportedFeatureProfilesMaxLength
  13240. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13241. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13243. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13244. // TransactionMessageAttempts
  13245. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13246. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13248. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13249. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13250. // TransactionMessageRetryInterval
  13251. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13254. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13255. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13256. // UnlockConnectorOnEVSideDisconnect
  13257. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13258. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13260. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13261. // WebSocketPingInterval
  13262. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13263. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13264. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13265. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13266. // QueueOffLineMeterValues
  13267. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13270. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13271. // AuthorizationKey
  13272. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13274. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  13275. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13276. // SecurityProfile
  13277. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13279. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  13280. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13281. // DefaultPrice
  13282. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13284. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13285. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13286. // CustomDisplayCostAndPrice
  13287. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13290. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13291. // CustomIdleFeeAfterStop
  13292. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13295. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13296. // TimeOffset
  13297. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13298. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  13299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  13300. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  13301. // NextTimeOffsetTransitionDateTime
  13302. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  13303. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  13304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  13305. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  13306. // TimeOffsetNextTransition
  13307. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  13308. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  13309. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  13310. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  13311. // SystemUptimeSec
  13312. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13313. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13314. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13315. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13316. // FreeVend
  13317. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13318. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "Free-FreeVend");
  13319. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13320. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13321. // Configuration Version
  13322. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13323. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13324. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13325. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13326. //* Local Auth List Management Profile*/
  13327. #if 0
  13328. //For OCTT Test Case
  13329. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13331. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13332. #endif
  13333. #if 1
  13334. //LocalAuthListEnabled
  13335. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13336. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13337. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13338. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13339. #endif
  13340. //LocalAuthListMaxLength
  13341. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  13344. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13345. //SendLocalListMaxLength
  13346. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13347. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13349. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13350. //ReserveConnectorZeroSupported
  13351. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13354. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13355. //* Smart Charging Profile */
  13356. //ChargeProfileMaxStackLevel
  13357. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13359. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13360. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13361. // ChargingScheduleAllowedChargingRateUnit
  13362. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13365. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13366. // ChargingScheduleMaxPeriods
  13367. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13368. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13369. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13370. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13371. // ConnectorSwitch3to1PhaseSupported
  13372. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13373. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13374. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13375. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13376. // MaxChargingProfilesInstalled
  13377. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13380. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13381. fclose(outfile);
  13382. }
  13383. else
  13384. {
  13385. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  13386. char keystr[60]={0};
  13387. char readonlystr[10]={0};
  13388. char valuestr[256]={0};
  13389. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  13390. if(fp == NULL) {
  13391. DEBUG_INFO("Error opening file");
  13392. return FALSE;
  13393. }
  13394. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13395. {
  13396. //DEBUG_INFO("Get Configuration \n");
  13397. if(strlen(str) > 0)
  13398. {
  13399. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13400. //*************************key*********************************/
  13401. if(strstr(str, "key") != NULL)
  13402. {
  13403. loc = strstr(str, "key");
  13404. c = 0;
  13405. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13406. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13407. {
  13408. sstr[c] = loc[strlen("key")+3+c];
  13409. c++;
  13410. }
  13411. sstr[c] = '\0';
  13412. strcpy(keystr,sstr);
  13413. }
  13414. //*************************readonly*********************************/
  13415. if(strstr(str, "readonly") != NULL)
  13416. {
  13417. loc = strstr(str, "readonly");
  13418. c = 0;
  13419. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13420. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13421. {
  13422. sstr[c] = loc[strlen("readonly")+2+c];
  13423. c++;
  13424. }
  13425. sstr[c] = '\0';
  13426. strcpy(readonlystr,sstr);
  13427. }
  13428. //*************************value*********************************/
  13429. if(strstr(str, "value") != NULL)
  13430. {
  13431. loc = strstr(str, "value");
  13432. c = 0;
  13433. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13434. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13435. {
  13436. sstr[c] = loc[strlen("value")+3+c];
  13437. c++;
  13438. }
  13439. sstr[c] = '\0';
  13440. strcpy(valuestr,sstr);
  13441. }
  13442. // DEBUG_INFO("keystr=%s\n",keystr);
  13443. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13444. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13445. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13446. {
  13447. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13448. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13449. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13450. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13451. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13452. }
  13453. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  13454. {
  13455. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13456. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13457. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  13458. }
  13459. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  13460. {
  13461. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13462. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  13463. }
  13464. if(strcmp(keystr, "BlinkRepeat") == 0)
  13465. {
  13466. //Charger.BlinkRepeat = Integer.parseInt(value);
  13467. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13468. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  13469. }
  13470. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  13471. {
  13472. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13473. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  13474. }
  13475. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  13476. {
  13477. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13478. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  13479. }
  13480. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  13481. {
  13482. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13483. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  13484. }
  13485. if(strcmp(keystr, "HeartbeatInterval") == 0)
  13486. {
  13487. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13488. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  13489. HeartBeatWaitTime = atoi(valuestr);
  13490. }
  13491. if(strcmp(keystr, "LightIntensity") == 0)
  13492. {
  13493. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13494. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  13495. }
  13496. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  13497. {
  13498. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13499. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  13500. }
  13501. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  13502. {
  13503. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13504. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  13505. }
  13506. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  13507. {
  13508. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13509. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  13510. }
  13511. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  13512. {
  13513. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13514. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  13515. }
  13516. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  13517. {
  13518. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13519. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  13520. }
  13521. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  13522. {
  13523. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13524. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  13525. }
  13526. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  13527. {
  13528. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13529. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  13530. }
  13531. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  13532. {
  13533. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13534. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  13535. }
  13536. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  13537. {
  13538. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13539. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  13540. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  13541. }
  13542. if(strcmp(keystr, "NumberOfConnectors") == 0)
  13543. {
  13544. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13545. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  13546. }
  13547. if(strcmp(keystr, "ResetRetries") == 0)
  13548. {
  13549. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13550. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  13551. }
  13552. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  13553. {
  13554. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13555. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  13556. }
  13557. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  13558. {
  13559. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13560. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  13561. }
  13562. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  13563. {
  13564. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13565. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  13566. }
  13567. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  13568. {
  13569. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13570. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  13571. }
  13572. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  13573. {
  13574. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13575. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  13576. }
  13577. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  13578. {
  13579. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13580. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13581. }
  13582. if(strcmp(keystr, "StopTxnSampledData") == 0)
  13583. {
  13584. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13585. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  13586. }
  13587. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  13588. {
  13589. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13590. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13591. }
  13592. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  13593. {
  13594. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13595. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  13596. }
  13597. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  13598. {
  13599. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13600. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  13601. }
  13602. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  13603. {
  13604. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13605. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  13606. TransactionMessageAttemptsValue = atoi(valuestr);
  13607. }
  13608. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  13609. {
  13610. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13611. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  13612. TransactionMessageRetryIntervalValue = atoi(valuestr);
  13613. }
  13614. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  13615. {
  13616. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13617. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  13618. }
  13619. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  13620. {
  13621. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13622. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  13623. }
  13624. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  13625. {
  13626. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13627. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  13628. }
  13629. if(strcmp(keystr, "AuthorizationKey") == 0)
  13630. {
  13631. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13632. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  13633. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  13634. }
  13635. if(strcmp(keystr, "SecurityProfile") == 0)
  13636. {
  13637. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13638. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  13639. }
  13640. if(strcmp(keystr, "DefaultPrice") == 0)
  13641. {
  13642. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13643. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  13644. }
  13645. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  13646. {
  13647. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13648. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  13649. }
  13650. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  13651. {
  13652. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13653. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  13654. }
  13655. if(strcmp(keystr, "TimeOffset") == 0)
  13656. {
  13657. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13658. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  13659. }
  13660. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  13661. {
  13662. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13663. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  13664. }
  13665. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  13666. {
  13667. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13668. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  13669. }
  13670. if(strcmp(keystr, "SystemUptimeSec") == 0)
  13671. {
  13672. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13673. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  13674. }
  13675. if(strcmp(keystr, "FreeVend") == 0)
  13676. {
  13677. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13678. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  13679. }
  13680. if(strcmp(keystr, "ConfigurationVersion") == 0)
  13681. {
  13682. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13683. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  13684. }
  13685. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  13686. {
  13687. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13688. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  13689. }
  13690. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  13691. {
  13692. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13693. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  13694. }
  13695. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  13696. {
  13697. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13698. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  13699. }
  13700. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  13701. {
  13702. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13703. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  13704. }
  13705. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  13706. {
  13707. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13708. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  13709. }
  13710. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13711. {
  13712. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13713. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  13714. }
  13715. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  13716. {
  13717. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13718. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  13719. }
  13720. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  13721. {
  13722. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13723. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  13724. }
  13725. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  13726. {
  13727. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13728. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  13729. }
  13730. }
  13731. }
  13732. fclose(fp);
  13733. }
  13734. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  13735. {
  13736. return PASS;
  13737. }
  13738. else
  13739. {
  13740. return FAIL;
  13741. }
  13742. }
  13743. void StoreConfigurationTable(void)
  13744. {
  13745. FILE *outfile;
  13746. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  13747. if(outfile == NULL)
  13748. {
  13749. DEBUG_INFO("Error opening file");
  13750. return ;
  13751. }
  13752. /*Core Profile*/
  13753. //AllowOfflineTxForUnknownId
  13754. /*
  13755. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13756. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  13757. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  13759. */
  13760. //DEBUG_INFO("data=%s\n",data);
  13761. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13762. //AuthorizationCacheEnabled
  13763. /*
  13764. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13767. */
  13768. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13769. //AuthorizeRemoteTxRequests
  13770. /*
  13771. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  13774. */
  13775. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13776. //BlinkRepeat
  13777. /*
  13778. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13781. */
  13782. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13783. //ClockAlignedDataInterval
  13784. /*
  13785. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13788. */
  13789. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13790. //ConnectionTimeOut
  13791. /*
  13792. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13795. */
  13796. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13797. //GetConfigurationMaxKeys
  13798. /*
  13799. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  13802. */
  13803. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13804. // HeartbeatInterval
  13805. /*
  13806. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  13809. */
  13810. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13811. // LightIntensity
  13812. /*
  13813. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13816. */
  13817. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13818. // LocalAuthorizeOffline
  13819. /*
  13820. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  13821. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13823. */
  13824. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13825. // LocalPreAuthorize
  13826. /*
  13827. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  13828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13830. */
  13831. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13832. // MaxEnergyOnInvalidId
  13833. /*
  13834. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13835. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13836. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13837. */
  13838. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  13839. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13840. // MeterValuesAlignedData
  13841. /*
  13842. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13845. */
  13846. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13847. // MeterValuesAlignedDataMaxLength
  13848. /*
  13849. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  13852. */
  13853. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13854. // MeterValuesSampledData
  13855. /*
  13856. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13859. */
  13860. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13861. // MeterValuesSampledDataMaxLength
  13862. /*
  13863. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  13866. */
  13867. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13868. // MeterValueSampleInterval
  13869. /*
  13870. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13871. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  13873. */
  13874. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13875. // MinimumStatusDuration
  13876. /*
  13877. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  13880. */
  13881. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13882. // NumberOfConnectors
  13883. /*
  13884. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13885. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13886. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13887. {
  13888. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13889. }
  13890. else
  13891. {
  13892. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13893. }
  13894. */
  13895. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13896. // ResetRetries
  13897. /*
  13898. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13899. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13901. */
  13902. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13903. // ConnectorPhaseRotation
  13904. /*
  13905. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13906. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13908. */
  13909. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13910. // ConnectorPhaseRotationMaxLength
  13911. /*
  13912. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13913. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13915. */
  13916. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13917. // StopTransactionOnEVSideDisconnect
  13918. /*
  13919. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13920. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13922. */
  13923. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13924. // StopTransactionOnInvalidId
  13925. /*
  13926. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  13927. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13928. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13929. */
  13930. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13931. // StopTxnAlignedData
  13932. /*
  13933. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  13934. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13935. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  13936. */
  13937. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13938. // StopTxnAlignedDataMaxLength
  13939. /*
  13940. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13941. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13942. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13943. */
  13944. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13945. // StopTxnSampledData
  13946. /*
  13947. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13948. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13949. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  13950. */
  13951. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13952. // StopTxnSampledDataMaxLength
  13953. /*
  13954. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13955. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  13957. */
  13958. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13959. // SupportedFeatureProfiles
  13960. /*
  13961. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13962. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13963. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13964. */
  13965. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13966. // SupportedFeatureProfilesMaxLength
  13967. /*
  13968. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13969. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13970. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13971. */
  13972. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13973. // TransactionMessageAttempts
  13974. /*
  13975. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13976. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13978. */
  13979. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13980. // TransactionMessageRetryInterval
  13981. /*
  13982. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13983. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13984. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13985. */
  13986. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13987. // UnlockConnectorOnEVSideDisconnect
  13988. /*
  13989. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13990. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13991. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13992. */
  13993. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13994. // WebSocketPingInterval
  13995. /*
  13996. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13997. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13998. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13999. */
  14000. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14001. // QueueOffLineMeterValues
  14002. /*
  14003. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14004. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14005. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14006. */
  14007. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14008. // AuthorizationKey
  14009. /*
  14010. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14011. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14012. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14013. */
  14014. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14015. // SecurityProfile
  14016. /*
  14017. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14018. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14019. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14020. */
  14021. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14022. // DefaultPrice
  14023. /*
  14024. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14025. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14026. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14027. */
  14028. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14029. // CustomDisplayCostAndPrice
  14030. /*
  14031. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14032. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14033. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14034. */
  14035. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14036. // CustomIdleFeeAfterStop
  14037. /*
  14038. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14039. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14040. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14041. */
  14042. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14043. // TimeOffset
  14044. /*
  14045. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14046. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  14048. */
  14049. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14050. // NextTimeOffsetTransitionDateTime
  14051. /*
  14052. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  14055. */
  14056. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14057. // TimeOffsetNextTransition
  14058. /*
  14059. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14060. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  14062. */
  14063. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14064. // SystemUptimeSec
  14065. /*
  14066. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14067. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14069. */
  14070. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14071. // FreeVend
  14072. /*
  14073. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14076. */
  14077. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14078. // ConfigurationVersion
  14079. /*
  14080. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14081. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14083. */
  14084. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14085. //* Local Auth List Management Profile*/
  14086. //LocalAuthListEnabled
  14087. /*
  14088. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14091. */
  14092. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14093. //LocalAuthListMaxLength
  14094. /*
  14095. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14098. */
  14099. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14100. //SendLocalListMaxLength
  14101. /*
  14102. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14105. */
  14106. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14107. //ReserveConnectorZeroSupported
  14108. /*
  14109. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14112. */
  14113. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14114. //* Smart Charging Profile */
  14115. //ChargeProfileMaxStackLevel
  14116. /*
  14117. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14120. */
  14121. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14122. // ChargingScheduleAllowedChargingRateUnit
  14123. /*
  14124. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14127. */
  14128. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14129. // ChargingScheduleMaxPeriods
  14130. /*
  14131. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14134. */
  14135. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14136. // ConnectorSwitch3to1PhaseSupported
  14137. /*
  14138. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14141. */
  14142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14143. // MaxChargingProfilesInstalled
  14144. /*
  14145. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14148. */
  14149. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14150. fclose(outfile);
  14151. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14152. }
  14153. void getKeyValue(char *keyReq)
  14154. {
  14155. int isEmpty = FALSE;
  14156. int isKnowKey = FALSE;
  14157. DEBUG_INFO("keyReq = %s\n", keyReq);
  14158. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14159. isEmpty = TRUE;
  14160. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14161. {
  14162. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14163. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14164. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14165. {
  14166. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14167. }
  14168. else
  14169. {
  14170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14171. }
  14172. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14173. isKnowKey = TRUE;
  14174. }
  14175. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14176. {
  14177. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14178. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14179. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14180. {
  14181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14182. }
  14183. else
  14184. {
  14185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14186. }
  14187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14188. isKnowKey = TRUE;
  14189. }
  14190. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14191. {
  14192. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14193. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14194. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14195. {
  14196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14197. }
  14198. else
  14199. {
  14200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14201. }
  14202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14203. isKnowKey = TRUE;
  14204. }
  14205. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14206. {
  14207. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14208. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14209. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14210. {
  14211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14212. }
  14213. else
  14214. {
  14215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14216. }
  14217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14218. isKnowKey = TRUE;
  14219. }
  14220. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14221. {
  14222. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14223. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14224. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14225. {
  14226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14227. }
  14228. else
  14229. {
  14230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14231. }
  14232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14233. isKnowKey = TRUE;
  14234. }
  14235. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14236. {
  14237. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14239. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14240. {
  14241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14242. }
  14243. else
  14244. {
  14245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14246. }
  14247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14248. isKnowKey = TRUE;
  14249. }
  14250. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14251. {
  14252. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14254. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14255. {
  14256. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14257. }
  14258. else
  14259. {
  14260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14261. }
  14262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14263. isKnowKey = TRUE;
  14264. }
  14265. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14266. {
  14267. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14269. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14270. {
  14271. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14272. }
  14273. else
  14274. {
  14275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14276. }
  14277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14278. isKnowKey = TRUE;
  14279. }
  14280. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14281. {
  14282. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14284. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14285. {
  14286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14287. }
  14288. else
  14289. {
  14290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14291. }
  14292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14293. isKnowKey = TRUE;
  14294. }
  14295. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14296. {
  14297. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14299. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14300. {
  14301. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14302. }
  14303. else
  14304. {
  14305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14306. }
  14307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14308. isKnowKey = TRUE;
  14309. }
  14310. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14311. {
  14312. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14314. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14315. {
  14316. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14317. }
  14318. else
  14319. {
  14320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14321. }
  14322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14323. isKnowKey = TRUE;
  14324. }
  14325. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14326. {
  14327. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14329. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14330. {
  14331. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14332. }
  14333. else
  14334. {
  14335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14336. }
  14337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14338. isKnowKey = TRUE;
  14339. }
  14340. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14341. {
  14342. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14344. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14345. {
  14346. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14347. }
  14348. else
  14349. {
  14350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14351. }
  14352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14353. isKnowKey = TRUE;
  14354. }
  14355. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14356. {
  14357. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14359. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14360. {
  14361. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14362. }
  14363. else
  14364. {
  14365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14366. }
  14367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14368. isKnowKey = TRUE;
  14369. }
  14370. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14371. {
  14372. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14374. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14375. {
  14376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14377. }
  14378. else
  14379. {
  14380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14381. }
  14382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14383. isKnowKey = TRUE;
  14384. }
  14385. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14386. {
  14387. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14389. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14390. {
  14391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14392. }
  14393. else
  14394. {
  14395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14396. }
  14397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  14398. isKnowKey = TRUE;
  14399. }
  14400. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  14401. {
  14402. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  14403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  14404. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14405. {
  14406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  14407. }
  14408. else
  14409. {
  14410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  14411. }
  14412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  14413. isKnowKey = TRUE;
  14414. }
  14415. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  14416. {
  14417. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  14418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  14419. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14420. {
  14421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  14422. }
  14423. else
  14424. {
  14425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  14426. }
  14427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  14428. isKnowKey = TRUE;
  14429. }
  14430. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  14431. {
  14432. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  14433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  14434. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14435. {
  14436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  14437. }
  14438. else
  14439. {
  14440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  14441. }
  14442. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  14443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  14444. isKnowKey = TRUE;
  14445. }
  14446. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  14447. {
  14448. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  14449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  14450. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14451. {
  14452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  14453. }
  14454. else
  14455. {
  14456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  14457. }
  14458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  14459. isKnowKey = TRUE;
  14460. }
  14461. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  14462. {
  14463. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  14464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  14465. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14466. {
  14467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  14468. }
  14469. else
  14470. {
  14471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  14472. }
  14473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  14474. isKnowKey = TRUE;
  14475. }
  14476. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  14477. {
  14478. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  14479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  14480. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14481. {
  14482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14483. }
  14484. else
  14485. {
  14486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14487. }
  14488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  14489. isKnowKey = TRUE;
  14490. }
  14491. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  14492. {
  14493. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  14494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  14495. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14496. {
  14497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14498. }
  14499. else
  14500. {
  14501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14502. }
  14503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  14504. isKnowKey = TRUE;
  14505. }
  14506. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  14507. {
  14508. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  14509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  14510. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14511. {
  14512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14513. }
  14514. else
  14515. {
  14516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14517. }
  14518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  14519. isKnowKey = TRUE;
  14520. }
  14521. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  14522. {
  14523. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  14524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  14525. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14526. {
  14527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14528. }
  14529. else
  14530. {
  14531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14532. }
  14533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  14534. isKnowKey = TRUE;
  14535. }
  14536. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  14537. {
  14538. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  14539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  14540. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14541. {
  14542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14543. }
  14544. else
  14545. {
  14546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14547. }
  14548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  14549. isKnowKey = TRUE;
  14550. }
  14551. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  14552. {
  14553. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  14554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  14555. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14556. {
  14557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  14558. }
  14559. else
  14560. {
  14561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  14562. }
  14563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  14564. isKnowKey = TRUE;
  14565. }
  14566. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  14567. {
  14568. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  14569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  14570. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14571. {
  14572. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14573. }
  14574. else
  14575. {
  14576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14577. }
  14578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  14579. isKnowKey = TRUE;
  14580. }
  14581. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  14582. {
  14583. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  14584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  14585. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14586. {
  14587. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  14588. }
  14589. else
  14590. {
  14591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  14592. }
  14593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  14594. isKnowKey = TRUE;
  14595. }
  14596. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  14597. {
  14598. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  14599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  14600. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14601. {
  14602. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14603. }
  14604. else
  14605. {
  14606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14607. }
  14608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  14609. isKnowKey = TRUE;
  14610. }
  14611. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  14612. {
  14613. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  14614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  14615. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14616. {
  14617. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  14618. }
  14619. else
  14620. {
  14621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  14622. }
  14623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  14624. isKnowKey = TRUE;
  14625. }
  14626. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  14627. {
  14628. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  14629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  14630. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14631. {
  14632. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  14633. }
  14634. else
  14635. {
  14636. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  14637. }
  14638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  14639. isKnowKey = TRUE;
  14640. }
  14641. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  14642. {
  14643. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  14644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  14645. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14646. {
  14647. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14648. }
  14649. else
  14650. {
  14651. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14652. }
  14653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  14654. isKnowKey = TRUE;
  14655. }
  14656. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  14657. {
  14658. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  14659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  14660. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14661. {
  14662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  14663. }
  14664. else
  14665. {
  14666. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  14667. }
  14668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  14669. isKnowKey = TRUE;
  14670. }
  14671. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  14672. {
  14673. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  14674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  14675. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14676. {
  14677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  14678. }
  14679. else
  14680. {
  14681. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  14682. }
  14683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  14684. isKnowKey = TRUE;
  14685. }
  14686. /*
  14687. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  14688. {
  14689. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  14690. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  14691. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  14692. {
  14693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  14694. }
  14695. else
  14696. {
  14697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  14698. }
  14699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  14700. isKnowKey = TRUE;
  14701. }*/
  14702. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  14703. {
  14704. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  14705. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  14706. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14707. {
  14708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  14709. }
  14710. else
  14711. {
  14712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  14713. }
  14714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  14715. isKnowKey = TRUE;
  14716. }
  14717. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  14718. {
  14719. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  14720. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  14721. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  14722. {
  14723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  14724. }
  14725. else
  14726. {
  14727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  14728. }
  14729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  14730. isKnowKey = TRUE;
  14731. }
  14732. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  14733. {
  14734. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  14735. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  14736. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14737. {
  14738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  14739. }
  14740. else
  14741. {
  14742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  14743. }
  14744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  14745. isKnowKey = TRUE;
  14746. }
  14747. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  14748. {
  14749. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  14750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  14751. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14752. {
  14753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  14754. }
  14755. else
  14756. {
  14757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  14758. }
  14759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  14760. isKnowKey = TRUE;
  14761. }
  14762. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  14763. {
  14764. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  14765. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  14766. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  14767. {
  14768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  14769. }
  14770. else
  14771. {
  14772. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  14773. }
  14774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  14775. isKnowKey = TRUE;
  14776. }
  14777. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  14778. {
  14779. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  14780. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  14781. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  14782. {
  14783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  14784. }
  14785. else
  14786. {
  14787. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  14788. }
  14789. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  14790. isKnowKey = TRUE;
  14791. }
  14792. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  14793. {
  14794. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  14795. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  14796. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  14797. {
  14798. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  14799. }
  14800. else
  14801. {
  14802. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  14803. }
  14804. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  14805. isKnowKey = TRUE;
  14806. }
  14807. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  14808. {
  14809. struct sysinfo s_info;
  14810. int error = sysinfo(&s_info);
  14811. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  14812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  14813. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  14814. {
  14815. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  14816. }
  14817. else
  14818. {
  14819. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  14820. }
  14821. if(error != 0)
  14822. {
  14823. DEBUG_WARN("System uptime get error: %d\n", error);
  14824. }
  14825. else
  14826. {
  14827. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  14828. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  14829. }
  14830. isKnowKey = TRUE;
  14831. }
  14832. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  14833. {
  14834. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  14835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  14836. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  14837. {
  14838. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  14839. }
  14840. else
  14841. {
  14842. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  14843. }
  14844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  14845. isKnowKey = TRUE;
  14846. }
  14847. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  14848. {
  14849. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  14850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  14851. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  14852. {
  14853. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  14854. }
  14855. else
  14856. {
  14857. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  14858. }
  14859. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  14860. isKnowKey = TRUE;
  14861. }
  14862. #if 1
  14863. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  14864. {
  14865. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  14866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  14867. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14868. {
  14869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  14870. }
  14871. else
  14872. {
  14873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  14874. }
  14875. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  14876. isKnowKey = TRUE;
  14877. }
  14878. #endif
  14879. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  14880. {
  14881. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  14882. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  14883. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14884. {
  14885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14886. }
  14887. else
  14888. {
  14889. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14890. }
  14891. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  14892. isKnowKey = TRUE;
  14893. }
  14894. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  14895. {
  14896. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  14897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  14898. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14899. {
  14900. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14901. }
  14902. else
  14903. {
  14904. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14905. }
  14906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  14907. isKnowKey = TRUE;
  14908. }
  14909. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  14910. {
  14911. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  14912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  14913. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14914. {
  14915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  14916. }
  14917. else
  14918. {
  14919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  14920. }
  14921. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14922. isKnowKey = TRUE;
  14923. }
  14924. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  14925. {
  14926. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  14927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  14928. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14929. {
  14930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  14931. }
  14932. else
  14933. {
  14934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  14935. }
  14936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14937. isKnowKey = TRUE;
  14938. }
  14939. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  14940. {
  14941. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  14942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  14943. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14944. {
  14945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  14946. }
  14947. else
  14948. {
  14949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  14950. }
  14951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14952. isKnowKey = TRUE;
  14953. }
  14954. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  14955. {
  14956. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  14957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  14958. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14959. {
  14960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  14961. }
  14962. else
  14963. {
  14964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  14965. }
  14966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14967. isKnowKey = TRUE;
  14968. }
  14969. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  14970. {
  14971. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  14972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  14973. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14974. {
  14975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  14976. }
  14977. else
  14978. {
  14979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  14980. }
  14981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14982. isKnowKey = TRUE;
  14983. }
  14984. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  14985. {
  14986. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  14987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  14988. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14989. {
  14990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  14991. }
  14992. else
  14993. {
  14994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  14995. }
  14996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14997. isKnowKey = TRUE;
  14998. }
  14999. //=========================================================
  15000. if(!isEmpty && !isKnowKey)
  15001. {
  15002. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15003. strcpy(unknownkey[UnknownKeynum], keyReq);
  15004. UnknownKeynum = UnknownKeynum + 1;
  15005. }
  15006. }
  15007. void processUnkownKey(void)
  15008. {
  15009. DEBUG_INFO("processUnkownKey...\n");
  15010. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15011. for(int index=0; index < UnknownKeynum; index++)
  15012. {
  15013. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15014. {
  15015. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15016. }
  15017. }
  15018. }
  15019. int setKeyValue(char *key, char *value)
  15020. {
  15021. int isSuccess = NotSupported;
  15022. int check_ascii=0;
  15023. char str[256]={0};
  15024. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15025. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15026. {
  15027. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15028. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15029. {
  15030. strcpy(str, (const char*)value);
  15031. for(int i = 0; str[i]; i++){
  15032. str[i] = tolower(str[i]);
  15033. }
  15034. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15035. isSuccess = ConfigurationStatus_Accepted;
  15036. }
  15037. else
  15038. {
  15039. isSuccess = ConfigurationStatus_Rejected;
  15040. }
  15041. }
  15042. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15043. {
  15044. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15045. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15046. {
  15047. strcpy(str, (const char*)value);
  15048. for(int i = 0; str[i]; i++){
  15049. str[i] = tolower(str[i]);
  15050. }
  15051. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15052. isSuccess = ConfigurationStatus_Accepted;
  15053. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  15054. }
  15055. else
  15056. {
  15057. isSuccess = ConfigurationStatus_Rejected;
  15058. }
  15059. }
  15060. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15061. {
  15062. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15063. {
  15064. strcpy(str, (const char*)value);
  15065. for(int i = 0; str[i]; i++)
  15066. {
  15067. str[i] = tolower(str[i]);
  15068. }
  15069. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15070. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15071. isSuccess = ConfigurationStatus_Accepted;
  15072. }
  15073. else
  15074. {
  15075. isSuccess = ConfigurationStatus_Rejected;
  15076. }
  15077. }
  15078. if(strcmp(key, "BlinkRepeat") == 0)
  15079. {
  15080. //Charger.BlinkRepeat = Integer.parseInt(value);
  15081. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15082. {
  15083. check_ascii = value[0];
  15084. if( (check_ascii < 48) || (check_ascii > 57) )
  15085. {
  15086. isSuccess = ConfigurationStatus_Rejected;
  15087. }
  15088. else
  15089. {
  15090. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15091. isSuccess = ConfigurationStatus_Accepted;
  15092. }
  15093. }
  15094. else
  15095. {
  15096. isSuccess = ConfigurationStatus_Rejected;
  15097. }
  15098. }
  15099. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15100. {
  15101. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15102. {
  15103. check_ascii = value[0];
  15104. if( (check_ascii < 48) || (check_ascii > 57) )
  15105. {
  15106. isSuccess = ConfigurationStatus_Rejected;
  15107. }
  15108. else
  15109. {
  15110. if((atoi(value) == 0) || (atoi(value) >= 5))
  15111. {
  15112. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15113. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15114. isSuccess = ConfigurationStatus_Accepted;
  15115. }
  15116. else
  15117. isSuccess = ConfigurationStatus_Rejected;
  15118. }
  15119. }
  15120. else
  15121. {
  15122. isSuccess = ConfigurationStatus_Rejected;
  15123. }
  15124. }
  15125. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15126. {
  15127. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15128. {
  15129. check_ascii = value[0];
  15130. if( (check_ascii < 48) || (check_ascii > 57) )
  15131. {
  15132. isSuccess = ConfigurationStatus_Rejected;
  15133. }
  15134. else
  15135. {
  15136. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15137. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15138. isSuccess = ConfigurationStatus_Accepted;
  15139. }
  15140. }
  15141. else
  15142. {
  15143. isSuccess = ConfigurationStatus_Rejected;
  15144. }
  15145. }
  15146. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15147. {
  15148. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15149. {
  15150. check_ascii = value[0];
  15151. if( (check_ascii < 48) || (check_ascii > 57) )
  15152. {
  15153. isSuccess = ConfigurationStatus_Rejected;
  15154. }
  15155. else
  15156. {
  15157. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15158. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15159. isSuccess = ConfigurationStatus_Accepted;
  15160. }
  15161. }
  15162. else
  15163. {
  15164. isSuccess = ConfigurationStatus_Rejected;
  15165. }
  15166. }
  15167. if(strcmp(key, "HeartbeatInterval") == 0)
  15168. {
  15169. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15170. {
  15171. check_ascii = value[0];
  15172. if( (check_ascii < 48) || (check_ascii > 57) )
  15173. {
  15174. isSuccess = ConfigurationStatus_Rejected;
  15175. }
  15176. else
  15177. {
  15178. if((atoi(value) == 0) || (atoi(value) >= 10))
  15179. {
  15180. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15181. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15182. HeartBeatWaitTime = atoi(value);
  15183. isSuccess = ConfigurationStatus_Accepted;
  15184. }
  15185. else
  15186. {
  15187. isSuccess = ConfigurationStatus_Rejected;
  15188. }
  15189. }
  15190. }
  15191. else
  15192. {
  15193. isSuccess = ConfigurationStatus_Rejected;
  15194. }
  15195. }
  15196. if(strcmp(key, "LightIntensity") == 0)
  15197. {
  15198. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15199. {
  15200. check_ascii = value[0];
  15201. if( (check_ascii < 48) || (check_ascii > 57) )
  15202. {
  15203. isSuccess = ConfigurationStatus_Rejected;
  15204. }
  15205. else
  15206. {
  15207. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15208. isSuccess = ConfigurationStatus_Accepted;
  15209. }
  15210. }
  15211. else
  15212. {
  15213. isSuccess = ConfigurationStatus_Rejected;
  15214. }
  15215. }
  15216. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15217. {
  15218. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15219. {
  15220. strcpy(str, (const char*)value);
  15221. for(int i = 0; str[i]; i++)
  15222. {
  15223. str[i] = tolower(str[i]);
  15224. }
  15225. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15226. isSuccess = ConfigurationStatus_Accepted;
  15227. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15228. }
  15229. else
  15230. {
  15231. isSuccess = ConfigurationStatus_Rejected;
  15232. }
  15233. }
  15234. if(strcmp(key, "LocalPreAuthorize") == 0)
  15235. {
  15236. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15237. {
  15238. strcpy(str, (const char*)value);
  15239. for(int i = 0; str[i]; i++)
  15240. {
  15241. str[i] = tolower(str[i]);
  15242. }
  15243. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15244. isSuccess = ConfigurationStatus_Accepted;
  15245. }
  15246. else
  15247. {
  15248. isSuccess = ConfigurationStatus_Rejected;
  15249. }
  15250. }
  15251. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15252. {
  15253. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15254. {
  15255. check_ascii = value[0];
  15256. if( (check_ascii < 48) || (check_ascii > 57) )
  15257. {
  15258. isSuccess = ConfigurationStatus_Rejected;
  15259. }
  15260. else
  15261. {
  15262. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15263. isSuccess = ConfigurationStatus_Accepted;
  15264. }
  15265. }
  15266. else
  15267. {
  15268. isSuccess = ConfigurationStatus_Rejected;
  15269. }
  15270. }
  15271. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15272. {
  15273. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15274. {
  15275. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15276. isSuccess = ConfigurationStatus_Accepted;
  15277. }
  15278. else
  15279. {
  15280. isSuccess = ConfigurationStatus_Rejected;
  15281. }
  15282. }
  15283. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15284. {
  15285. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15286. {
  15287. check_ascii = value[0];
  15288. if( (check_ascii < 48) || (check_ascii > 57) )
  15289. {
  15290. isSuccess = ConfigurationStatus_Rejected;
  15291. }
  15292. else
  15293. {
  15294. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15295. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15296. isSuccess = ConfigurationStatus_Accepted;
  15297. }
  15298. }
  15299. else
  15300. {
  15301. isSuccess = ConfigurationStatus_Rejected;
  15302. }
  15303. }
  15304. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15305. {
  15306. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15307. {
  15308. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15309. isSuccess = ConfigurationStatus_Accepted;
  15310. }
  15311. else
  15312. {
  15313. isSuccess = ConfigurationStatus_Rejected;
  15314. }
  15315. }
  15316. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  15317. {
  15318. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15319. {
  15320. check_ascii = value[0];
  15321. if( (check_ascii < 48) || (check_ascii > 57) )
  15322. {
  15323. isSuccess = ConfigurationStatus_Rejected;
  15324. }
  15325. else
  15326. {
  15327. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15328. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  15329. isSuccess = ConfigurationStatus_Accepted;
  15330. }
  15331. }
  15332. else
  15333. {
  15334. isSuccess = ConfigurationStatus_Rejected;
  15335. }
  15336. }
  15337. if(strcmp(key, "MeterValueSampleInterval") == 0)
  15338. {
  15339. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15340. {
  15341. check_ascii = value[0];
  15342. if( (check_ascii < 48) || (check_ascii > 57) )
  15343. {
  15344. isSuccess = ConfigurationStatus_Rejected;
  15345. }
  15346. else
  15347. {
  15348. if((atoi(value) == 0) || (atoi(value) >= 5))
  15349. {
  15350. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15351. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  15352. isSuccess = ConfigurationStatus_Accepted;
  15353. }
  15354. else
  15355. {
  15356. isSuccess = ConfigurationStatus_Rejected;
  15357. }
  15358. }
  15359. }
  15360. else
  15361. {
  15362. isSuccess = ConfigurationStatus_Rejected;
  15363. }
  15364. }
  15365. if(strcmp(key, "MinimumStatusDuration") == 0)
  15366. {
  15367. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15368. {
  15369. check_ascii = value[0];
  15370. if( (check_ascii < 48) || (check_ascii > 57) )
  15371. {
  15372. isSuccess = ConfigurationStatus_Rejected;
  15373. }
  15374. else
  15375. {
  15376. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  15377. {
  15378. isSuccess = ConfigurationStatus_Rejected;
  15379. }
  15380. else
  15381. {
  15382. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  15383. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  15384. server_cycle_Status = atoi(value); //StatusNotification Cycle
  15385. isSuccess = ConfigurationStatus_Accepted;
  15386. }
  15387. }
  15388. }
  15389. else
  15390. {
  15391. isSuccess = ConfigurationStatus_Rejected;
  15392. }
  15393. }
  15394. if(strcmp(key, "NumberOfConnectors") == 0)
  15395. {
  15396. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15397. {
  15398. check_ascii = value[0];
  15399. if( (check_ascii < 48) || (check_ascii > 57) )
  15400. {
  15401. isSuccess = ConfigurationStatus_Rejected;
  15402. }
  15403. else
  15404. {
  15405. //Charger.ResetRetries = Integer.parseInt(value);
  15406. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  15407. isSuccess = ConfigurationStatus_Accepted;
  15408. }
  15409. }
  15410. else
  15411. {
  15412. isSuccess = ConfigurationStatus_Rejected;
  15413. }
  15414. }
  15415. if(strcmp(key, "ResetRetries") == 0)
  15416. {
  15417. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15418. {
  15419. check_ascii = value[0];
  15420. if( (check_ascii < 48) || (check_ascii > 57) )
  15421. {
  15422. isSuccess = ConfigurationStatus_Rejected;
  15423. }
  15424. else
  15425. {
  15426. //Charger.ResetRetries = Integer.parseInt(value);
  15427. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  15428. isSuccess = ConfigurationStatus_Accepted;
  15429. }
  15430. }
  15431. else
  15432. {
  15433. isSuccess = ConfigurationStatus_Rejected;
  15434. }
  15435. }
  15436. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  15437. {
  15438. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15439. {
  15440. strcpy(str, (const char*)value);
  15441. for(int i = 0; str[i]; i++)
  15442. {
  15443. str[i] = tolower(str[i]);
  15444. }
  15445. if(strcmp(str, "notapplicable")== 0)
  15446. {
  15447. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  15448. isSuccess = ConfigurationStatus_Accepted;
  15449. }
  15450. else if(strcmp(str, "unknown")== 0)
  15451. {
  15452. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  15453. isSuccess = ConfigurationStatus_Accepted;
  15454. }
  15455. else if(strcmp(str, "rst")== 0)
  15456. {
  15457. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  15458. isSuccess = ConfigurationStatus_Accepted;
  15459. }
  15460. else if(strcmp(str, "rts")== 0)
  15461. {
  15462. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  15463. isSuccess = ConfigurationStatus_Accepted;
  15464. }
  15465. else if(strcmp(str, "srt")== 0)
  15466. {
  15467. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  15468. isSuccess = ConfigurationStatus_Accepted;
  15469. }
  15470. else if(strcmp(str, "str")== 0)
  15471. {
  15472. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  15473. isSuccess = ConfigurationStatus_Accepted;
  15474. }
  15475. else if(strcmp(str, "trs")== 0)
  15476. {
  15477. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  15478. isSuccess = ConfigurationStatus_Accepted;
  15479. }
  15480. else if(strcmp(str, "tsr")== 0)
  15481. {
  15482. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  15483. isSuccess = ConfigurationStatus_Accepted;
  15484. }
  15485. else
  15486. {
  15487. isSuccess = ConfigurationStatus_Rejected;
  15488. }
  15489. }
  15490. else
  15491. {
  15492. isSuccess = ConfigurationStatus_Rejected;
  15493. }
  15494. }
  15495. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  15496. {
  15497. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15498. {
  15499. check_ascii = value[0];
  15500. if( (check_ascii < 48) || (check_ascii > 57) )
  15501. {
  15502. isSuccess = ConfigurationStatus_Rejected;
  15503. }
  15504. else
  15505. {
  15506. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  15507. isSuccess = ConfigurationStatus_Accepted;
  15508. }
  15509. }
  15510. else
  15511. {
  15512. isSuccess = ConfigurationStatus_Rejected;
  15513. }
  15514. }
  15515. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  15516. {
  15517. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15518. {
  15519. strcpy(str, (const char*)value);
  15520. for(int i = 0; str[i]; i++)
  15521. {
  15522. str[i] = tolower(str[i]);
  15523. }
  15524. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15525. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15526. isSuccess = ConfigurationStatus_Accepted;
  15527. }
  15528. else
  15529. {
  15530. isSuccess = ConfigurationStatus_Rejected;
  15531. }
  15532. }
  15533. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  15534. {
  15535. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15536. {
  15537. strcpy(str, (const char*)value);
  15538. for(int i = 0; str[i]; i++)
  15539. {
  15540. str[i] = tolower(str[i]);
  15541. }
  15542. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  15543. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15544. isSuccess = ConfigurationStatus_Accepted;
  15545. }
  15546. else
  15547. {
  15548. isSuccess = ConfigurationStatus_Rejected;
  15549. }
  15550. }
  15551. if(strcmp(key, "StopTxnAlignedData") == 0)
  15552. {
  15553. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15554. {
  15555. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  15556. isSuccess = ConfigurationStatus_Accepted;
  15557. }
  15558. else
  15559. {
  15560. isSuccess = ConfigurationStatus_Rejected;
  15561. }
  15562. }
  15563. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  15564. {
  15565. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15566. {
  15567. check_ascii = value[0];
  15568. if( (check_ascii < 48) || (check_ascii > 57) )
  15569. {
  15570. isSuccess = ConfigurationStatus_Rejected;
  15571. }
  15572. else
  15573. {
  15574. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  15575. isSuccess = ConfigurationStatus_Accepted;
  15576. }
  15577. }
  15578. else
  15579. {
  15580. isSuccess = ConfigurationStatus_Rejected;
  15581. }
  15582. }
  15583. if(strcmp(key, "StopTxnSampledData") == 0)
  15584. {
  15585. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15586. {
  15587. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  15588. isSuccess = ConfigurationStatus_Accepted;
  15589. }
  15590. else
  15591. {
  15592. isSuccess = ConfigurationStatus_Rejected;
  15593. }
  15594. }
  15595. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  15596. {
  15597. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15598. {
  15599. check_ascii = value[0];
  15600. if( (check_ascii < 48) || (check_ascii > 57) )
  15601. {
  15602. isSuccess = ConfigurationStatus_Rejected;
  15603. }
  15604. else
  15605. {
  15606. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  15607. isSuccess = ConfigurationStatus_Accepted;
  15608. }
  15609. }
  15610. else
  15611. {
  15612. isSuccess = ConfigurationStatus_Rejected;
  15613. }
  15614. }
  15615. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  15616. {
  15617. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15618. {
  15619. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  15620. isSuccess = ConfigurationStatus_Accepted;
  15621. }
  15622. else
  15623. {
  15624. isSuccess = ConfigurationStatus_Rejected;
  15625. }
  15626. }
  15627. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  15628. {
  15629. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15630. {
  15631. check_ascii = value[0];
  15632. if( (check_ascii < 48) || (check_ascii > 57) )
  15633. {
  15634. isSuccess = ConfigurationStatus_Rejected;
  15635. }
  15636. else
  15637. {
  15638. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  15639. isSuccess = ConfigurationStatus_Accepted;
  15640. }
  15641. }
  15642. else
  15643. {
  15644. isSuccess = ConfigurationStatus_Rejected;
  15645. }
  15646. }
  15647. if(strcmp(key, "TransactionMessageAttempts") == 0)
  15648. {
  15649. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15650. {
  15651. check_ascii = value[0];
  15652. if( (check_ascii < 48) || (check_ascii > 57) )
  15653. {
  15654. isSuccess = ConfigurationStatus_Rejected;
  15655. }
  15656. else
  15657. {
  15658. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  15659. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  15660. TransactionMessageAttemptsValue = atoi(value);
  15661. isSuccess = ConfigurationStatus_Accepted;
  15662. }
  15663. }
  15664. else
  15665. {
  15666. isSuccess = ConfigurationStatus_Rejected;
  15667. }
  15668. }
  15669. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  15670. {
  15671. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15672. {
  15673. check_ascii = value[0];
  15674. if( (check_ascii < 48) || (check_ascii > 57) )
  15675. {
  15676. isSuccess = ConfigurationStatus_Rejected;
  15677. }
  15678. else
  15679. {
  15680. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  15681. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  15682. TransactionMessageRetryIntervalValue = atoi(value);
  15683. isSuccess = ConfigurationStatus_Accepted;
  15684. }
  15685. }
  15686. else
  15687. {
  15688. isSuccess = ConfigurationStatus_Rejected;
  15689. }
  15690. }
  15691. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  15692. {
  15693. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15694. {
  15695. strcpy(str, (const char*)value);
  15696. for(int i = 0; str[i]; i++)
  15697. {
  15698. str[i] = tolower(str[i]);
  15699. }
  15700. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15701. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15702. isSuccess = ConfigurationStatus_Accepted;
  15703. }
  15704. else
  15705. {
  15706. isSuccess = ConfigurationStatus_Rejected;
  15707. }
  15708. }
  15709. if(strcmp(key, "WebSocketPingInterval") == 0)
  15710. {
  15711. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15712. {
  15713. check_ascii = value[0];
  15714. if( (check_ascii < 48) || (check_ascii > 57) )
  15715. {
  15716. isSuccess = ConfigurationStatus_Rejected;
  15717. }
  15718. else
  15719. {
  15720. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15721. isSuccess = ConfigurationStatus_Accepted;
  15722. }
  15723. }
  15724. else
  15725. {
  15726. isSuccess = ConfigurationStatus_Rejected;
  15727. }
  15728. }
  15729. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  15730. {
  15731. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15732. {
  15733. strcpy(str, (const char*)value);
  15734. for(int i = 0; str[i]; i++)
  15735. {
  15736. str[i] = tolower(str[i]);
  15737. }
  15738. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15739. isSuccess = ConfigurationStatus_Accepted;
  15740. }
  15741. else
  15742. {
  15743. isSuccess = ConfigurationStatus_Rejected;
  15744. }
  15745. }
  15746. if(strcmp(key, "AuthorizationKey") == 0)
  15747. {
  15748. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  15749. {
  15750. strcpy(str, (const char*)value);
  15751. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  15752. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15753. isSuccess = ConfigurationStatus_Accepted;
  15754. }
  15755. else
  15756. {
  15757. isSuccess = ConfigurationStatus_Rejected;
  15758. }
  15759. }
  15760. if(strcmp(key, "SecurityProfile") == 0)
  15761. {
  15762. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15763. {
  15764. check_ascii = value[0];
  15765. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  15766. {
  15767. isSuccess = ConfigurationStatus_Rejected;
  15768. }
  15769. else if(check_ascii == 0x33)
  15770. {
  15771. isSuccess = NotSupported;
  15772. }
  15773. else
  15774. {
  15775. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  15776. {
  15777. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  15778. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  15779. isSuccess = ConfigurationStatus_Accepted;
  15780. }
  15781. else
  15782. isSuccess = ConfigurationStatus_Rejected;
  15783. }
  15784. }
  15785. else
  15786. {
  15787. isSuccess = ConfigurationStatus_Rejected;
  15788. }
  15789. }
  15790. if(strcmp(key, "DefaultPrice") == 0)
  15791. {
  15792. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  15793. {
  15794. strcpy(str, (const char*)value);
  15795. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  15796. isSuccess = ConfigurationStatus_Accepted;
  15797. }
  15798. else
  15799. {
  15800. isSuccess = ConfigurationStatus_Rejected;
  15801. }
  15802. }
  15803. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  15804. {
  15805. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15806. {
  15807. strcpy(str, (const char*)value);
  15808. for(int i = 0; str[i]; i++)
  15809. {
  15810. str[i] = tolower(str[i]);
  15811. }
  15812. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15813. isSuccess = ConfigurationStatus_Accepted;
  15814. }
  15815. else
  15816. {
  15817. isSuccess = ConfigurationStatus_Rejected;
  15818. }
  15819. }
  15820. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  15821. {
  15822. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15823. {
  15824. strcpy(str, (const char*)value);
  15825. for(int i = 0; str[i]; i++)
  15826. {
  15827. str[i] = tolower(str[i]);
  15828. }
  15829. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15830. isSuccess = ConfigurationStatus_Accepted;
  15831. }
  15832. else
  15833. {
  15834. isSuccess = ConfigurationStatus_Rejected;
  15835. }
  15836. }
  15837. if(strcmp(key, "TimeOffset") == 0)
  15838. {
  15839. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15840. {
  15841. strcpy(str, (const char*)value);
  15842. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  15843. isSuccess = ConfigurationStatus_Accepted;
  15844. }
  15845. else
  15846. {
  15847. isSuccess = ConfigurationStatus_Rejected;
  15848. }
  15849. }
  15850. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  15851. {
  15852. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15853. {
  15854. strcpy(str, (const char*)value);
  15855. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  15856. isSuccess = ConfigurationStatus_Accepted;
  15857. }
  15858. else
  15859. {
  15860. isSuccess = ConfigurationStatus_Rejected;
  15861. }
  15862. }
  15863. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  15864. {
  15865. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15866. {
  15867. strcpy(str, (const char*)value);
  15868. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  15869. isSuccess = ConfigurationStatus_Accepted;
  15870. }
  15871. else
  15872. {
  15873. isSuccess = ConfigurationStatus_Rejected;
  15874. }
  15875. }
  15876. if(strcmp(key, "SystemUptimeSec") == 0)
  15877. {
  15878. isSuccess = NotSupported;
  15879. }
  15880. if(strcmp(key, "FreeVend") == 0)
  15881. {
  15882. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15883. {
  15884. strcpy(str, (const char*)value);
  15885. for(int i = 0; str[i]; i++)
  15886. {
  15887. str[i] = tolower(str[i]);
  15888. }
  15889. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  15890. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15891. isSuccess = ConfigurationStatus_Accepted;
  15892. }
  15893. else
  15894. {
  15895. isSuccess = ConfigurationStatus_Rejected;
  15896. }
  15897. }
  15898. #if 0
  15899. //For OCPP Test Case
  15900. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  15901. {
  15902. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15903. {
  15904. strcpy(str, (const char*)value);
  15905. for(int i = 0; str[i]; i++)
  15906. {
  15907. str[i] = tolower(str[i]);
  15908. }
  15909. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15910. isSuccess = ConfigurationStatus_Accepted;
  15911. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15912. }
  15913. else
  15914. {
  15915. isSuccess = ConfigurationStatus_Rejected;
  15916. }
  15917. }
  15918. #endif
  15919. #if 1
  15920. if(strcmp(key, "LocalAuthListEnabled") == 0)
  15921. {
  15922. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15923. {
  15924. strcpy(str, (const char*)value);
  15925. for(int i = 0; str[i]; i++)
  15926. {
  15927. str[i] = tolower(str[i]);
  15928. }
  15929. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15930. isSuccess = ConfigurationStatus_Accepted;
  15931. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15932. }
  15933. else
  15934. {
  15935. isSuccess = ConfigurationStatus_Rejected;
  15936. }
  15937. }
  15938. #endif
  15939. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  15940. {
  15941. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15942. {
  15943. check_ascii = value[0];
  15944. if( (check_ascii < 48) || (check_ascii > 57) )
  15945. {
  15946. isSuccess = ConfigurationStatus_Rejected;
  15947. }
  15948. else
  15949. {
  15950. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  15951. isSuccess = ConfigurationStatus_Accepted;
  15952. }
  15953. }
  15954. else
  15955. {
  15956. isSuccess = ConfigurationStatus_Rejected;
  15957. }
  15958. }
  15959. if(strcmp(key, "SendLocalListMaxLength") == 0)
  15960. {
  15961. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15962. {
  15963. check_ascii = value[0];
  15964. if( (check_ascii < 48) || (check_ascii > 57) )
  15965. {
  15966. isSuccess = ConfigurationStatus_Rejected;
  15967. }
  15968. else
  15969. {
  15970. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  15971. isSuccess = ConfigurationStatus_Accepted;
  15972. }
  15973. }
  15974. else
  15975. {
  15976. isSuccess = ConfigurationStatus_Rejected;
  15977. }
  15978. }
  15979. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  15980. {
  15981. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15982. {
  15983. strcpy(str, (const char*)value);
  15984. for(int i = 0; str[i]; i++)
  15985. {
  15986. str[i] = tolower(str[i]);
  15987. }
  15988. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15989. isSuccess = ConfigurationStatus_Accepted;
  15990. }
  15991. else
  15992. {
  15993. isSuccess = ConfigurationStatus_Rejected;
  15994. }
  15995. }
  15996. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  15997. {
  15998. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15999. {
  16000. check_ascii = value[0];
  16001. if( (check_ascii < 48) || (check_ascii > 57) )
  16002. {
  16003. isSuccess = ConfigurationStatus_Rejected;
  16004. }
  16005. else
  16006. {
  16007. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16008. isSuccess = ConfigurationStatus_Accepted;
  16009. }
  16010. }
  16011. else
  16012. {
  16013. isSuccess = ConfigurationStatus_Rejected;
  16014. }
  16015. }
  16016. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16017. {
  16018. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16019. {
  16020. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16021. isSuccess = ConfigurationStatus_Accepted;
  16022. }
  16023. else
  16024. {
  16025. isSuccess = ConfigurationStatus_Rejected;
  16026. }
  16027. }
  16028. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16029. {
  16030. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16031. {
  16032. check_ascii = value[0];
  16033. if( (check_ascii < 48) || (check_ascii > 57) )
  16034. {
  16035. isSuccess = ConfigurationStatus_Rejected;
  16036. }
  16037. else
  16038. {
  16039. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16040. isSuccess = ConfigurationStatus_Accepted;
  16041. }
  16042. }
  16043. else
  16044. {
  16045. isSuccess = ConfigurationStatus_Rejected;
  16046. }
  16047. }
  16048. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16049. {
  16050. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16051. {
  16052. strcpy(str, (const char*)value);
  16053. for(int i = 0; str[i]; i++)
  16054. {
  16055. str[i] = tolower(str[i]);
  16056. }
  16057. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16058. isSuccess = ConfigurationStatus_Accepted;
  16059. }
  16060. else
  16061. {
  16062. isSuccess = ConfigurationStatus_Rejected;
  16063. }
  16064. }
  16065. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16066. {
  16067. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16068. {
  16069. check_ascii = value[0];
  16070. if( (check_ascii < 48) || (check_ascii > 57) )
  16071. {
  16072. isSuccess = ConfigurationStatus_Rejected;
  16073. }
  16074. else
  16075. {
  16076. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16077. isSuccess = ConfigurationStatus_Accepted;
  16078. }
  16079. }
  16080. else
  16081. {
  16082. isSuccess = ConfigurationStatus_Rejected;
  16083. }
  16084. }
  16085. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16086. return isSuccess;
  16087. }
  16088. int TransactionMessageAttemptsGet(void)
  16089. {
  16090. return TransactionMessageAttemptsValue;
  16091. }
  16092. int FirstHeartBeatResponse(void)
  16093. {
  16094. return FirstHeartBeat;
  16095. }
  16096. int TransactionMessageRetryIntervalGet(void)
  16097. {
  16098. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16099. }
  16100. int ReadHttpStatus(int sock)
  16101. {
  16102. //char c;
  16103. char buff[1024]="",*ptr=buff+1;
  16104. int bytes_received, status;
  16105. DEBUG_INFO("Begin Response ..\n");
  16106. while((bytes_received = recv(sock, ptr, 1, 0))){
  16107. if(bytes_received==-1){
  16108. perror("ReadHttpStatus");
  16109. exit(1);
  16110. }
  16111. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16112. ptr++;
  16113. }
  16114. *ptr=0;
  16115. ptr=buff+1;
  16116. sscanf(ptr,"%*s %d ", &status);
  16117. DEBUG_INFO("%s\n",ptr);
  16118. DEBUG_INFO("status=%d\n",status);
  16119. DEBUG_INFO("End Response ..\n");
  16120. return (bytes_received>0)?status:0;
  16121. }
  16122. //the only filed that it parsed is 'Content-Length'
  16123. int ParseHeader(int sock)
  16124. {
  16125. //char c;
  16126. char buff[1024]="",*ptr=buff+4;
  16127. int bytes_received;
  16128. DEBUG_INFO("Begin HEADER ..\n");
  16129. while((bytes_received = recv(sock, ptr, 1, 0))){
  16130. if(bytes_received==-1){
  16131. perror("Parse Header");
  16132. exit(1);
  16133. }
  16134. if(
  16135. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16136. (ptr[-1]=='\r') && (*ptr=='\n' )
  16137. ) break;
  16138. ptr++;
  16139. }
  16140. *ptr=0;
  16141. ptr=buff+4;
  16142. //printf("%s",ptr);
  16143. if(bytes_received){
  16144. ptr=strstr(ptr,"Content-Length:");
  16145. if(ptr){
  16146. sscanf(ptr,"%*s %d",&bytes_received);
  16147. }else
  16148. bytes_received=-1; //unknown size
  16149. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16150. }
  16151. DEBUG_INFO("End HEADER ..\n");
  16152. return bytes_received ;
  16153. }
  16154. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16155. {
  16156. int result = TRUE;
  16157. char rmFileCmd[100]={0};
  16158. char FilePath[100]={0};
  16159. char ftpbuf[200];
  16160. int systemresult;
  16161. sprintf(FilePath,"/mnt/%s",filename);
  16162. system("ping 8.8.8.8 &");
  16163. if((access(FilePath,F_OK))!=-1)
  16164. {
  16165. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16166. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16167. system(rmFileCmd);
  16168. }
  16169. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16170. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16171. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16172. systemresult = system(ftpbuf);
  16173. if(systemresult != 0)
  16174. {
  16175. DEBUG_INFO("http DownLoad error!\n");
  16176. result = FALSE;
  16177. }
  16178. system("pkill ping");
  16179. return result;
  16180. }
  16181. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16182. {
  16183. int result = TRUE;
  16184. char rmFileCmd[100]={0};
  16185. char FilePath[100]={0};
  16186. char ftpbuf[200];
  16187. int systemresult;
  16188. sprintf(FilePath,"/mnt/%s",filename);
  16189. system("ping 8.8.8.8 &");
  16190. if((access(FilePath,F_OK))!=-1)
  16191. {
  16192. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16193. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16194. system(rmFileCmd);
  16195. }
  16196. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16197. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  16198. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16199. systemresult = system(ftpbuf);
  16200. if(systemresult != 0)
  16201. {
  16202. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  16203. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16204. systemresult = system(ftpbuf);
  16205. if(systemresult != 0)
  16206. {
  16207. DEBUG_WARN("wget error!\n");
  16208. result = FALSE;
  16209. }
  16210. }
  16211. system("pkill ping");
  16212. return result;
  16213. }
  16214. int httpUploadFile(char *location, char *path, char *filename,char *url)
  16215. {
  16216. char rmFileCmd[100]={0};
  16217. char FilePath[100]={0};
  16218. char buf[512];
  16219. int systemresult = 0;
  16220. //DEBUG_INFO("filename=%s\n",filename);
  16221. //DEBUG_INFO("url=%s\n",url);
  16222. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  16223. if((access(FilePath,F_OK))!=-1)
  16224. {
  16225. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16226. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16227. system(rmFileCmd);
  16228. }
  16229. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  16230. if(fp == NULL)
  16231. {
  16232. DEBUG_INFO("log is NULL\n");
  16233. return FALSE;
  16234. }
  16235. else
  16236. {
  16237. fprintf(fp, "%s\n", url);
  16238. fprintf(fp, "%s\n", filename);
  16239. fclose(fp);
  16240. }
  16241. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  16242. if(phpFP == NULL)
  16243. {
  16244. DEBUG_INFO("PHP upload fail.\n");
  16245. return FALSE;
  16246. }
  16247. else
  16248. {
  16249. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16250. {
  16251. if(strstr(buf, "result") != NULL)
  16252. {
  16253. sscanf(buf, "result: %d", &systemresult);
  16254. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  16255. }
  16256. }
  16257. pclose(phpFP);
  16258. }
  16259. if(systemresult != 1)
  16260. {
  16261. DEBUG_INFO("HTTP upload error!\n");
  16262. return FALSE;
  16263. }
  16264. return TRUE;
  16265. }
  16266. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  16267. {
  16268. int result = FALSE;
  16269. char ftpbuf[200];
  16270. int systemresult;
  16271. /*
  16272. // Domaind name transfer to IP address
  16273. struct hostent* server;
  16274. char *IPbuffer;
  16275. server = gethostbyname(location);
  16276. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  16277. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16278. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  16279. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  16280. systemresult = system(ftpbuf);
  16281. if(systemresult != 0)
  16282. {
  16283. DEBUG_INFO("ftpput error!\n");
  16284. }
  16285. else
  16286. {
  16287. result = TRUE;
  16288. DEBUG_INFO("ftpput OK!\n");
  16289. }
  16290. return result;
  16291. }
  16292. int GetOcppServerURL()
  16293. {
  16294. int result = FALSE;
  16295. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  16296. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  16297. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  16298. struct yuarel url;
  16299. char urlStr[512];
  16300. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  16301. {
  16302. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  16303. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16304. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16305. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  16306. if(yuarel_parse(&url, urlStr) != -1)
  16307. {
  16308. sprintf(OcppProtocol, "%s", url.scheme);
  16309. sprintf(OcppHost, "%s", url.host);
  16310. if(url.path == NULL)
  16311. OcppTempPath[0] = '\0';
  16312. else
  16313. {
  16314. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  16315. {
  16316. sprintf(OcppTempPath, "%s/", url.path);
  16317. }
  16318. else
  16319. {
  16320. sprintf(OcppTempPath, "%s", url.path);
  16321. }
  16322. }
  16323. if(url.port == 0)
  16324. {
  16325. if(strcmp(OcppProtocol, "wss") == 0)
  16326. OcppPort = 443;
  16327. else
  16328. OcppPort = 80;
  16329. }
  16330. else
  16331. OcppPort = url.port;
  16332. result = TRUE;
  16333. }
  16334. }
  16335. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  16336. {
  16337. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  16338. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16339. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16340. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  16341. if(yuarel_parse(&url, urlStr) != -1)
  16342. {
  16343. sprintf(OcppProtocol, "%s", url.scheme);
  16344. sprintf(OcppHost, "%s", url.host);
  16345. if(url.path == NULL)
  16346. OcppTempPath[0] = '\0';
  16347. else
  16348. sprintf(OcppTempPath, "%s", url.path);
  16349. if(url.port == 0)
  16350. {
  16351. if(strcmp(OcppProtocol, "wss") == 0)
  16352. OcppPort = 443;
  16353. else
  16354. OcppPort = 80;
  16355. }
  16356. else
  16357. OcppPort = url.port;
  16358. result = TRUE;
  16359. }
  16360. }
  16361. else
  16362. {
  16363. strcpy(OcppHost,"");
  16364. }
  16365. return result;
  16366. }
  16367. int GetOcppPath()
  16368. {
  16369. int result = FALSE;
  16370. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  16371. {
  16372. if(OcppTempPath == NULL)
  16373. {
  16374. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  16375. }
  16376. else
  16377. {
  16378. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  16379. }
  16380. result = TRUE;
  16381. goto End;
  16382. }
  16383. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  16384. {
  16385. if(OcppTempPath == NULL)
  16386. {
  16387. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  16388. }
  16389. else
  16390. {
  16391. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  16392. }
  16393. result = TRUE;
  16394. goto End;
  16395. }
  16396. else
  16397. {
  16398. strcpy(OcppPath,"");
  16399. }
  16400. End:
  16401. return result;
  16402. }
  16403. int GetOcppPort()
  16404. {
  16405. return OcppPort;
  16406. }
  16407. int GetOcppConnStatus(void)
  16408. {
  16409. return ShmOCPP16Data->OcppConnStatus;
  16410. }
  16411. void SetOcppConnStatus(uint8_t status)
  16412. {
  16413. ShmOCPP16Data->OcppConnStatus = status;
  16414. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  16415. }
  16416. int GetHeartBeatWithNOResponse(void)
  16417. {
  16418. return HeartBeatWithNOResponse;
  16419. }
  16420. void SetHeartBeatWithNOResponse(void)
  16421. {
  16422. HeartBeatWithNOResponse = 0;
  16423. }
  16424. void GetStartTransactionIdTag(int gun_index)
  16425. {
  16426. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  16427. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  16428. }
  16429. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  16430. {
  16431. char ch;
  16432. FILE *fptr1;
  16433. int temptransactionId;
  16434. char str[100]={0};
  16435. temptransactionId = 0;
  16436. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  16437. {
  16438. DEBUG_INFO("IdTag is empty.\n");
  16439. return temptransactionId;
  16440. }
  16441. /*------ Read the file ----------------*/
  16442. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  16443. if (!fptr1)
  16444. {
  16445. DEBUG_INFO("QueueTransactionId file open error.\n");
  16446. //printf(" File not found or unable to open the input file!!\n");
  16447. return temptransactionId;
  16448. }
  16449. ch=fgetc(fptr1);
  16450. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  16451. rewind(fptr1);
  16452. if(ch!=EOF)
  16453. {
  16454. // printf("%c",ch);
  16455. while (fgets(str, 100, fptr1) != NULL)
  16456. {
  16457. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16458. if(str[0]=='\0')
  16459. {
  16460. break;
  16461. }
  16462. char *revbuf[8] = {0}; // Variable store string split
  16463. int num = 0;// Quantity after string split
  16464. DEBUG_INFO("Transaction queue data= %s\n", str);
  16465. splitstring(str,",",revbuf,&num); // String split
  16466. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  16467. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  16468. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  16469. DEBUG_INFO("------------------------------\n");
  16470. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  16471. {
  16472. if(isStopTransaction)
  16473. {
  16474. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  16475. {
  16476. temptransactionId = atoi(revbuf[2]);
  16477. //break;
  16478. }
  16479. }
  16480. else
  16481. {
  16482. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  16483. {
  16484. temptransactionId = atoi(revbuf[2]);
  16485. //break;
  16486. }
  16487. }
  16488. }
  16489. }
  16490. }
  16491. else
  16492. DEBUG_INFO("EOF\n");
  16493. fclose(fptr1);
  16494. /*------- End of reading ---------------*/
  16495. return temptransactionId;
  16496. }
  16497. void SetTransactionIdZero(int transactionId)
  16498. {
  16499. char ch;
  16500. FILE *fptr1, *fptr2;
  16501. int temptransactionId = 0;
  16502. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  16503. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  16504. if (!fptr1)
  16505. {
  16506. //printf(" File not found or unable to open the input file!!\n");
  16507. return ;
  16508. }
  16509. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  16510. if (!fptr2)
  16511. {
  16512. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  16513. fclose(fptr1);
  16514. return ;
  16515. }
  16516. ch=fgetc(fptr1);
  16517. rewind(fptr1);
  16518. if(ch!=EOF)
  16519. {
  16520. // copy all contents to the temporary file except the specific line
  16521. while (fgets(str, 100, fptr1) != NULL)
  16522. {
  16523. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16524. if(str[0]=='\0')
  16525. {
  16526. break;
  16527. }
  16528. char *revbuf[8] = {0};
  16529. int num = 0;
  16530. strcpy(strtemp, str);
  16531. splitstring(str,",",revbuf,&num);
  16532. if(revbuf[2][0] != '\0')
  16533. {
  16534. temptransactionId = atoi(revbuf[2]);
  16535. if(transactionId != temptransactionId)
  16536. {
  16537. fprintf(fptr2, "%s\n", strtemp);
  16538. }
  16539. }
  16540. }
  16541. }
  16542. fclose(fptr1);
  16543. fclose(fptr2);
  16544. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  16545. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  16546. /*------ Read the file ----------------*/
  16547. }
  16548. int InternetDisconnect(void)
  16549. {
  16550. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  16551. }
  16552. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  16553. void storeTempStopTransaction(int gun_index)
  16554. {
  16555. char guid[37]={0};
  16556. int tempIndex = 0;
  16557. char TempStopTransaction[256];
  16558. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  16559. DEBUG_INFO("storeTempStopTransaction...\n");
  16560. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  16561. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  16562. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  16563. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16564. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16565. {
  16566. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16567. {
  16568. tempIndex = ((gun_index==2) ? 1: 0);
  16569. }
  16570. else
  16571. {
  16572. tempIndex = gun_index;
  16573. }
  16574. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16575. {
  16576. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16577. {
  16578. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  16579. }
  16580. }// END OF CHAdeMO_QUANTITY
  16581. }
  16582. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16583. {
  16584. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16585. {
  16586. tempIndex = ((gun_index==2) ? 1: 0);
  16587. }
  16588. else
  16589. {
  16590. tempIndex = gun_index;
  16591. }
  16592. for (int index = 0; index < CCS_QUANTITY; index++)
  16593. {
  16594. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16595. {
  16596. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  16597. }
  16598. }// END OF CCS_QUANTITY
  16599. }
  16600. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16601. {
  16602. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16603. {
  16604. tempIndex = ((gun_index==2) ? 1: 0);
  16605. }
  16606. else
  16607. {
  16608. tempIndex = gun_index;
  16609. }
  16610. for (int index = 0; index < GB_QUANTITY; index++)
  16611. {
  16612. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16613. {
  16614. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  16615. }
  16616. }// END OF GB_QUANTITY
  16617. }
  16618. else if(gunType[gun_index] == GUN_TYPE_DO)
  16619. {
  16620. tempIndex = gun_index;
  16621. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16622. {
  16623. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16624. {
  16625. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  16626. }
  16627. }
  16628. }
  16629. else
  16630. {
  16631. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16632. {
  16633. tempIndex = 2;
  16634. }
  16635. else
  16636. {
  16637. tempIndex = gun_index;
  16638. }
  16639. for (int index = 0; index < AC_QUANTITY; index++)
  16640. {
  16641. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16642. {
  16643. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  16644. }
  16645. }// END OF AC_QUANTITY
  16646. }
  16647. //Stop Transaction Time
  16648. struct timeval tmnow;
  16649. struct tm *tm;
  16650. char buf[28];//, usec_buf[6];
  16651. gettimeofday(&tmnow, NULL);
  16652. time_t t;
  16653. t = time(NULL);
  16654. /*UTC time and date*/
  16655. tm = gmtime(&t);
  16656. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  16657. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  16658. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  16659. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  16660. random_uuid(guid);
  16661. /***********************************transactionData******************************************************/
  16662. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  16663. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  16664. //=================================
  16665. //1. Transaction_Begin
  16666. //=================================
  16667. //============================== Energy.Active.Import.Interval ===========================================
  16668. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16669. {
  16670. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  16671. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16672. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  16673. 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*/]);
  16674. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16675. 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))
  16676. {
  16677. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  16678. }
  16679. else
  16680. {
  16681. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  16682. }
  16683. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  16684. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16685. }
  16686. //=================================
  16687. //2. Transaction_End
  16688. //=================================
  16689. //2.1====================================== Current.Import L1 ==============================================
  16690. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16691. {
  16692. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  16693. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16694. {
  16695. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16696. {
  16697. tempIndex = ((gun_index==2) ? 1: 0);
  16698. }
  16699. else
  16700. {
  16701. tempIndex = gun_index;
  16702. }
  16703. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16704. {
  16705. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16706. {
  16707. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16708. }
  16709. }// End of for CHAdeMO_QUANTITY
  16710. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16711. }
  16712. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16713. {
  16714. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16715. {
  16716. tempIndex = ((gun_index==2) ? 1: 0);
  16717. }
  16718. else
  16719. {
  16720. tempIndex = gun_index;
  16721. }
  16722. for (int index = 0; index < CCS_QUANTITY; index++)
  16723. {
  16724. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16725. {
  16726. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16727. }
  16728. }// End of for CCS_QUANTITY
  16729. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16730. }
  16731. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16732. {
  16733. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16734. {
  16735. tempIndex = ((gun_index==2) ? 1: 0);
  16736. }
  16737. else
  16738. {
  16739. tempIndex = gun_index;
  16740. }
  16741. for (int index = 0; index < GB_QUANTITY; index++)
  16742. {
  16743. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16744. {
  16745. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16746. }
  16747. }// End of for GB_QUANTITY
  16748. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16749. }
  16750. else if(gunType[gun_index] == GUN_TYPE_DO)
  16751. {
  16752. tempIndex = gun_index;
  16753. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16754. {
  16755. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16756. {
  16757. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16758. }
  16759. }
  16760. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16761. }
  16762. else
  16763. {
  16764. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16765. {
  16766. tempIndex = 2;
  16767. }
  16768. else
  16769. {
  16770. tempIndex = gun_index;
  16771. }
  16772. for (int index = 0; index < AC_QUANTITY; index++)
  16773. {
  16774. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16775. {
  16776. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  16777. }
  16778. }// End of for AC_QUANTITY
  16779. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16780. }
  16781. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16782. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  16783. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  16784. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16785. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  16786. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16787. }
  16788. //2.2===================================== Energy.Active.Import.Interval ==========================================
  16789. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16790. {
  16791. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16792. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16793. {
  16794. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16795. {
  16796. tempIndex = ((gun_index==2) ? 1: 0);
  16797. }
  16798. else
  16799. {
  16800. tempIndex = gun_index;
  16801. }
  16802. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16803. {
  16804. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16805. {
  16806. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16807. }
  16808. }// END OF CHAdeMO_QUANTITY
  16809. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16810. }
  16811. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16812. {
  16813. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16814. {
  16815. tempIndex = ((gun_index==2) ? 1: 0);
  16816. }
  16817. else
  16818. {
  16819. tempIndex = gun_index;
  16820. }
  16821. for (int index = 0; index < CCS_QUANTITY; index++)
  16822. {
  16823. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16824. {
  16825. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16826. }
  16827. }// END OF CCS_QUANTITY
  16828. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16829. }
  16830. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16831. {
  16832. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16833. {
  16834. tempIndex = ((gun_index==2) ? 1: 0);
  16835. }
  16836. else
  16837. {
  16838. tempIndex = gun_index;
  16839. }
  16840. for (int index = 0; index < GB_QUANTITY; index++)
  16841. {
  16842. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16843. {
  16844. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16845. }
  16846. }// END OF GB_QUANTITY
  16847. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16848. }
  16849. else if(gunType[gun_index] == GUN_TYPE_DO)
  16850. {
  16851. tempIndex = gun_index;
  16852. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16853. {
  16854. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16855. {
  16856. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16857. }
  16858. }
  16859. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16860. }
  16861. else
  16862. {
  16863. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16864. {
  16865. tempIndex = 2;
  16866. }
  16867. else
  16868. {
  16869. tempIndex = gun_index;
  16870. }
  16871. for (int index = 0; index < AC_QUANTITY; index++)
  16872. {
  16873. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16874. {
  16875. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16876. }
  16877. }// END OF AC_QUANTITY
  16878. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16879. }
  16880. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16881. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  16882. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  16883. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16884. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  16885. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16886. }
  16887. //2.3====================================== Power.Active.Import =========================================
  16888. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  16889. {
  16890. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16891. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16892. {
  16893. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16894. {
  16895. tempIndex = ((gun_index==2) ? 1: 0);
  16896. }
  16897. else
  16898. {
  16899. tempIndex = gun_index;
  16900. }
  16901. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16902. {
  16903. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16904. {
  16905. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16906. }
  16907. } // End for CHAdeMO_QUANTITY
  16908. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16909. }
  16910. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16911. {
  16912. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16913. {
  16914. tempIndex = ((gun_index==2) ? 1: 0);
  16915. }
  16916. else
  16917. {
  16918. tempIndex = gun_index;
  16919. }
  16920. for (int index = 0; index < CCS_QUANTITY; index++)
  16921. {
  16922. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16923. {
  16924. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16925. }
  16926. } // END for CCS_QUANTITY
  16927. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16928. }
  16929. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16930. {
  16931. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16932. {
  16933. tempIndex = ((gun_index==2) ? 1: 0);
  16934. }
  16935. else
  16936. {
  16937. tempIndex = gun_index;
  16938. }
  16939. for (int index = 0; index < GB_QUANTITY; index++)
  16940. {
  16941. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16942. {
  16943. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16944. }
  16945. }// END for GB_QUANTITY
  16946. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16947. }
  16948. else if(gunType[gun_index] == GUN_TYPE_DO)
  16949. {
  16950. tempIndex = gun_index;
  16951. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16952. {
  16953. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16954. {
  16955. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16956. }
  16957. }
  16958. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16959. }
  16960. else
  16961. {
  16962. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16963. {
  16964. tempIndex = 2;
  16965. }
  16966. else
  16967. {
  16968. tempIndex = gun_index;
  16969. }
  16970. for (int index = 0; index < AC_QUANTITY; index++)
  16971. {
  16972. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16973. {
  16974. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16975. }
  16976. } // END for AC_QUANTITY
  16977. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16978. }
  16979. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16980. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  16981. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  16982. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16983. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  16984. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  16985. }
  16986. //2.4====================================== Voltage L1 ====================================================
  16987. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16988. {
  16989. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16990. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16991. {
  16992. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16993. {
  16994. tempIndex = ((gun_index==2) ? 1: 0);
  16995. }
  16996. else
  16997. {
  16998. tempIndex = gun_index;
  16999. }
  17000. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17001. {
  17002. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17003. {
  17004. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17005. }
  17006. } // END OF FOR CHAdeMO_QUANTITY
  17007. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17008. }
  17009. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17010. {
  17011. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17012. {
  17013. tempIndex = ((gun_index==2) ? 1: 0);
  17014. }
  17015. else
  17016. {
  17017. tempIndex = gun_index;
  17018. }
  17019. for (int index = 0; index < CCS_QUANTITY; index++)
  17020. {
  17021. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17022. {
  17023. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17024. }
  17025. } // END OF FOR CCS_QUANTITY
  17026. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17027. }
  17028. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17029. {
  17030. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17031. {
  17032. tempIndex = ((gun_index==2) ? 1: 0);
  17033. }
  17034. else
  17035. {
  17036. tempIndex = gun_index;
  17037. }
  17038. for (int index = 0; index < GB_QUANTITY; index++)
  17039. {
  17040. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17041. {
  17042. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17043. }
  17044. } // END OF FOR GB_QUANTITY
  17045. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17046. }
  17047. else if(gunType[gun_index] == GUN_TYPE_DO)
  17048. {
  17049. tempIndex = gun_index;
  17050. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17051. {
  17052. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17053. {
  17054. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17055. }
  17056. }
  17057. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17058. }
  17059. else
  17060. {
  17061. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17062. {
  17063. tempIndex = 2;
  17064. }
  17065. else
  17066. {
  17067. tempIndex = gun_index;
  17068. }
  17069. for (int index = 0; index < AC_QUANTITY; index++)
  17070. {
  17071. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17072. {
  17073. 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
  17074. }
  17075. } // END OF FOR AC_QUANTITY
  17076. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17077. }
  17078. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17079. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17081. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17082. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17083. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17084. }
  17085. //2.5============================================== End SoC =========================================================
  17086. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17087. {
  17088. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17089. 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))
  17090. {
  17091. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17092. {
  17093. tempIndex = ((gun_index==2) ? 1: 0);
  17094. }
  17095. else
  17096. {
  17097. tempIndex = gun_index;
  17098. }
  17099. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17100. {
  17101. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17102. {
  17103. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17104. {
  17105. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17106. }
  17107. }
  17108. }
  17109. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17110. {
  17111. for (int index = 0; index < CCS_QUANTITY; index++)
  17112. {
  17113. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17114. {
  17115. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17116. }
  17117. }
  17118. }
  17119. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17120. {
  17121. for (int index = 0; index < GB_QUANTITY; index++)
  17122. {
  17123. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17124. {
  17125. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17126. }
  17127. }
  17128. }
  17129. else if(gunType[gun_index] == GUN_TYPE_DO)
  17130. {
  17131. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17132. {
  17133. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17134. {
  17135. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17136. }
  17137. }
  17138. }
  17139. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17140. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17141. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17142. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17143. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17144. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17145. } // END FOR DC CASE
  17146. }
  17147. //2.6====================================== Current.Import L2 ==============================================
  17148. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17149. {
  17150. // AC 3 phase L2 current
  17151. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17152. {
  17153. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17154. {
  17155. tempIndex = 2;
  17156. }
  17157. else
  17158. {
  17159. tempIndex = gun_index;
  17160. }
  17161. for (int index = 0; index < AC_QUANTITY; index++)
  17162. {
  17163. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17164. {
  17165. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17166. }
  17167. }// End of for AC_QUANTITY
  17168. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17169. }
  17170. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17171. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17172. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17173. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17174. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17175. }
  17176. //2.7====================================== Current.Import L3 ==============================================
  17177. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17178. {
  17179. // AC 3 phase L3 current
  17180. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17181. {
  17182. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17183. {
  17184. tempIndex = 2;
  17185. }
  17186. else
  17187. {
  17188. tempIndex = gun_index;
  17189. }
  17190. for (int index = 0; index < AC_QUANTITY; index++)
  17191. {
  17192. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17193. {
  17194. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  17195. }
  17196. }// End of for AC_QUANTITY
  17197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  17198. }
  17199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  17201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  17202. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  17203. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17204. }
  17205. //2.9====================================== Voltage L2 ====================================================
  17206. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17207. {
  17208. // AC 3 phase L2 volatge
  17209. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17210. {
  17211. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17212. {
  17213. tempIndex = 2;
  17214. }
  17215. else
  17216. {
  17217. tempIndex = gun_index;
  17218. }
  17219. for (int index = 0; index < AC_QUANTITY; index++)
  17220. {
  17221. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17222. {
  17223. 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
  17224. }
  17225. } // END OF FOR AC_QUANTITY
  17226. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  17227. }
  17228. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17229. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  17230. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  17231. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  17232. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17233. }
  17234. //2.10====================================== Voltage L3 ====================================================
  17235. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17236. {
  17237. // AC 3 phase L3 volatge
  17238. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17239. {
  17240. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17241. {
  17242. tempIndex = 2;
  17243. }
  17244. else
  17245. {
  17246. tempIndex = gun_index;
  17247. }
  17248. for (int index = 0; index < AC_QUANTITY; index++)
  17249. {
  17250. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17251. {
  17252. 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
  17253. }
  17254. } // END OF FOR AC_QUANTITY
  17255. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  17256. }
  17257. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17258. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  17259. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  17260. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  17261. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17262. }
  17263. //====================== Start SoC ================================
  17264. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17265. {
  17266. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17267. 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))
  17268. {
  17269. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17270. {
  17271. tempIndex = ((gun_index==2) ? 1: 0);
  17272. }
  17273. else
  17274. {
  17275. tempIndex = gun_index;
  17276. }
  17277. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17278. {
  17279. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17280. {
  17281. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17282. {
  17283. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  17284. }
  17285. }
  17286. }
  17287. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17288. {
  17289. for (int index = 0; index < CCS_QUANTITY; index++)
  17290. {
  17291. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17292. {
  17293. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  17294. }
  17295. }
  17296. }
  17297. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17298. {
  17299. for (int index = 0; index < GB_QUANTITY; index++)
  17300. {
  17301. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17302. {
  17303. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  17304. }
  17305. }
  17306. }
  17307. else if(gunType[gun_index] == GUN_TYPE_DO)
  17308. {
  17309. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17310. {
  17311. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17312. {
  17313. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  17314. }
  17315. }
  17316. }
  17317. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17318. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  17319. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17320. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  17321. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  17322. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17323. } // END FOR DC CASE
  17324. }
  17325. //======================================== Message create ==============================================
  17326. json_object *StopTransaction = json_object_new_object();
  17327. json_object *transactionDatas = json_object_new_array();
  17328. json_object *sampledValues = json_object_new_array();
  17329. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  17330. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  17331. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  17332. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  17333. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  17334. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  17335. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  17336. {
  17337. json_object *transactionData = json_object_new_object();
  17338. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  17339. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  17340. {
  17341. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  17342. {
  17343. json_object *sampledValue = json_object_new_object();
  17344. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  17345. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  17346. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  17347. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  17348. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  17349. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  17350. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  17351. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  17352. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  17353. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  17354. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  17355. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  17356. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  17357. json_object_array_add(sampledValues, sampledValue);
  17358. }
  17359. }
  17360. json_object_object_add(transactionData, "sampledValue", sampledValues);
  17361. json_object_array_add(transactionDatas, transactionData);
  17362. }
  17363. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  17364. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  17365. ,MESSAGE_TYPE_CALL
  17366. ,guid
  17367. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  17368. json_object_put(StopTransaction);
  17369. // Check File "TempStopTransaction" Exist
  17370. if((access(TempStopTransaction,F_OK))!=-1)
  17371. {
  17372. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  17373. fclose(fopen(TempStopTransaction, "w"));
  17374. }
  17375. else
  17376. {
  17377. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  17378. FILE *log = fopen(TempStopTransaction, "w+");
  17379. if(log == NULL)
  17380. {
  17381. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  17382. return ;
  17383. }
  17384. else
  17385. {
  17386. fclose(log);
  17387. }
  17388. }
  17389. //Add TempStopTransaction | Update TempStopTransaction
  17390. // open file for writing
  17391. FILE *outfile;
  17392. outfile = fopen (TempStopTransaction, "a");
  17393. //DEBUG_INFO("data = %s\n", queuedata);
  17394. fputs(queuedata, outfile);
  17395. fputs("\n", outfile);
  17396. fclose (outfile);
  17397. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17398. }
  17399. void checkTempStopTransaction(int gun_index)
  17400. {
  17401. FILE *fptr1;
  17402. char ch;
  17403. char str[QUEUE_MESSAGE_LENGTH]={0};
  17404. char guid[37]={0};
  17405. char tempdata[65]={0};
  17406. char connectorStr[2]={0};
  17407. char TempStopTransaction[256];
  17408. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  17409. fptr1 = fopen(TempStopTransaction, "r");
  17410. //TempStopTransaction格式: 槍號,StopTransaction封包
  17411. if (!fptr1)
  17412. {
  17413. //printf(" File not found or unable to open the input file!!\n");
  17414. return ;
  17415. }
  17416. ch=fgetc(fptr1);
  17417. //printf(" Now the content of the file %s is : \n",fname);
  17418. rewind(fptr1);
  17419. if(ch!=EOF)
  17420. {
  17421. // copy all contents to the temporary file except the specific line
  17422. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  17423. {
  17424. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17425. if(str[0]=='\0')
  17426. {
  17427. break;
  17428. }
  17429. //TempStopTransaction格式: 槍號,StopTransaction封包
  17430. strncpy(connectorStr, str, 1);
  17431. if(atoi(connectorStr) != (gun_index+1))
  17432. {
  17433. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  17434. fclose(fptr1);
  17435. return ;
  17436. }
  17437. //random_uuid(guid);
  17438. strncpy(guid, str+6, 36); //copy guid
  17439. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  17440. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  17441. {
  17442. //DEBUG_INFO("StopTransaction mapitem pass\n");
  17443. }
  17444. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  17445. OCPP_insert_transaction_msg(NO, str);
  17446. memset(str,0,ARRAY_SIZE(str));
  17447. }
  17448. }
  17449. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  17450. fclose(fptr1);
  17451. remove(TempStopTransaction); // remove the original file
  17452. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17453. }
  17454. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  17455. {
  17456. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  17457. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  17458. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  17459. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  17460. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  17461. }
  17462. int GetWebSocketPingInterval(void)
  17463. {
  17464. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  17465. }
  17466. int GetServerSign(void)
  17467. {
  17468. return server_sign;
  17469. }
  17470. uint8_t GetOcppSecurityProfile()
  17471. {
  17472. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  17473. }
  17474. void GetOcppChargerBoxId(uint8_t *data)
  17475. {
  17476. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17477. }
  17478. void GetOcppSecurityPassword(uint8_t *data)
  17479. {
  17480. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17481. }
  17482. void SetOcppVersion(uint8_t *version)
  17483. {
  17484. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  17485. DEBUG_INFO("ocpp version: %s\n", version);
  17486. if(strstr((char*)version, "ocpp1.6") != NULL)
  17487. {
  17488. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  17489. }
  17490. else if(strstr((char*)version, "ocpp2.0") != NULL)
  17491. {
  17492. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  17493. system("pkill OcppBackend");
  17494. }
  17495. }
  17496. void SetServerSign(int value)
  17497. {
  17498. server_sign = value;
  17499. }
  17500. int GetBootNotificationInterval(void)
  17501. {
  17502. return BootNotificationInterval;
  17503. }
  17504. int GetInternetConn(void)
  17505. {
  17506. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  17507. }
  17508. int GetBackendConnectionTimeout(void)
  17509. {
  17510. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  17511. }
  17512. int isConnectorInitMode(int gun_index)
  17513. {
  17514. int tempIndex = 0;
  17515. int result = TRUE;
  17516. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17517. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17518. {
  17519. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17520. {
  17521. tempIndex = ((gun_index==2) ? 1: 0);
  17522. }
  17523. else
  17524. {
  17525. tempIndex = gun_index;
  17526. }
  17527. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17528. {
  17529. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  17530. {
  17531. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17532. } //end of the same index
  17533. }//end of for CHAdeMO_QUANTITY
  17534. }
  17535. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17536. {
  17537. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17538. {
  17539. tempIndex = ((gun_index==2) ? 1: 0);
  17540. }
  17541. else
  17542. {
  17543. tempIndex = gun_index;
  17544. }
  17545. for (int index = 0; index < CCS_QUANTITY; index++)
  17546. {
  17547. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17548. {
  17549. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17550. } //end of the same index
  17551. } // end of for CCS_QUANTITY
  17552. }
  17553. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17554. {
  17555. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17556. {
  17557. tempIndex = ((gun_index==2) ? 1: 0);
  17558. }
  17559. else
  17560. {
  17561. tempIndex = gun_index;
  17562. }
  17563. for (int index = 0; index < GB_QUANTITY; index++)
  17564. {
  17565. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17566. {
  17567. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17568. } //end of the same index
  17569. } // end of for GB_QUANTITY
  17570. }
  17571. else if(gunType[gun_index] == GUN_TYPE_DO)
  17572. {
  17573. tempIndex = gun_index;
  17574. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17575. {
  17576. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17577. {
  17578. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17579. } //end of the same index
  17580. }
  17581. }
  17582. else
  17583. {
  17584. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17585. {
  17586. tempIndex = 2;
  17587. }
  17588. else
  17589. {
  17590. tempIndex = gun_index;
  17591. }
  17592. for (int index = 0; index < AC_QUANTITY; index++)
  17593. {
  17594. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17595. {
  17596. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17597. }//end of the same index
  17598. }//end of for AC_QUANTITY
  17599. }
  17600. return result;
  17601. }
  17602. void refreshProcDogTimer()
  17603. {
  17604. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  17605. }
  17606. void InitialSystemValue(void)
  17607. {
  17608. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  17609. locallistVersion=0;
  17610. BootNotificationInterval = 0;
  17611. authorizeRetryTimes = 0;
  17612. GunStatusInterval = 10;
  17613. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  17614. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17615. //Hear Beat
  17616. HeartBeatWithNOResponse = 0;
  17617. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  17618. FirstHeartBeat = 0;
  17619. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  17620. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  17621. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  17622. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  17623. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  17624. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  17625. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  17626. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  17627. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  17628. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  17629. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  17630. //Status && ConnectorPlugIn Setting
  17631. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17632. {
  17633. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  17634. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  17635. }
  17636. for (int index = 0; index < CCS_QUANTITY; index++)
  17637. {
  17638. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  17639. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  17640. }
  17641. for (int index = 0; index < GB_QUANTITY; index++)
  17642. {
  17643. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  17644. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  17645. }
  17646. for (int index = 0; index < AC_QUANTITY; index++)
  17647. {
  17648. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  17649. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  17650. }
  17651. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17652. {
  17653. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  17654. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  17655. }
  17656. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  17657. {
  17658. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  17659. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  17660. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  17661. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  17662. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  17663. }
  17664. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  17665. refreshStartTimer(&clientTime.Heartbeat);
  17666. sleep(1);
  17667. }
  17668. void LWS_Send(char *str)
  17669. {
  17670. //=====================================================
  17671. // Check InternetConn 0: disconnected, 1: connected
  17672. //====================================================
  17673. if(GetOcppConnStatus() == 0)
  17674. {
  17675. DEBUG_INFO("offline now !!!\n");
  17676. return;
  17677. }
  17678. // Only disable isWebsocketSendable operation initiated by charger
  17679. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17680. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17681. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17682. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17683. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17684. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17685. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17686. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17687. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17688. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17689. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17690. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17691. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17692. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17693. {
  17694. isWebsocketSendable = 0;
  17695. }
  17696. pthread_mutex_lock(&lock_send);
  17697. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17698. sprintf((char *)SendBuffer, "%s", str);
  17699. SendBufLen = strlen(str);
  17700. pthread_mutex_unlock(&lock_send);
  17701. lws_callback_on_writable(wsi_client);
  17702. //lws_service(context, 0);
  17703. //sleep(1);
  17704. }
  17705. void LWS_SendNow(char *str)
  17706. {
  17707. //=====================================================
  17708. // Check InternetConn 0: disconnected, 1: connected
  17709. //====================================================
  17710. if(GetOcppConnStatus() == 0)
  17711. {
  17712. DEBUG_INFO("offline now !!!\n");
  17713. return;
  17714. }
  17715. // Only disable isWebsocketSendable operation initiated by charger
  17716. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17717. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17718. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17719. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17720. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17721. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17722. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17723. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17724. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17725. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17726. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17727. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17728. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17729. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17730. {
  17731. isWebsocketSendable = 0;
  17732. }
  17733. pthread_mutex_lock(&lock_send);
  17734. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17735. sprintf((char *)SendBuffer, "%s", str);
  17736. SendBufLen = strlen(str);
  17737. pthread_mutex_unlock(&lock_send);
  17738. lws_callback_on_writable(wsi_client);
  17739. lws_service(context, 0);
  17740. //sleep(1);
  17741. }