MessageHandler.c 947 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755
  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 ParsingRatedCur modelnameInfo = {0};
  28. static int gunTotalNumber = 0;
  29. static uint8_t gunType[4] = {0};
  30. //===============================
  31. // Local List Version
  32. //===============================
  33. static int locallistVersion=0;
  34. static char idTagAuthorization[32] = {0};
  35. //===============================
  36. // OCPP sign variable
  37. //===============================
  38. static int server_sign = FALSE;
  39. int server_pending = FALSE;
  40. static int BootNotificationInterval = 0;
  41. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  42. //===============================
  43. // OCPP auth variable
  44. //===============================
  45. static int authorizeRetryTimes = 0; //number of Retry times
  46. //===============================
  47. // OCPP other variables
  48. //===============================
  49. static int HeartBeatWaitTime = 10;
  50. static int FirstHeartBeat = 0;
  51. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  52. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  53. static char CurrentChargingProfileScheduleStr[30] = {0};
  54. //========================================
  55. // OCPP status/previous related variables
  56. //========================================
  57. static int GunStatusInterval = 10;
  58. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  59. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  60. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  61. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  62. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  63. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  64. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  65. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  66. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  67. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  68. static int TransactionMessageAttemptsValue = 0;
  69. static int TransactionMessageRetryIntervalValue = 0;
  70. static int TempMeterValueInterval = 0;
  71. static struct OCPPAuthLocalElemet
  72. {
  73. int listVersionInt;
  74. char idTagstr[21];
  75. char parentIdTag[21];
  76. char expiryDate[36];
  77. char idTagstatus[16];
  78. }idTagQuery;
  79. //============================================
  80. // OCPP MeterValue request flag
  81. //============================================
  82. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  83. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  84. //=============================================
  85. // OCPP HeartBeat Response Not Receive Counts
  86. //============================================
  87. static int HeartBeatWithNOResponse = 0;
  88. extern sqlite3 *db;
  89. int TransactionMessageAttemptsGet(void);
  90. int TransactionMessageRetryIntervalGet(void);
  91. int GetOcppConnStatus(void);
  92. void SetOcppConnStatus(uint8_t status);
  93. int setKeyValue(char *key, char *value);
  94. void OCPP_get_TableAuthlocalAllData(void);
  95. void processUnkownKey(void);
  96. struct InterLock
  97. {
  98. unsigned char isGetDiagnosticGoing:1;
  99. unsigned char isUpdateFirmwareGoing:1;
  100. }interLock;
  101. struct ClientTime
  102. {
  103. struct timespec Heartbeat;
  104. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  105. struct timespec StartTransaction;
  106. struct timespec StopTransaction;
  107. struct timespec MeterValues[CONNECTOR_QUANTITY];
  108. struct timespec RemoteStartWait;
  109. struct timespec TcciQueryDeduct;
  110. }clientTime;
  111. typedef union
  112. {
  113. //Operations Initiated by Central System
  114. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  115. struct
  116. {
  117. //CsMsgValue[0]
  118. unsigned char StatusNotificationReq:1; //bit 0,
  119. unsigned char StatusNotificationConf:1; //bit 1,
  120. unsigned char TriggerMeterValue:1; //bit 2,
  121. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  122. unsigned char isOnCharging:1; //bit 4,
  123. unsigned char :3; //bit5~7
  124. }bits[CONNECTOR_QUANTITY];
  125. }CpinitiateMsg;
  126. CpinitiateMsg cpinitateMsg;
  127. //GetConfiguration Array
  128. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  129. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  130. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  131. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  132. #if 0
  133. static char *ChargePointErrorCodeStr[] = {
  134. MACROSTR(ConnectorLockFailure),
  135. MACROSTR(EVCommunicationError),
  136. MACROSTR(GroundFailure),
  137. MACROSTR(HighTemperature),
  138. MACROSTR(InternalError),
  139. MACROSTR(LocalListConflict),
  140. MACROSTR(NoError),
  141. MACROSTR(OtherError),
  142. MACROSTR(OverCurrentFailure),
  143. MACROSTR(OverVoltage),
  144. MACROSTR(PowerMeterFailure),
  145. MACROSTR(PowerSwitchFailure),
  146. MACROSTR(ReaderFailure),
  147. MACROSTR(ResetFailure),
  148. MACROSTR(UnderVoltage),
  149. MACROSTR(WeakSignal)
  150. };
  151. #endif
  152. static char * ChargePointStatusStr[] = {
  153. MACROSTR(Available),
  154. MACROSTR(Preparing),
  155. MACROSTR(Charging),
  156. MACROSTR(SuspendedEVSE),
  157. MACROSTR(SuspendedEV),
  158. MACROSTR(Finishing),
  159. MACROSTR(Reserved),
  160. MACROSTR(Unavailable),
  161. MACROSTR(Faulted)
  162. };
  163. static char *RegistrationStatusStr[] = {
  164. MACROSTR(Accepted),
  165. MACROSTR(Pending),
  166. MACROSTR(Rejected)
  167. };
  168. static char *AvailabilityTypeStr[] = {
  169. MACROSTR(Inoperative),
  170. MACROSTR(Operative)
  171. };
  172. static char *AvailabilityStatusStr[] = {
  173. MACROSTR(Accepted),
  174. MACROSTR(Rejected),
  175. MACROSTR(Scheduled)
  176. };
  177. static char *ConfigurationStatusStr[] = {
  178. MACROSTR(Accepted),
  179. MACROSTR(Rejected),
  180. MACROSTR(RebootRequired),
  181. MACROSTR(NotSupported)
  182. };
  183. static char *ClearCacheStatusStr[] = {
  184. MACROSTR(Accepted),
  185. MACROSTR(Rejected)
  186. };
  187. static char *ChargingProfilePurposeTypeStr[] = {
  188. MACROSTR(ChargePointMaxProfile),
  189. MACROSTR(TxDefaultProfile),
  190. MACROSTR(TxProfile)
  191. };
  192. static char *ChargingProfileStatusStr[] = {
  193. MACROSTR(Accepted),
  194. MACROSTR(Rejected),
  195. MACROSTR(NotSupported)
  196. };
  197. static char *ClearChargingProfileStatusStr[] = {
  198. MACROSTR(Accepted),
  199. MACROSTR(Unknown)
  200. };
  201. static char *GetCompositeScheduleStatusStr[] = {
  202. MACROSTR(Accepted),
  203. MACROSTR(Rejected)
  204. };
  205. static char *UpdateTypeStr[] = {
  206. MACROSTR(Differential),
  207. MACROSTR(Full)
  208. };
  209. static char *UpdateStatusStr[] = {
  210. MACROSTR(Accepted),
  211. MACROSTR(Failed),
  212. MACROSTR(NotSupported),
  213. MACROSTR(VersionMismatch)
  214. };
  215. static char *RemoteStartStopStatusStr[] = {
  216. MACROSTR(Accepted),
  217. MACROSTR(Rejected)
  218. };
  219. static char *ReservationStatusStr[] = {
  220. MACROSTR(Accepted),
  221. MACROSTR(Faulted),
  222. MACROSTR(Occupied),
  223. MACROSTR(Rejected),
  224. MACROSTR(Unavailable)
  225. };
  226. static char *ResetTypeStr[] = {
  227. MACROSTR(Hard),
  228. MACROSTR(Soft)
  229. };
  230. static char *ResetStatusStr[] = {
  231. MACROSTR(Accepted),
  232. MACROSTR(Rejected)
  233. };
  234. static char * DiagnosticsStatusStr[] = {
  235. MACROSTR(Idle),
  236. MACROSTR(Uploaded),
  237. MACROSTR(UploadFailed),
  238. MACROSTR(Uploading)
  239. };
  240. static char * FirmwareStatusStr[] = {
  241. MACROSTR(Downloaded),
  242. MACROSTR(DownloadFailed),
  243. MACROSTR(Downloading),
  244. MACROSTR(Idle),
  245. MACROSTR(InstallationFailed),
  246. MACROSTR(Installing),
  247. MACROSTR(Installed)
  248. };
  249. static char * MessageTriggerStr[] = {
  250. MACROSTR(BootNotification),
  251. MACROSTR(DiagnosticsStatusNotification),
  252. MACROSTR(FirmwareStatusNotification),
  253. MACROSTR(Heartbeat),
  254. MACROSTR(MeterValues),
  255. MACROSTR(StatusNotification)
  256. };
  257. static char * TriggerMessageStatusStr[] = {
  258. MACROSTR(Accepted),
  259. MACROSTR(Rejected),
  260. MACROSTR(NotImplemented)
  261. };
  262. static char * UnlockStatusStr[] = {
  263. MACROSTR(Unlocked),
  264. MACROSTR(UnlockFailed),
  265. MACROSTR(NotSupported)
  266. };
  267. #if 0
  268. static char * StopTransactionReasonStr[] = {
  269. MACROSTR(EmergencyStop),
  270. MACROSTR(EVDisconnected),
  271. MACROSTR(HardReset),
  272. MACROSTR(Local),
  273. MACROSTR(Other),
  274. MACROSTR(PowerLoss),
  275. MACROSTR(Reboot),
  276. MACROSTR(Remote),
  277. MACROSTR(SoftReset),
  278. MACROSTR(UnlockCommand),
  279. MACROSTR(DeAuthorized)
  280. };
  281. #endif
  282. static char * CancelReservationStatusStr[] = {
  283. MACROSTR(Accepted),
  284. MACROSTR(Rejected)
  285. };
  286. static char * ReadingContextStr[] = {
  287. MACROSTR(Interruption.Begin),
  288. MACROSTR(Interruption.End),
  289. MACROSTR(Other),
  290. MACROSTR(Sample.Clock),
  291. MACROSTR(Sample.Periodic),
  292. MACROSTR(Transaction.Begin),
  293. MACROSTR(Transaction.End),
  294. MACROSTR(Trigger)
  295. };
  296. static char * ValueFormatStr[] = {
  297. MACROSTR(Raw),
  298. MACROSTR(SignedData)
  299. };
  300. static char * MeasurandStr[] = {
  301. MACROSTR(Current.Export),
  302. MACROSTR(Current.Import),
  303. MACROSTR(Current.Offered),
  304. MACROSTR(Energy.Active.Export.Register),
  305. MACROSTR(Energy.Active.Import.Register),
  306. MACROSTR(Energy.Reactive.Export.Register),
  307. MACROSTR(Energy.Reactive.Import.Register),
  308. MACROSTR(Energy.Active.Export.Interval),
  309. MACROSTR(Energy.Active.Import.Interval),
  310. MACROSTR(Energy.Reactive.Export.Interval),
  311. MACROSTR(Energy.Reactive.Import.Interval),
  312. MACROSTR(Frequency),
  313. MACROSTR(Power.Active.Export),
  314. MACROSTR(Power.Active.Import),
  315. MACROSTR(Power.Factor),
  316. MACROSTR(Power.Offered),
  317. MACROSTR(Power.Reactive.ExportMACROSTR),
  318. MACROSTR(Power.Reactive.Import),
  319. MACROSTR(RPM),
  320. MACROSTR(SoC),
  321. MACROSTR(Temperature),
  322. MACROSTR(Voltage)
  323. };
  324. static char * LocationStr[] = {
  325. MACROSTR(Body),
  326. MACROSTR(Cable),
  327. MACROSTR(EV),
  328. MACROSTR(Inlet),
  329. MACROSTR(Outlet)
  330. };
  331. static char * PhaseStr[] = {
  332. MACROSTR(L1),
  333. MACROSTR(L2),
  334. MACROSTR(L3),
  335. MACROSTR(N),
  336. MACROSTR(L1-N),
  337. MACROSTR(L2-N),
  338. MACROSTR(L3-N),
  339. MACROSTR(L1-L2),
  340. MACROSTR(L2-L3),
  341. MACROSTR(L3-L1)
  342. };
  343. static char * UnitOfMeasureStr[] = {
  344. MACROSTR(Wh),
  345. MACROSTR(kWh),
  346. MACROSTR(varh),
  347. MACROSTR(kvarh),
  348. MACROSTR(W),
  349. MACROSTR(kW),
  350. MACROSTR(VA),
  351. MACROSTR(kVA),
  352. MACROSTR(var),
  353. MACROSTR(kvar),
  354. MACROSTR(A),
  355. MACROSTR(V),
  356. MACROSTR(Celsius),
  357. MACROSTR(Fahrenheit),
  358. MACROSTR(K),
  359. MACROSTR(Percent)
  360. };
  361. //=========================================
  362. // TTIA routine
  363. //=========================================
  364. int sendTTIAInfo(uint8_t gun_index)
  365. {
  366. static int sn = 0;
  367. int result = FAIL;
  368. struct hostent *server;
  369. int udp_socket_fd;
  370. struct sockaddr_in dest_addr = {0};
  371. uint8_t tx_buf[80] = {0};
  372. uint8_t logBuf[256]= {0};
  373. uint8_t tx_len, tempIndex, socStart, socEnd;
  374. uint16_t PresentChargedEnergy;
  375. struct tm tmStart, tmEnd;
  376. DEBUG_INFO("sendTTIAInfo...\n");
  377. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  378. {
  379. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  380. {
  381. tempIndex = ((gun_index==2) ? 1: 0);
  382. }
  383. else
  384. {
  385. tempIndex = gun_index;
  386. }
  387. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  388. {
  389. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  390. {
  391. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  392. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  393. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  394. }
  395. }
  396. }
  397. else if(gunType[gun_index] == GUN_TYPE_CCS)
  398. {
  399. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  400. {
  401. tempIndex = ((gun_index==2) ? 1: 0);
  402. }
  403. else
  404. {
  405. tempIndex = gun_index;
  406. }
  407. for (int index = 0; index < CCS_QUANTITY; index++)
  408. {
  409. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  410. {
  411. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  412. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  413. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  414. }
  415. }
  416. }
  417. else if(gunType[gun_index] == GUN_TYPE_GBT)
  418. {
  419. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  420. {
  421. tempIndex = ((gun_index==2) ? 1: 0);
  422. }
  423. else
  424. {
  425. tempIndex = gun_index;
  426. }
  427. for (int index = 0; index < GB_QUANTITY; index++)
  428. {
  429. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  430. {
  431. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  432. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  433. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  434. }
  435. }
  436. }
  437. else if(gunType[gun_index] == GUN_TYPE_DO)
  438. {
  439. tempIndex = gun_index;
  440. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  441. {
  442. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  443. {
  444. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  445. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  446. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  447. }
  448. }
  449. }
  450. else
  451. {
  452. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  453. {
  454. tempIndex = 2;
  455. }
  456. else
  457. {
  458. tempIndex = gun_index;
  459. }
  460. for (int index = 0; index < AC_QUANTITY; index++)
  461. {
  462. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  463. {
  464. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  465. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  466. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  467. }
  468. }// END
  469. }
  470. // Message assembly
  471. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  472. tx_buf[4] = 0x02; // Protocol Version
  473. tx_buf[5] = 0xb0; // Message ID
  474. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  475. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  476. tx_buf[8] = 0x00; // CarID low byte
  477. tx_buf[9] = 0x00; // CarID high byte
  478. tx_buf[10] = 0x00; // ID Storage
  479. tx_buf[11] = 0x00; // Driver lowest byte
  480. tx_buf[12] = 0x00; // Driver 2nd byte
  481. tx_buf[13] = 0x00; // Driver 3rd byte
  482. tx_buf[14] = 0x00; // Driver highest byte
  483. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  484. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  485. tx_buf[17] = 0x00; // Reserve
  486. tx_buf[18] = 60 & 0xff; // Payload length low byte
  487. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  488. // EVSE provider
  489. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  490. // EVSE provider
  491. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  492. // EVSE id
  493. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  494. // Connector id
  495. tx_buf[37] = gun_index;
  496. // EVSE station
  497. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  498. // Vehicle SN
  499. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  500. // Mileage
  501. tx_buf[61] = 0x00; // lowest byte
  502. tx_buf[62] = 0x00; // 2nd byte
  503. tx_buf[63] = 0x00; // highest byte
  504. // Start date time 6 bytes
  505. 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))
  506. {
  507. struct tm *tmTarget;
  508. struct timeb tbTarget;
  509. tmStart.tm_year -= 1900;
  510. tmStart.tm_mon -= 1;
  511. tmStart.tm_gmtoff = 0;
  512. tbTarget.time = mktime(&tmStart);
  513. tbTarget.timezone = 0;
  514. tbTarget.time += (8*3600);
  515. tmTarget = gmtime(&tbTarget.time);
  516. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  517. tx_buf[65] = (tmTarget->tm_mon+1);
  518. tx_buf[66] = tmTarget->tm_mday;
  519. tx_buf[67] = tmTarget->tm_hour;
  520. tx_buf[68] = tmTarget->tm_min;
  521. tx_buf[69] = tmTarget->tm_sec;
  522. }
  523. // Stop date time 6 bytes
  524. 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))
  525. {
  526. struct tm *tmTarget;
  527. struct timeb tbTarget;
  528. tmEnd.tm_year -= 1900;
  529. tmEnd.tm_mon -= 1;
  530. tmEnd.tm_gmtoff = 0;
  531. tbTarget.time = mktime(&tmEnd);
  532. tbTarget.timezone = 0;
  533. tbTarget.time += (8*3600);
  534. tmTarget = gmtime(&tbTarget.time);
  535. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  536. tx_buf[71] = (tmTarget->tm_mon+1);
  537. tx_buf[72] = tmTarget->tm_mday;
  538. tx_buf[73] = tmTarget->tm_hour;
  539. tx_buf[74] = tmTarget->tm_min;
  540. tx_buf[75] = tmTarget->tm_sec;
  541. }
  542. // Session energy 2 bytes
  543. tx_buf[76] = PresentChargedEnergy & 0xff;
  544. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  545. // Start SOC 1 byte
  546. tx_buf[78] = socStart;
  547. // Stop SOC 1 byte
  548. tx_buf[79] = socEnd;
  549. // Open socket
  550. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  551. if(udp_socket_fd == -1)
  552. {
  553. DEBUG_ERROR("UDP socket create failed!\n");
  554. }
  555. else
  556. {
  557. // Get server DNS entry
  558. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  559. if (server == NULL)
  560. {
  561. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  562. }
  563. else
  564. {
  565. // Build the server's Internet address
  566. bzero((char *) &dest_addr, sizeof(dest_addr));
  567. dest_addr.sin_family = AF_INET;
  568. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  569. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  570. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  571. {
  572. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  573. {
  574. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  575. }
  576. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  577. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  578. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  579. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  580. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  581. DEBUG_TTIA_INFO("---------- Header ----------\n");
  582. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  583. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  584. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  585. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  586. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  587. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  588. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  589. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  590. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  591. DEBUG_TTIA_INFO("Len: 0x3C\n");
  592. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  593. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  594. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  595. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  596. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  597. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  598. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  599. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  600. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  601. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  602. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  603. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  604. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  605. DEBUG_TTIA_INFO("=========================================\n");
  606. sn++;
  607. result = PASS;
  608. }
  609. else
  610. {
  611. DEBUG_ERROR("UDP sent out fail.\n");
  612. }
  613. }
  614. }
  615. return result;
  616. }
  617. //=========================================
  618. // Save configuration
  619. //=========================================
  620. int runShellCmd(const char*cmd)
  621. {
  622. int result = FAIL;
  623. char buf[256];
  624. FILE *fp;
  625. fp = popen(cmd, "r");
  626. if(fp != NULL)
  627. {
  628. while(fgets(buf, sizeof(buf), fp) != NULL)
  629. {
  630. DEBUG_INFO("%s\n", buf);
  631. }
  632. result = PASS;
  633. }
  634. pclose(fp);
  635. return result;
  636. }
  637. int StoreUsrConfigData(struct SysConfigData *UsrData)
  638. {
  639. int result = PASS;
  640. int fd,wrd;
  641. unsigned int i,Chk;
  642. unsigned char *ptr, *BufTmp;
  643. int MtdBlockSize = 0x300000;
  644. Chk=0;
  645. ptr=(unsigned char *)UsrData;
  646. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  647. {
  648. memset(BufTmp,0,MtdBlockSize);
  649. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  650. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  651. Chk+=*(BufTmp+i);
  652. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  653. // Output configuration to file.
  654. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  655. if (fd < 0)
  656. {
  657. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  658. free(BufTmp);
  659. return 0;
  660. }
  661. wrd=write(fd, BufTmp, MtdBlockSize);
  662. close(fd);
  663. if(wrd<MtdBlockSize)
  664. {
  665. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  666. free(BufTmp);
  667. return 0;
  668. }
  669. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  670. DEBUG_INFO("Erase /dev/mtd10.\n");
  671. runShellCmd("flash_erase /dev/mtd10 0 0");
  672. DEBUG_INFO("Write /dev/mtd10.\n");
  673. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  674. DEBUG_INFO("Erase /dev/mtd11.\n");
  675. runShellCmd("flash_erase /dev/mtd11 0 0");
  676. DEBUG_INFO("Write /dev/mtd11.\n");
  677. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  678. system("rm -f /mnt/EvseConfig.bin");
  679. DEBUG_INFO("EvseConfig write to flash OK\n");
  680. }
  681. else
  682. {
  683. DEBUG_ERROR("alloc BlockSize NG\r\n");
  684. result = FAIL;
  685. }
  686. if(BufTmp!=NULL)
  687. free(BufTmp);
  688. return result;
  689. }
  690. //=========================================
  691. // Sqlite3 related function
  692. //=========================================
  693. static int selectSqlCount = 0;
  694. static int callback(void *data, int argc, char **argv, char **azColName){
  695. int i;
  696. //printf("%s: ", (const char*)data);
  697. selectSqlCount = argc;
  698. for(i = 0; i<argc; i++){
  699. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  700. }
  701. //printf("\n");
  702. return 0;
  703. }
  704. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  705. //int i;
  706. //printf("%s:\n", (const char*)data);
  707. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  708. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  709. return 0;
  710. }
  711. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  712. //printf("%s:\n", (const char*)data);
  713. //idTag
  714. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  715. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  716. //parentIdTag
  717. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  718. //expir_date
  719. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  720. //status
  721. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  722. //version
  723. if(columenCount > 5)
  724. idTagQuery.listVersionInt = atoi(columnValue[5]);
  725. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  726. return 0;
  727. }
  728. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  729. {
  730. // localversion = argv[5] ? atoi(argv[5]) : 0;
  731. // printf("localversion=%d\n", localversion);
  732. return 0;
  733. }
  734. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  735. {
  736. for (int i = 0; i < n_columns; i++)
  737. {
  738. DEBUG_INFO("%s\t", col_values[i]);
  739. }
  740. DEBUG_INFO("\n");
  741. return 0;
  742. }
  743. int OCPP_cleanLocalCache()
  744. {
  745. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  746. char *errMsg = 0;
  747. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  748. if (SQLITE_OK != rc)
  749. {
  750. DEBUG_INFO("SQL error: %s\n",errMsg);
  751. return FALSE;
  752. }
  753. return TRUE;
  754. }
  755. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  756. {
  757. int isSuccess = TRUE;
  758. int ret = 0;
  759. //const char* data = "Callback function called";
  760. char sql[300];
  761. char zErrMsg[200];
  762. memset(sql, 0, 300);
  763. memset(zErrMsg, 0, 200);
  764. 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);
  765. //* Execute SQL statement */
  766. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  767. if( ret != SQLITE_OK )
  768. {
  769. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  770. isSuccess = FALSE;
  771. }
  772. return isSuccess;
  773. }
  774. void OCPP_getIdTagFromLocalCache(char idTag[])
  775. {
  776. int rc = 0;
  777. char sql[100];
  778. char zErrMsg[100];
  779. memset(sql, 0, 100);
  780. memset(zErrMsg, 0, 100);
  781. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  782. memset(&idTagQuery, 0, sizeof(idTagQuery));
  783. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  784. /* Execute SQL statement */
  785. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  786. if( rc != SQLITE_OK )
  787. {
  788. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  789. }
  790. }
  791. void OCPP_getListVerion()
  792. {
  793. int rc = 0;
  794. // const char* data = "Callback function called";
  795. char sql[100];
  796. char zErrMsg[100];
  797. memset(sql, 0, 100);
  798. memset(zErrMsg, 0, 100);
  799. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  800. /* Execute SQL statement */
  801. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  802. if( rc != SQLITE_OK )
  803. {
  804. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  805. }
  806. }
  807. void OCPP_get_TableAuthlocalAllData(void)
  808. {
  809. int rc = 0;
  810. char sql[100];
  811. char zErrMsg[100];
  812. memset(sql, 0, 100);
  813. memset(zErrMsg, 0, 100);
  814. sprintf(sql,"select * from ocpp_auth_local ");
  815. /* Execute SQL statement */
  816. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  817. if( rc != SQLITE_OK )
  818. {
  819. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  820. }
  821. //return ver;
  822. }
  823. int OCPP_cleanLocalList()
  824. {
  825. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  826. char *errMsg = 0;
  827. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  828. if (SQLITE_OK != rc)
  829. {
  830. DEBUG_INFO("%s\n",errMsg);
  831. return FALSE;
  832. }
  833. return TRUE;
  834. }
  835. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  836. {
  837. int isSuccess = FALSE;
  838. int ret = 0;
  839. //const char* data = "Callback function called";
  840. char sql[300];
  841. char zErrMsg[200];
  842. memset(sql, 0, 300);
  843. memset(zErrMsg, 0, 200);
  844. 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);
  845. //* Execute SQL statement */
  846. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  847. if( ret != SQLITE_OK )
  848. {
  849. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  850. return isSuccess;
  851. }
  852. memset(sql, 0, 300);
  853. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  854. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  855. if( ret != SQLITE_OK )
  856. {
  857. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  858. return isSuccess;
  859. }
  860. isSuccess = TRUE;
  861. return isSuccess;
  862. }
  863. void OCPP_getIdTagFromLocalList(char idTag[])
  864. {
  865. int rc = 0;
  866. // const char* data = "Callback function called";
  867. char sql[100];
  868. char zErrMsg[100];
  869. memset(sql, 0, 100);
  870. memset(zErrMsg, 0, 100);
  871. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  872. memset(&idTagQuery, 0, sizeof(idTagQuery));
  873. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  874. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  875. /* Execute SQL statement */
  876. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  877. if( rc != SQLITE_OK )
  878. {
  879. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  880. }
  881. //return ver;
  882. }
  883. void OCPP_deleteIdTagFromLocalList(char idTag[])
  884. {
  885. //int ver = 0;
  886. //int isSuccess = FALSE;
  887. int rc = 0;
  888. char sql[100];
  889. char zErrMsg[100];
  890. memset(sql, 0, 100);
  891. memset(zErrMsg, 0, 100);
  892. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  893. //* Execute SQL statement */
  894. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  895. if( rc != SQLITE_OK )
  896. {
  897. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  898. }
  899. }
  900. int getCurrentYear()
  901. {
  902. int result = 0;
  903. time_t CurrentTime;
  904. struct tm *tm;
  905. CurrentTime = time(NULL);
  906. tm=localtime(&CurrentTime);
  907. result = (tm->tm_year + 1900);
  908. return result;
  909. }
  910. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  911. {
  912. int result = PASS;
  913. char* errMsg = NULL;
  914. char sqlStr[8192];
  915. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  916. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  917. {
  918. result = FAIL;
  919. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  920. }
  921. 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));
  922. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  923. {
  924. result = FAIL;
  925. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  926. }
  927. return result;
  928. }
  929. int OCPP_updatePeriodEnergy(uint8_t gun_index)
  930. {
  931. int isSuccess = TRUE;
  932. int tempIndex;
  933. json_object *EnergyDataTransfer = json_object_new_object();
  934. json_object *periodEnergys = json_object_new_object();
  935. char sql[1024];
  936. char zErrMsg[200];
  937. memset(sql, 0, ARRAY_SIZE(sql));
  938. memset(zErrMsg, 0, ARRAY_SIZE(zErrMsg));
  939. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  940. {
  941. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  942. {
  943. tempIndex = ((gun_index==2) ? 1: 0);
  944. }
  945. else
  946. {
  947. tempIndex = gun_index;
  948. }
  949. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  950. {
  951. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  952. {
  953. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  954. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  955. {
  956. uint8_t period[3];
  957. sprintf((char*)period, "%d", idxPeriod);
  958. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  959. }
  960. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  961. } //end of the same index
  962. }//end of for CHAdeMO_QUANTITY
  963. }
  964. else if(gunType[gun_index] == GUN_TYPE_CCS)
  965. {
  966. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  967. {
  968. tempIndex = ((gun_index==2) ? 1: 0);
  969. }
  970. else
  971. {
  972. tempIndex = gun_index;
  973. }
  974. for (int index = 0; index < CCS_QUANTITY; index++)
  975. {
  976. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  977. {
  978. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  979. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  980. {
  981. uint8_t period[3];
  982. sprintf((char*)period, "%d", idxPeriod);
  983. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  984. }
  985. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  986. } //end of the same index
  987. } // end of for CCS_QUANTITY
  988. }
  989. else if(gunType[gun_index] == GUN_TYPE_GBT)
  990. {
  991. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  992. {
  993. tempIndex = ((gun_index==2) ? 1: 0);
  994. }
  995. else
  996. {
  997. tempIndex = gun_index;
  998. }
  999. for (int index = 0; index < GB_QUANTITY; index++)
  1000. {
  1001. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1002. {
  1003. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1004. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1005. {
  1006. uint8_t period[3];
  1007. sprintf((char*)period, "%d", idxPeriod);
  1008. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1009. }
  1010. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1011. } //end of the same index
  1012. } // end of for GB_QUANTITY
  1013. }
  1014. else if(gunType[gun_index] == GUN_TYPE_DO)
  1015. {
  1016. tempIndex = gun_index;
  1017. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1018. {
  1019. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1020. {
  1021. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1022. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod);idxPeriod++)
  1023. {
  1024. uint8_t period[3];
  1025. sprintf((char*)period, "%d", idxPeriod);
  1026. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod[idxPeriod]));
  1027. }
  1028. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1029. } //end of the same index
  1030. }
  1031. }
  1032. else
  1033. {
  1034. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1035. {
  1036. tempIndex = 2;
  1037. }
  1038. else
  1039. {
  1040. tempIndex = gun_index;
  1041. }
  1042. for (int index = 0; index < AC_QUANTITY; index++)
  1043. {
  1044. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1045. {
  1046. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1047. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1048. {
  1049. uint8_t period[3];
  1050. sprintf((char*)period, "%d", idxPeriod);
  1051. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1052. }
  1053. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1054. }//end of the same index
  1055. }//end of for AC_QUANTITY
  1056. }
  1057. sprintf(sql, "insert or replace into ocpp_period_energy (transactionId, connectorId, occurDatetime, periodEnergy) VALUES ('%d', '%d', CURRENT_TIMESTAMP, '%s');", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, (gun_index+1), json_object_to_json_string_ext(EnergyDataTransfer, JSON_C_TO_STRING_PLAIN));
  1058. json_object_put(EnergyDataTransfer);
  1059. //* Execute SQL statement */
  1060. if( sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg) != SQLITE_OK )
  1061. {
  1062. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1063. isSuccess = FALSE;
  1064. }
  1065. sprintf(sql, "delete from ocpp_period_energy where (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1066. if (sqlite3_exec(db, sql, 0, 0, (char **)&zErrMsg) != SQLITE_OK)
  1067. {
  1068. DEBUG_WARN( "delete period energy record error message: %s\n", zErrMsg);
  1069. isSuccess = FALSE;
  1070. }
  1071. return isSuccess;
  1072. }
  1073. int OCPP_getPeriodEnergyToDataTransfer(int32_t transactionId)
  1074. {
  1075. int isSuccess = TRUE;
  1076. char sql[512];
  1077. char zErrMsg[200];
  1078. int rows, cols;
  1079. char **resultData;
  1080. sprintf(sql, "select * from ocpp_period_energy where transactionId=%d;", transactionId);
  1081. /* Execute SQL statement */
  1082. if( sqlite3_get_table(db, sql, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  1083. {
  1084. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1085. isSuccess = FALSE;
  1086. }
  1087. else
  1088. {
  1089. if((rows > 0) && (atoi(resultData[4]) > 0))
  1090. {
  1091. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, "%s", resultData[7]);
  1092. }
  1093. else
  1094. {
  1095. DEBUG_WARN("There is not match transaction data.\n");
  1096. isSuccess = FALSE;
  1097. }
  1098. }
  1099. return isSuccess;
  1100. }
  1101. int OCPP_insert_deduct_info(int txId, char *creditNo, uint8_t deductResult, uint8_t isDonateInvoice, double amount, char *vemData, char *ROC, char *RRN, char *approvalNo, char *storeId)
  1102. {
  1103. int result = PASS;
  1104. char* errMsg = NULL;
  1105. char sqlStr[8192];
  1106. sprintf(sqlStr, "insert or replace into report_deduct_info(txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId, isUploaded) values('%d', '%s', '%d', '%d', '%.2f', '%s', '%s', '%s', '%s', '%s', '0');",
  1107. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  1108. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1109. {
  1110. result = FAIL;
  1111. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  1112. }
  1113. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  1114. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1115. {
  1116. result = FAIL;
  1117. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  1118. }
  1119. return result;
  1120. }
  1121. int OCPP_update_deduct_info(int txId, char *creditNo)
  1122. {
  1123. int result = PASS;
  1124. char* errMsg = NULL;
  1125. char sqlStr[8192];
  1126. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  1127. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1128. {
  1129. result = FAIL;
  1130. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  1131. }
  1132. return result;
  1133. }
  1134. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1135. {
  1136. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1137. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  1138. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s,\\\"approvalNo\\\":\\\"%s\\\"}",
  1139. atoi(columnValue[1]),
  1140. columnValue[2],
  1141. atoi(columnValue[3])==1?"true":"false",
  1142. atoi(columnValue[4])==1?"true":"false",
  1143. columnValue[5],
  1144. columnValue[9]);
  1145. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1146. return 0;
  1147. }
  1148. void OCPP_query_deduct_info()
  1149. {
  1150. int rc = 0;
  1151. char sql[100];
  1152. char zErrMsg[100];
  1153. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  1154. /* Execute SQL statement */
  1155. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  1156. if( rc != SQLITE_OK )
  1157. {
  1158. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1159. }
  1160. }
  1161. void reportReaderStatus(int gun_index)
  1162. {
  1163. struct timeval tmnow;
  1164. struct tm *tm;
  1165. char buf[28];//, usec_buf[6];
  1166. gettimeofday(&tmnow, NULL);
  1167. time_t t;
  1168. t = time(NULL);
  1169. /*UTC time and date*/
  1170. tm = gmtime(&t);
  1171. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1172. #if 0 // remove temporally
  1173. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1174. strcat(buf,".");
  1175. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1176. strcat(buf,usec_buf);
  1177. #endif
  1178. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1179. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_ReaderStatus");
  1180. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "{\\\"connectorId\\\":%d,\\\"readerStatus\\\":%d,\\\"timestamp\\\":\\\"%s\\\",\\\"SerialNo\\\":\\\"%s\\\",\\\"creditNo\\\":\\\"%s\\\",\\\"VEMData\\\":\\\"%s\\\"}",
  1181. (gun_index+1),
  1182. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].readerStatus,
  1183. buf,
  1184. ShmOCPP16Data->TcciCustomData.SerialNo[gun_index],
  1185. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].creditNo,
  1186. ShmOCPP16Data->TcciCustomData.VEMData[gun_index]);
  1187. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1188. }
  1189. //==========================================
  1190. // Check time passed since today
  1191. //==========================================
  1192. long long DiffTimebWithNow(struct timeb ST)
  1193. {
  1194. //return milli-second
  1195. struct timeb ET;
  1196. long long StartTime,StopTime;
  1197. ftime(&ET);
  1198. StartTime=(long long)ST.time;
  1199. StopTime=(long long)ET.time;
  1200. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1201. }
  1202. int getTimePassSinceToday(uint8_t gun_index)
  1203. {
  1204. int result = -1;
  1205. static time_t lastTime[4];
  1206. time_t t;
  1207. struct tm *tmStartToday;
  1208. struct timeb tbStartToday;
  1209. t=time(NULL);
  1210. if(difftime(t, lastTime[gun_index])>0)
  1211. {
  1212. tmStartToday=localtime(&t);
  1213. tmStartToday->tm_hour = 0;
  1214. tmStartToday->tm_min = 0;
  1215. tmStartToday->tm_sec = 0;
  1216. tbStartToday.time = mktime(tmStartToday);
  1217. tbStartToday.millitm = 0;
  1218. result = DiffTimebWithNow(tbStartToday)/1000;
  1219. lastTime[gun_index] = t;
  1220. }
  1221. return result;
  1222. }
  1223. void getNowDatetime(uint8_t *data)
  1224. {
  1225. time_t t = time(NULL);
  1226. struct tm tm = *localtime(&t);
  1227. 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);
  1228. }
  1229. int syncDateTimeRTC(uint8_t *data)
  1230. {
  1231. struct ParsingResult
  1232. {
  1233. int result;
  1234. int scanedElement;
  1235. int year;
  1236. int month;
  1237. int mday;
  1238. int hour;
  1239. int min;
  1240. int sec;
  1241. int tz_hour;
  1242. int tz_min;
  1243. float minSec;
  1244. }result;
  1245. struct tm tmOrg;
  1246. struct tm *tmTarget;
  1247. struct timeb tbTarget;
  1248. char buf[128];
  1249. memset(&result, 0x00, sizeof(struct ParsingResult));
  1250. result.result = PASS;
  1251. if(strstr((char*)data, ".") != NULL)
  1252. {
  1253. // Original data with mini second
  1254. if(strstr((char*)data, "Z") != NULL)
  1255. {
  1256. // Original data with Z
  1257. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1258. &result.year,
  1259. &result.month,
  1260. &result.mday,
  1261. &result.hour,
  1262. &result.min,
  1263. &result.sec,
  1264. &result.minSec);
  1265. }
  1266. else
  1267. {
  1268. // Original data without Z
  1269. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1270. &result.year,
  1271. &result.month,
  1272. &result.mday,
  1273. &result.hour,
  1274. &result.min,
  1275. &result.sec,
  1276. &result.minSec,
  1277. &result.tz_hour,
  1278. &result.tz_min);
  1279. }
  1280. }
  1281. else
  1282. {
  1283. // Original data without mini second
  1284. if(strstr((char*)data, "Z") != NULL)
  1285. {
  1286. // Original data with Z
  1287. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1288. &result.year,
  1289. &result.month,
  1290. &result.mday,
  1291. &result.hour,
  1292. &result.min,
  1293. &result.sec);
  1294. }
  1295. else
  1296. {
  1297. // Original data without Z
  1298. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1299. &result.year,
  1300. &result.month,
  1301. &result.mday,
  1302. &result.hour,
  1303. &result.min,
  1304. &result.sec,
  1305. &result.tz_hour,
  1306. &result.tz_min);
  1307. }
  1308. }
  1309. tmOrg.tm_year = result.year - 1900;
  1310. tmOrg.tm_mon = result.month - 1;
  1311. tmOrg.tm_mday = result.mday;
  1312. tmOrg.tm_hour = result.hour;
  1313. tmOrg.tm_min = result.min;
  1314. tmOrg.tm_sec = result.sec;
  1315. tmOrg.tm_gmtoff = 0;
  1316. tbTarget.time = mktime(&tmOrg);
  1317. tbTarget.timezone = 0;
  1318. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1319. tmTarget = gmtime(&tbTarget.time);
  1320. 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);
  1321. //DEBUG_INFO(" org date time: %s\n", data);
  1322. //DEBUG_INFO("parse date time: %s\n", buf);
  1323. system(buf);
  1324. system("/sbin/hwclock -w --systohc");
  1325. if(result.scanedElement < 6)
  1326. result.result = FAIL;
  1327. return result.result;
  1328. }
  1329. //==========================================
  1330. // GetCompositeSchedule logic related function
  1331. //==========================================
  1332. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1333. {
  1334. //return milli-second
  1335. unsigned int StartTime,StopTime;
  1336. StartTime=(unsigned int)ST.time;
  1337. StopTime=(unsigned int)ET.time;
  1338. return (StopTime-StartTime);
  1339. }
  1340. int DiffTimebWithNowSec(struct timeb ST)
  1341. {
  1342. //return milli-second
  1343. struct timeb ET;
  1344. unsigned int StartTime,StopTime;
  1345. ftime(&ET);
  1346. StartTime=(unsigned int)ST.time;
  1347. StopTime=(unsigned int)ET.time;
  1348. return (StopTime-StartTime);
  1349. }
  1350. int getStartStop(uint8_t *start, uint8_t *stop)
  1351. {
  1352. struct ParsingResult
  1353. {
  1354. int result;
  1355. int scanedElement;
  1356. int year;
  1357. int month;
  1358. int mday;
  1359. int hour;
  1360. int min;
  1361. int sec;
  1362. int tz_hour;
  1363. int tz_min;
  1364. float minSec;
  1365. };
  1366. struct ParsingResult parseStart;
  1367. struct ParsingResult parseStop;
  1368. int result = -1;
  1369. struct tm tmStart;
  1370. struct timeb tbStart;
  1371. struct tm tmStop;
  1372. struct timeb tbStop;
  1373. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1374. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1375. // Scan start & stop date time
  1376. if(strstr((char*)start, ".") != NULL)
  1377. {
  1378. // Original data with mini second
  1379. if(strstr((char*)start, "Z") != NULL)
  1380. {
  1381. // Original data with Z
  1382. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1383. &parseStart.year,
  1384. &parseStart.month,
  1385. &parseStart.mday,
  1386. &parseStart.hour,
  1387. &parseStart.min,
  1388. &parseStart.sec,
  1389. &parseStart.minSec);
  1390. }
  1391. else
  1392. {
  1393. // Original data without Z
  1394. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1395. &parseStart.year,
  1396. &parseStart.month,
  1397. &parseStart.mday,
  1398. &parseStart.hour,
  1399. &parseStart.min,
  1400. &parseStart.sec,
  1401. &parseStart.minSec,
  1402. &parseStart.tz_hour,
  1403. &parseStart.tz_min);
  1404. }
  1405. }
  1406. else
  1407. {
  1408. // Original data without mini second
  1409. if(strstr((char*)start, "Z") != NULL)
  1410. {
  1411. // Original data with Z
  1412. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1413. &parseStart.year,
  1414. &parseStart.month,
  1415. &parseStart.mday,
  1416. &parseStart.hour,
  1417. &parseStart.min,
  1418. &parseStart.sec);
  1419. }
  1420. else
  1421. {
  1422. // Original data without Z
  1423. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1424. &parseStart.year,
  1425. &parseStart.month,
  1426. &parseStart.mday,
  1427. &parseStart.hour,
  1428. &parseStart.min,
  1429. &parseStart.sec,
  1430. &parseStart.tz_hour,
  1431. &parseStart.tz_min);
  1432. }
  1433. }
  1434. if(strstr((char*)stop, ".") != NULL)
  1435. {
  1436. // Original data with mini second
  1437. if(strstr((char*)stop, "Z") != NULL)
  1438. {
  1439. // Original data with Z
  1440. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1441. &parseStop.year,
  1442. &parseStop.month,
  1443. &parseStop.mday,
  1444. &parseStop.hour,
  1445. &parseStop.min,
  1446. &parseStop.sec,
  1447. &parseStop.minSec);
  1448. }
  1449. else
  1450. {
  1451. // Original data without Z
  1452. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1453. &parseStop.year,
  1454. &parseStop.month,
  1455. &parseStop.mday,
  1456. &parseStop.hour,
  1457. &parseStop.min,
  1458. &parseStop.sec,
  1459. &parseStop.minSec,
  1460. &parseStop.tz_hour,
  1461. &parseStop.tz_min);
  1462. }
  1463. }
  1464. else
  1465. {
  1466. // Original data without mini second
  1467. if(strstr((char*)stop, "Z") != NULL)
  1468. {
  1469. // Original data with Z
  1470. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1471. &parseStop.year,
  1472. &parseStop.month,
  1473. &parseStop.mday,
  1474. &parseStop.hour,
  1475. &parseStop.min,
  1476. &parseStop.sec);
  1477. }
  1478. else
  1479. {
  1480. // Original data without Z
  1481. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1482. &parseStop.year,
  1483. &parseStop.month,
  1484. &parseStop.mday,
  1485. &parseStop.hour,
  1486. &parseStop.min,
  1487. &parseStop.sec,
  1488. &parseStop.tz_hour,
  1489. &parseStop.tz_min);
  1490. }
  1491. }
  1492. // Calculate date time difference
  1493. if((parseStart.scanedElement >=6) &&
  1494. (parseStop.scanedElement >=6))
  1495. {
  1496. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1497. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1498. tmStart.tm_year = parseStart.year - 1900;
  1499. tmStart.tm_mon = parseStart.month - 1;
  1500. tmStart.tm_mday = parseStart.mday;
  1501. tmStart.tm_hour = parseStart.hour;
  1502. tmStart.tm_min = parseStart.min;
  1503. tmStart.tm_sec = parseStart.sec;
  1504. tmStart.tm_gmtoff = 0;
  1505. tbStart.time = mktime(&tmStart);
  1506. tbStart.timezone = 0;
  1507. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1508. tmStop.tm_year = parseStop.year - 1900;
  1509. tmStop.tm_mon = parseStop.month - 1;
  1510. tmStop.tm_mday = parseStop.mday;
  1511. tmStop.tm_hour = parseStop.hour;
  1512. tmStop.tm_min = parseStop.min;
  1513. tmStop.tm_sec = parseStop.sec;
  1514. tmStop.tm_gmtoff = 0;
  1515. tbStop.time = mktime(&tmStop);
  1516. tbStop.timezone = 0;
  1517. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1518. result = DiffTimebSec(tbStart, tbStop);
  1519. //DEBUG_INFO("getStartStop(): %d\n", result);
  1520. }
  1521. else
  1522. {
  1523. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1524. }
  1525. return result;
  1526. }
  1527. int isOvertNow(uint8_t *start)
  1528. {
  1529. int result = NO;
  1530. struct ParsingResult
  1531. {
  1532. int result;
  1533. int scanedElement;
  1534. int year;
  1535. int month;
  1536. int mday;
  1537. int hour;
  1538. int min;
  1539. int sec;
  1540. int tz_hour;
  1541. int tz_min;
  1542. float minSec;
  1543. }parsingResult;
  1544. struct tm tmStart;
  1545. struct timeb tbStart;
  1546. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1547. if(strstr((char*)start, ".") != NULL)
  1548. {
  1549. // Original data with mini second
  1550. if(strstr((char*)start, "Z") != NULL)
  1551. {
  1552. // Original data with Z
  1553. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1554. &parsingResult.year,
  1555. &parsingResult.month,
  1556. &parsingResult.mday,
  1557. &parsingResult.hour,
  1558. &parsingResult.min,
  1559. &parsingResult.sec,
  1560. &parsingResult.minSec);
  1561. }
  1562. else
  1563. {
  1564. // Original data without Z
  1565. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1566. &parsingResult.year,
  1567. &parsingResult.month,
  1568. &parsingResult.mday,
  1569. &parsingResult.hour,
  1570. &parsingResult.min,
  1571. &parsingResult.sec,
  1572. &parsingResult.minSec,
  1573. &parsingResult.tz_hour,
  1574. &parsingResult.tz_min);
  1575. }
  1576. }
  1577. else
  1578. {
  1579. // Original data without mini second
  1580. if(strstr((char*)start, "Z") != NULL)
  1581. {
  1582. // Original data with Z
  1583. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1584. &parsingResult.year,
  1585. &parsingResult.month,
  1586. &parsingResult.mday,
  1587. &parsingResult.hour,
  1588. &parsingResult.min,
  1589. &parsingResult.sec);
  1590. }
  1591. else
  1592. {
  1593. // Original data without Z
  1594. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1595. &parsingResult.year,
  1596. &parsingResult.month,
  1597. &parsingResult.mday,
  1598. &parsingResult.hour,
  1599. &parsingResult.min,
  1600. &parsingResult.sec,
  1601. &parsingResult.tz_hour,
  1602. &parsingResult.tz_min);
  1603. }
  1604. }
  1605. if(parsingResult.scanedElement >= 6)
  1606. {
  1607. tmStart.tm_year = parsingResult.year - 1900;
  1608. tmStart.tm_mon = parsingResult.month - 1;
  1609. tmStart.tm_mday = parsingResult.mday;
  1610. tmStart.tm_hour = parsingResult.hour;
  1611. tmStart.tm_min = parsingResult.min;
  1612. tmStart.tm_sec = parsingResult.sec;
  1613. tmStart.tm_gmtoff = 0;
  1614. tbStart.time = mktime(&tmStart);
  1615. tbStart.timezone = 0;
  1616. tbStart.millitm = 0;
  1617. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1618. if(DiffTimebWithNowSec(tbStart) <= 0)
  1619. result = NO;
  1620. else
  1621. result = YES;
  1622. }
  1623. else
  1624. {
  1625. DEBUG_WARN("Start date parsing error.\n");
  1626. }
  1627. return result;
  1628. }
  1629. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1630. {
  1631. struct ParsingResult
  1632. {
  1633. int result;
  1634. int scanedElement;
  1635. int year;
  1636. int month;
  1637. int mday;
  1638. int hour;
  1639. int min;
  1640. int sec;
  1641. int tz_hour;
  1642. int tz_min;
  1643. float minSec;
  1644. };
  1645. struct ParsingResult parseStart;
  1646. struct ParsingResult parseStop;
  1647. int result = -1;
  1648. struct tm tmStart;
  1649. struct timeb tbStart;
  1650. struct tm tmStop;
  1651. struct timeb tbStop;
  1652. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1653. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1654. // Scan start & stop date time
  1655. if(strstr((char*)start, ".") != NULL)
  1656. {
  1657. // Original data with mini second
  1658. if(strstr((char*)start, "Z") != NULL)
  1659. {
  1660. // Original data with Z
  1661. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1662. &parseStart.year,
  1663. &parseStart.month,
  1664. &parseStart.mday,
  1665. &parseStart.hour,
  1666. &parseStart.min,
  1667. &parseStart.sec,
  1668. &parseStart.minSec);
  1669. }
  1670. else
  1671. {
  1672. // Original data without Z
  1673. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1674. &parseStart.year,
  1675. &parseStart.month,
  1676. &parseStart.mday,
  1677. &parseStart.hour,
  1678. &parseStart.min,
  1679. &parseStart.sec,
  1680. &parseStart.minSec,
  1681. &parseStart.tz_hour,
  1682. &parseStart.tz_min);
  1683. }
  1684. }
  1685. else
  1686. {
  1687. // Original data without mini second
  1688. if(strstr((char*)start, "Z") != NULL)
  1689. {
  1690. // Original data with Z
  1691. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1692. &parseStart.year,
  1693. &parseStart.month,
  1694. &parseStart.mday,
  1695. &parseStart.hour,
  1696. &parseStart.min,
  1697. &parseStart.sec);
  1698. }
  1699. else
  1700. {
  1701. // Original data without Z
  1702. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1703. &parseStart.year,
  1704. &parseStart.month,
  1705. &parseStart.mday,
  1706. &parseStart.hour,
  1707. &parseStart.min,
  1708. &parseStart.sec,
  1709. &parseStart.tz_hour,
  1710. &parseStart.tz_min);
  1711. }
  1712. }
  1713. if(strstr((char*)stop, ".") != NULL)
  1714. {
  1715. // Original data with mini second
  1716. if(strstr((char*)stop, "Z") != NULL)
  1717. {
  1718. // Original data with Z
  1719. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1720. &parseStop.year,
  1721. &parseStop.month,
  1722. &parseStop.mday,
  1723. &parseStop.hour,
  1724. &parseStop.min,
  1725. &parseStop.sec,
  1726. &parseStop.minSec);
  1727. }
  1728. else
  1729. {
  1730. // Original data without Z
  1731. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1732. &parseStop.year,
  1733. &parseStop.month,
  1734. &parseStop.mday,
  1735. &parseStop.hour,
  1736. &parseStop.min,
  1737. &parseStop.sec,
  1738. &parseStop.minSec,
  1739. &parseStop.tz_hour,
  1740. &parseStop.tz_min);
  1741. }
  1742. }
  1743. else
  1744. {
  1745. // Original data without mini second
  1746. if(strstr((char*)stop, "Z") != NULL)
  1747. {
  1748. // Original data with Z
  1749. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1750. &parseStop.year,
  1751. &parseStop.month,
  1752. &parseStop.mday,
  1753. &parseStop.hour,
  1754. &parseStop.min,
  1755. &parseStop.sec);
  1756. }
  1757. else
  1758. {
  1759. // Original data without Z
  1760. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1761. &parseStop.year,
  1762. &parseStop.month,
  1763. &parseStop.mday,
  1764. &parseStop.hour,
  1765. &parseStop.min,
  1766. &parseStop.sec,
  1767. &parseStop.tz_hour,
  1768. &parseStop.tz_min);
  1769. }
  1770. }
  1771. // Calculate date time difference
  1772. if((parseStart.scanedElement >=6) &&
  1773. (parseStop.scanedElement >=6))
  1774. {
  1775. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1776. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1777. tmStart.tm_year = parseStart.year - 1900;
  1778. tmStart.tm_mon = parseStart.month - 1;
  1779. tmStart.tm_mday = parseStart.mday;
  1780. tmStart.tm_hour = parseStart.hour;
  1781. tmStart.tm_min = parseStart.min;
  1782. tmStart.tm_sec = parseStart.sec;
  1783. tmStart.tm_gmtoff = 0;
  1784. tbStart.time = mktime(&tmStart);
  1785. tbStart.timezone = 0;
  1786. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1787. tmStop.tm_year = parseStop.year - 1900;
  1788. tmStop.tm_mon = parseStop.month - 1;
  1789. tmStop.tm_mday = parseStop.mday;
  1790. tmStop.tm_hour = parseStop.hour;
  1791. tmStop.tm_min = parseStop.min;
  1792. tmStop.tm_sec = parseStop.sec;
  1793. tmStop.tm_gmtoff = 0;
  1794. tbStop.time = mktime(&tmStop);
  1795. tbStop.timezone = 0;
  1796. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1797. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1798. //DEBUG_INFO("getStartStop(): %d\n", result);
  1799. }
  1800. else
  1801. {
  1802. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1803. }
  1804. return result;
  1805. }
  1806. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1807. {
  1808. FILE *fp;
  1809. char profileFileName[128];
  1810. char *line = NULL;
  1811. size_t len = 0;
  1812. time_t CurrentTime;
  1813. struct tm *tmComposite;
  1814. struct StructChargingProfile maxProfile;
  1815. struct StructChargingProfile compositeProfile;
  1816. uint8_t limitMax=0;
  1817. int compositePeriodIdx = 0;
  1818. CurrentTime = time(NULL);
  1819. tmComposite=localtime(&CurrentTime);
  1820. 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);
  1821. if(isUnitA)
  1822. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1823. else
  1824. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1825. compositeProfile.ChargingSchedule.Duration = durationReq;
  1826. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1827. {
  1828. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1829. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1830. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1831. }
  1832. compositeProfile.ChargingProfileId = 0;
  1833. compositeProfile.StackLevel = 99 ;
  1834. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1835. maxProfile.ChargingProfileId = -1;
  1836. maxProfile.ChargingSchedule.Duration = -1;
  1837. system("rm -f /tmp/*.json");
  1838. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1839. // Search max profile
  1840. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1841. if((access(profileFileName, F_OK))!=-1)
  1842. {
  1843. fp = fopen(profileFileName, "r");
  1844. while(getline(&line, &len, fp) != -1)
  1845. {
  1846. json_object *obj = NULL;
  1847. obj = json_tokener_parse(line);
  1848. if(is_error(obj))
  1849. {
  1850. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1851. }
  1852. else
  1853. {
  1854. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1855. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1856. )
  1857. {
  1858. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1859. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1860. )
  1861. {
  1862. struct tm tmFrom, tmTo;
  1863. struct timeb tbFrom, tbTo;
  1864. 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) &&
  1865. (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))
  1866. {
  1867. tmFrom.tm_year -= 1900;
  1868. tmFrom.tm_mon -= 1;
  1869. tbFrom.time = mktime(&tmFrom);
  1870. tmTo.tm_year -= 1900;
  1871. tmTo.tm_mon -= 1;
  1872. tbTo.time = mktime(&tmTo);
  1873. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1874. {
  1875. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1876. {
  1877. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1878. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1879. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1880. }
  1881. if(maxProfile.ChargingProfileId == -1)
  1882. DEBUG_INFO("MaxProfile found.\n");
  1883. else
  1884. DEBUG_INFO("MaxProfile updated.\n");
  1885. // Required item
  1886. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1887. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1888. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1889. if(isUnitA)
  1890. {
  1891. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1892. 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++)
  1893. {
  1894. 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"));
  1895. 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?
  1896. 3:
  1897. 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")));
  1898. 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")));
  1899. }
  1900. }
  1901. else
  1902. {
  1903. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1904. 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++)
  1905. {
  1906. 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"));
  1907. 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?
  1908. 3:
  1909. 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")));
  1910. 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));
  1911. }
  1912. }
  1913. // Optional item
  1914. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1915. {
  1916. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1917. }
  1918. else
  1919. {
  1920. sprintf((char*)maxProfile.ValidFrom, " ");
  1921. }
  1922. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1923. {
  1924. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1925. }
  1926. else
  1927. {
  1928. sprintf((char*)maxProfile.ValidTo, " ");
  1929. }
  1930. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1931. {
  1932. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1933. }
  1934. else
  1935. {
  1936. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1937. }
  1938. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1939. {
  1940. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1941. }
  1942. else
  1943. {
  1944. maxProfile.TransactionId = -1;
  1945. }
  1946. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1947. {
  1948. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1949. }
  1950. else
  1951. {
  1952. maxProfile.ChargingSchedule.Duration = 86400;
  1953. }
  1954. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1955. {
  1956. 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")));
  1957. }
  1958. else
  1959. {
  1960. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1961. }
  1962. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1963. {
  1964. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1965. }
  1966. else
  1967. {
  1968. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1969. }
  1970. }
  1971. }
  1972. }
  1973. else
  1974. {
  1975. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1976. {
  1977. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1978. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1979. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1980. }
  1981. if(maxProfile.ChargingProfileId == -1)
  1982. DEBUG_INFO("MaxProfile found.\n");
  1983. else
  1984. DEBUG_INFO("MaxProfile updated.\n");
  1985. // Required item
  1986. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1987. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1988. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1989. if(isUnitA)
  1990. {
  1991. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1992. 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++)
  1993. {
  1994. 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"));
  1995. 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?
  1996. 3:
  1997. 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")));
  1998. 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")));
  1999. }
  2000. }
  2001. else
  2002. {
  2003. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2004. 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++)
  2005. {
  2006. 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"));
  2007. 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?
  2008. 3:
  2009. 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")));
  2010. 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));
  2011. }
  2012. }
  2013. // Optional item
  2014. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2015. {
  2016. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2017. }
  2018. else
  2019. {
  2020. sprintf((char*)maxProfile.ValidFrom, " ");
  2021. }
  2022. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2023. {
  2024. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2025. }
  2026. else
  2027. {
  2028. sprintf((char*)maxProfile.ValidTo, " ");
  2029. }
  2030. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2031. {
  2032. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2033. }
  2034. else
  2035. {
  2036. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2037. }
  2038. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2039. {
  2040. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2041. }
  2042. else
  2043. {
  2044. maxProfile.TransactionId = -1;
  2045. }
  2046. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2047. {
  2048. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2049. }
  2050. else
  2051. {
  2052. maxProfile.ChargingSchedule.Duration = 86400;
  2053. }
  2054. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2055. {
  2056. 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")));
  2057. }
  2058. else
  2059. {
  2060. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2061. }
  2062. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2063. {
  2064. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2065. }
  2066. else
  2067. {
  2068. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2069. }
  2070. }
  2071. }
  2072. }
  2073. json_object_put(obj);
  2074. }
  2075. fclose(fp);
  2076. /*
  2077. if(maxProfile.ChargingProfileId !=-1)
  2078. {
  2079. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2080. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2081. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2082. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2083. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2084. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2085. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2086. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2087. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2088. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2089. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2090. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2091. {
  2092. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2093. {
  2094. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2095. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2096. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2097. }
  2098. }
  2099. }
  2100. else
  2101. DEBUG_INFO("MaxProfile not found.\n");
  2102. DEBUG_INFO("------------------------------------\n");*/
  2103. }
  2104. if(maxProfile.ChargingProfileId != -1)
  2105. {
  2106. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2107. {
  2108. if(maxProfile.ChargingSchedule.Duration != -1)
  2109. {
  2110. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2111. 0:
  2112. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2113. }
  2114. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2115. {
  2116. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2117. {
  2118. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2119. 0:
  2120. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2121. if(idxPeriod > 0)
  2122. {
  2123. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2124. {
  2125. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2126. }
  2127. }
  2128. }
  2129. }
  2130. }
  2131. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2132. {
  2133. if(maxProfile.ChargingSchedule.Duration != -1)
  2134. {
  2135. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2136. }
  2137. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2138. {
  2139. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2140. {
  2141. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  2142. if(idxPeriod > 0)
  2143. {
  2144. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2145. {
  2146. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2147. }
  2148. }
  2149. }
  2150. }
  2151. }
  2152. else
  2153. {
  2154. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2155. {
  2156. if(maxProfile.ChargingSchedule.Duration != -1)
  2157. {
  2158. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2159. 0:
  2160. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2161. }
  2162. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2163. {
  2164. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2165. {
  2166. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2167. 0:
  2168. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2169. if(idxPeriod > 0)
  2170. {
  2171. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2172. {
  2173. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2174. }
  2175. }
  2176. }
  2177. }
  2178. }
  2179. else
  2180. {
  2181. if(maxProfile.ChargingSchedule.Duration != -1)
  2182. {
  2183. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2184. 0:
  2185. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2186. }
  2187. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2188. {
  2189. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2190. {
  2191. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2192. 0:
  2193. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2194. if(idxPeriod > 0)
  2195. {
  2196. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2197. {
  2198. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2199. }
  2200. }
  2201. }
  2202. }
  2203. }
  2204. }
  2205. /*
  2206. DEBUG_INFO("MaxProfile after align.\n");
  2207. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2208. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2209. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2210. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2211. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2212. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2213. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2214. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2215. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2216. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2217. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2218. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2219. {
  2220. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2221. {
  2222. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2223. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2224. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2225. }
  2226. }
  2227. DEBUG_INFO("------------------------------------\n");*/
  2228. }
  2229. // Find each profile period quantity
  2230. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2231. {
  2232. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2233. limitMax = idx+1;
  2234. }
  2235. if(maxProfile.ChargingProfileId != -1)
  2236. {
  2237. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2238. {
  2239. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2240. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2241. (maxProfile.ChargingSchedule.Duration > 0))
  2242. {
  2243. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2244. {
  2245. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2246. compositePeriodIdx++;
  2247. }
  2248. else
  2249. {
  2250. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2251. }
  2252. }
  2253. }
  2254. }
  2255. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  2256. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2257. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  2258. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  2259. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2260. {
  2261. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2262. {
  2263. compositeProfile.ChargingProfileId = 1;
  2264. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2265. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2266. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2267. }
  2268. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2269. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2270. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2271. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2272. }
  2273. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  2274. if(line)
  2275. free(line);
  2276. }
  2277. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2278. {
  2279. FILE *fp;
  2280. char profileFileName[128];
  2281. char *line = NULL;
  2282. size_t len = 0;
  2283. time_t CurrentTime;
  2284. struct tm *tmComposite;
  2285. struct StructChargingProfile maxProfile;
  2286. struct StructChargingProfile defaultTxProfile;
  2287. struct StructChargingProfile txProfile;
  2288. struct StructChargingProfile compositeProfile;
  2289. struct StructChargingSchedulePeriod tmpPeriod;
  2290. uint8_t limitMax=0;
  2291. uint8_t limitDef=0;
  2292. uint8_t limitTx=0;
  2293. int compositePeriodIdx = 0;
  2294. CurrentTime = time(NULL);
  2295. tmComposite=localtime(&CurrentTime);
  2296. 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);
  2297. if(isUnitA)
  2298. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2299. else
  2300. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2301. compositeProfile.ChargingSchedule.Duration = durationReq;
  2302. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2303. {
  2304. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2305. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2306. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2307. }
  2308. compositeProfile.ChargingProfileId = 0;
  2309. compositeProfile.StackLevel = 99 ;
  2310. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2311. maxProfile.ChargingProfileId = -1;
  2312. defaultTxProfile.ChargingProfileId = -1;
  2313. txProfile.ChargingProfileId = -1;
  2314. maxProfile.ChargingSchedule.Duration = -1;
  2315. defaultTxProfile.ChargingSchedule.Duration = -1;
  2316. txProfile.ChargingSchedule.Duration = -1;
  2317. system("rm -f /tmp/*.json");
  2318. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2319. /*
  2320. * Search valid charging profile
  2321. */
  2322. //DEBUG_INFO("====================================\n");
  2323. // Search tx profile
  2324. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  2325. if((access(profileFileName, F_OK))!=-1)
  2326. {
  2327. fp = fopen(profileFileName, "r");
  2328. while(getline(&line, &len, fp) != -1)
  2329. {
  2330. json_object *obj = NULL;
  2331. obj = json_tokener_parse(line);
  2332. if(is_error(obj))
  2333. {
  2334. DEBUG_ERROR("Parse txProfile from file error.\n");
  2335. }
  2336. else
  2337. {
  2338. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  2339. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  2340. )
  2341. {
  2342. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2343. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2344. )
  2345. {
  2346. struct tm tmFrom, tmTo;
  2347. struct timeb tbFrom, tbTo;
  2348. 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) &&
  2349. (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))
  2350. {
  2351. tmFrom.tm_year -= 1900;
  2352. tmFrom.tm_mon -= 1;
  2353. tbFrom.time = mktime(&tmFrom);
  2354. tmTo.tm_year -= 1900;
  2355. tmTo.tm_mon -= 1;
  2356. tbTo.time = mktime(&tmTo);
  2357. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2358. {
  2359. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2360. {
  2361. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2362. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2363. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2364. }
  2365. if(txProfile.ChargingProfileId == -1)
  2366. DEBUG_INFO("TxProfile found.\n");
  2367. else
  2368. DEBUG_INFO("TxProfile updated.\n");
  2369. // Required item
  2370. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2371. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2372. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2373. if(isUnitA)
  2374. {
  2375. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2376. 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++)
  2377. {
  2378. 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"));
  2379. 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?
  2380. 3:
  2381. 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")));
  2382. 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")));
  2383. }
  2384. }
  2385. else
  2386. {
  2387. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2388. 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++)
  2389. {
  2390. 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"));
  2391. 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?
  2392. 3:
  2393. 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")));
  2394. 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));
  2395. }
  2396. }
  2397. // Optional item
  2398. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2399. {
  2400. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2401. }
  2402. else
  2403. {
  2404. sprintf((char*)txProfile.ValidFrom, " ");
  2405. }
  2406. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2407. {
  2408. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2409. }
  2410. else
  2411. {
  2412. sprintf((char*)txProfile.ValidTo, " ");
  2413. }
  2414. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2415. {
  2416. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2417. }
  2418. else
  2419. {
  2420. sprintf((char*)txProfile.RecurrencyKind, " ");
  2421. }
  2422. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2423. {
  2424. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2425. }
  2426. else
  2427. {
  2428. txProfile.TransactionId = -1;
  2429. }
  2430. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2431. {
  2432. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2433. }
  2434. else
  2435. {
  2436. txProfile.ChargingSchedule.Duration = 86400;
  2437. }
  2438. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2439. {
  2440. 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")));
  2441. }
  2442. else
  2443. {
  2444. 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));
  2445. }
  2446. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2447. {
  2448. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2449. }
  2450. else
  2451. {
  2452. txProfile.ChargingSchedule.MinChargingRate = -1;
  2453. }
  2454. }
  2455. }
  2456. }
  2457. else
  2458. {
  2459. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2460. {
  2461. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2462. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2463. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2464. }
  2465. if(txProfile.ChargingProfileId == -1)
  2466. DEBUG_INFO("TxProfile found.\n");
  2467. else
  2468. DEBUG_INFO("TxProfile updated.\n");
  2469. // Required item
  2470. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2471. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2472. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2473. if(isUnitA)
  2474. {
  2475. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2476. 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++)
  2477. {
  2478. 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"));
  2479. 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?
  2480. 3:
  2481. 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")));
  2482. 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")));
  2483. }
  2484. }
  2485. else
  2486. {
  2487. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2488. 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++)
  2489. {
  2490. 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"));
  2491. 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?
  2492. 3:
  2493. 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")));
  2494. 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));
  2495. }
  2496. }
  2497. // Optional item
  2498. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2499. {
  2500. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2501. }
  2502. else
  2503. {
  2504. sprintf((char*)txProfile.ValidFrom, " ");
  2505. }
  2506. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2507. {
  2508. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2509. }
  2510. else
  2511. {
  2512. sprintf((char*)txProfile.ValidTo, " ");
  2513. }
  2514. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2515. {
  2516. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2517. }
  2518. else
  2519. {
  2520. sprintf((char*)txProfile.RecurrencyKind, " ");
  2521. }
  2522. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2523. {
  2524. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2525. }
  2526. else
  2527. {
  2528. txProfile.TransactionId = -1;
  2529. }
  2530. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2531. {
  2532. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2533. }
  2534. else
  2535. {
  2536. txProfile.ChargingSchedule.Duration = 86400;
  2537. }
  2538. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2539. {
  2540. 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")));
  2541. }
  2542. else
  2543. {
  2544. 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));
  2545. }
  2546. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2547. {
  2548. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2549. }
  2550. else
  2551. {
  2552. txProfile.ChargingSchedule.MinChargingRate = -1;
  2553. }
  2554. }
  2555. }
  2556. }
  2557. json_object_put(obj);
  2558. }
  2559. fclose(fp);
  2560. /*
  2561. if(txProfile.ChargingProfileId != -1)
  2562. {
  2563. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2564. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2565. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2566. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2567. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2568. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2569. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2570. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2571. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2572. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2573. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2574. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2575. {
  2576. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2577. {
  2578. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2579. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2580. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2581. }
  2582. }
  2583. }
  2584. else
  2585. DEBUG_INFO("TxProfile not found.\n");*/
  2586. }
  2587. // Search default tx profile
  2588. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2589. if((access(profileFileName, F_OK))==-1)
  2590. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2591. if((access(profileFileName, F_OK))!=-1)
  2592. {
  2593. fp = fopen(profileFileName, "r");
  2594. while(getline(&line, &len, fp) != -1)
  2595. {
  2596. json_object *obj = NULL;
  2597. obj = json_tokener_parse(line);
  2598. if(is_error(obj))
  2599. {
  2600. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2601. }
  2602. else
  2603. {
  2604. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2605. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2606. )
  2607. {
  2608. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2609. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2610. )
  2611. {
  2612. struct tm tmFrom, tmTo;
  2613. struct timeb tbFrom, tbTo;
  2614. 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) &&
  2615. (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))
  2616. {
  2617. tmFrom.tm_year -= 1900;
  2618. tmFrom.tm_mon -= 1;
  2619. tbFrom.time = mktime(&tmFrom);
  2620. tmTo.tm_year -= 1900;
  2621. tmTo.tm_mon -= 1;
  2622. tbTo.time = mktime(&tmTo);
  2623. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2624. {
  2625. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2626. {
  2627. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2628. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2629. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2630. }
  2631. if(defaultTxProfile.ChargingProfileId == -1)
  2632. DEBUG_INFO("TxDefaultProfile found.\n");
  2633. else
  2634. DEBUG_INFO("TxDefaultProfile updated.\n");
  2635. // Required item
  2636. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2637. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2638. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2639. if(isUnitA)
  2640. {
  2641. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2642. 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++)
  2643. {
  2644. 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"));
  2645. 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?
  2646. 3:
  2647. 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")));
  2648. 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")));
  2649. }
  2650. }
  2651. else
  2652. {
  2653. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2654. 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++)
  2655. {
  2656. 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"));
  2657. 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?
  2658. 3:
  2659. 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")));
  2660. 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));
  2661. }
  2662. }
  2663. // Optional item
  2664. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2665. {
  2666. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2667. }
  2668. else
  2669. {
  2670. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2671. }
  2672. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2673. {
  2674. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2675. }
  2676. else
  2677. {
  2678. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2679. }
  2680. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2681. {
  2682. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2683. }
  2684. else
  2685. {
  2686. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2687. }
  2688. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2689. {
  2690. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2691. }
  2692. else
  2693. {
  2694. defaultTxProfile.TransactionId = -1;
  2695. }
  2696. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2697. {
  2698. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2699. }
  2700. else
  2701. {
  2702. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2703. }
  2704. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2705. {
  2706. 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")));
  2707. }
  2708. else
  2709. {
  2710. 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));
  2711. }
  2712. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2713. {
  2714. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2715. }
  2716. else
  2717. {
  2718. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2719. }
  2720. }
  2721. }
  2722. }
  2723. else
  2724. {
  2725. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2726. {
  2727. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2728. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2729. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2730. }
  2731. if(defaultTxProfile.ChargingProfileId == -1)
  2732. DEBUG_INFO("TxDefaultProfile found.\n");
  2733. else
  2734. DEBUG_INFO("TxDefaultProfile updated.\n");
  2735. // Required item
  2736. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2737. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2738. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2739. if(isUnitA)
  2740. {
  2741. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2742. 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++)
  2743. {
  2744. 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"));
  2745. 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?
  2746. 3:
  2747. 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")));
  2748. 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")));
  2749. }
  2750. }
  2751. else
  2752. {
  2753. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2754. 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++)
  2755. {
  2756. 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"));
  2757. 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?
  2758. 3:
  2759. 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")));
  2760. 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));
  2761. }
  2762. }
  2763. // Optional item
  2764. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2765. {
  2766. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2767. }
  2768. else
  2769. {
  2770. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2771. }
  2772. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2773. {
  2774. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2775. }
  2776. else
  2777. {
  2778. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2779. }
  2780. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2781. {
  2782. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2783. }
  2784. else
  2785. {
  2786. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2787. }
  2788. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2789. {
  2790. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2791. }
  2792. else
  2793. {
  2794. defaultTxProfile.TransactionId = -1;
  2795. }
  2796. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2797. {
  2798. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2799. }
  2800. else
  2801. {
  2802. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2803. }
  2804. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2805. {
  2806. 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")));
  2807. }
  2808. else
  2809. {
  2810. 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));
  2811. }
  2812. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2813. {
  2814. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2815. }
  2816. else
  2817. {
  2818. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2819. }
  2820. }
  2821. }
  2822. }
  2823. json_object_put(obj);
  2824. }
  2825. fclose(fp);
  2826. /*
  2827. if(defaultTxProfile.ChargingProfileId != -1)
  2828. {
  2829. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2830. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2831. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2832. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2833. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2834. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2835. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2836. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2837. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2838. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2839. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2840. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2841. {
  2842. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2843. {
  2844. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2845. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2846. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2847. }
  2848. }
  2849. }
  2850. else
  2851. DEBUG_INFO("TxDefaultProfile not found.\n");
  2852. DEBUG_INFO("------------------------------------\n");*/
  2853. }
  2854. // Search max profile
  2855. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2856. if((access(profileFileName, F_OK))!=-1)
  2857. {
  2858. fp = fopen(profileFileName, "r");
  2859. while(getline(&line, &len, fp) != -1)
  2860. {
  2861. json_object *obj = NULL;
  2862. obj = json_tokener_parse(line);
  2863. if(is_error(obj))
  2864. {
  2865. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2866. }
  2867. else
  2868. {
  2869. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2870. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2871. )
  2872. {
  2873. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2874. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2875. )
  2876. {
  2877. struct tm tmFrom, tmTo;
  2878. struct timeb tbFrom, tbTo;
  2879. 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) &&
  2880. (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))
  2881. {
  2882. tmFrom.tm_year -= 1900;
  2883. tmFrom.tm_mon -= 1;
  2884. tbFrom.time = mktime(&tmFrom);
  2885. tmTo.tm_year -= 1900;
  2886. tmTo.tm_mon -= 1;
  2887. tbTo.time = mktime(&tmTo);
  2888. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2889. {
  2890. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2891. {
  2892. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2893. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2894. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2895. }
  2896. if(maxProfile.ChargingProfileId == -1)
  2897. DEBUG_INFO("MaxProfile found.\n");
  2898. else
  2899. DEBUG_INFO("MaxProfile updated.\n");
  2900. // Required item
  2901. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2902. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2903. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2904. if(isUnitA)
  2905. {
  2906. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2907. 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++)
  2908. {
  2909. 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"));
  2910. 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?
  2911. 3:
  2912. 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")));
  2913. 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")));
  2914. }
  2915. }
  2916. else
  2917. {
  2918. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2919. 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++)
  2920. {
  2921. 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"));
  2922. 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?
  2923. 3:
  2924. 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")));
  2925. 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));
  2926. }
  2927. }
  2928. // Optional item
  2929. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2930. {
  2931. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2932. }
  2933. else
  2934. {
  2935. sprintf((char*)maxProfile.ValidFrom, " ");
  2936. }
  2937. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2938. {
  2939. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2940. }
  2941. else
  2942. {
  2943. sprintf((char*)maxProfile.ValidTo, " ");
  2944. }
  2945. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2946. {
  2947. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2948. }
  2949. else
  2950. {
  2951. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2952. }
  2953. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2954. {
  2955. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2956. }
  2957. else
  2958. {
  2959. maxProfile.TransactionId = -1;
  2960. }
  2961. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2962. {
  2963. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2964. }
  2965. else
  2966. {
  2967. maxProfile.ChargingSchedule.Duration = 86400;
  2968. }
  2969. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2970. {
  2971. 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")));
  2972. }
  2973. else
  2974. {
  2975. 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));
  2976. }
  2977. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2978. {
  2979. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2980. }
  2981. else
  2982. {
  2983. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2984. }
  2985. }
  2986. }
  2987. }
  2988. else
  2989. {
  2990. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2991. {
  2992. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2993. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2994. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2995. }
  2996. if(maxProfile.ChargingProfileId == -1)
  2997. DEBUG_INFO("MaxProfile found.\n");
  2998. else
  2999. DEBUG_INFO("MaxProfile updated.\n");
  3000. // Required item
  3001. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3002. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3003. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3004. if(isUnitA)
  3005. {
  3006. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3007. 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++)
  3008. {
  3009. 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"));
  3010. 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?
  3011. 3:
  3012. 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")));
  3013. 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")));
  3014. }
  3015. }
  3016. else
  3017. {
  3018. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3019. 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++)
  3020. {
  3021. 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"));
  3022. 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?
  3023. 3:
  3024. 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")));
  3025. 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));
  3026. }
  3027. }
  3028. // Optional item
  3029. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3030. {
  3031. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3032. }
  3033. else
  3034. {
  3035. sprintf((char*)maxProfile.ValidFrom, " ");
  3036. }
  3037. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3038. {
  3039. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3040. }
  3041. else
  3042. {
  3043. sprintf((char*)maxProfile.ValidTo, " ");
  3044. }
  3045. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3046. {
  3047. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3048. }
  3049. else
  3050. {
  3051. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3052. }
  3053. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3054. {
  3055. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3056. }
  3057. else
  3058. {
  3059. maxProfile.TransactionId = -1;
  3060. }
  3061. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3062. {
  3063. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3064. }
  3065. else
  3066. {
  3067. maxProfile.ChargingSchedule.Duration = 86400;
  3068. }
  3069. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3070. {
  3071. 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")));
  3072. }
  3073. else
  3074. {
  3075. 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));
  3076. }
  3077. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3078. {
  3079. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3080. }
  3081. else
  3082. {
  3083. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3084. }
  3085. }
  3086. }
  3087. }
  3088. json_object_put(obj);
  3089. }
  3090. fclose(fp);
  3091. /*
  3092. if(maxProfile.ChargingProfileId !=-1)
  3093. {
  3094. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3095. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3096. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3097. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3098. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3099. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3100. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3101. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  3102. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3103. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3104. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3105. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3106. {
  3107. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3108. {
  3109. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3110. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3111. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3112. }
  3113. }
  3114. }
  3115. else
  3116. DEBUG_INFO("MaxProfile not found.\n");
  3117. DEBUG_INFO("------------------------------------\n");*/
  3118. }
  3119. /*
  3120. * Align found profile start schedule & periods
  3121. */
  3122. //DEBUG_INFO("====================================\n");
  3123. /*
  3124. // For local test usage, force modify found profile start schedule info
  3125. 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);
  3126. 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);
  3127. 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);
  3128. */
  3129. if(txProfile.ChargingProfileId != -1)
  3130. {
  3131. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  3132. {
  3133. if(txProfile.ChargingSchedule.Duration != -1)
  3134. {
  3135. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3136. 0:
  3137. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3138. }
  3139. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3140. {
  3141. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3142. {
  3143. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3144. 0:
  3145. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3146. if(idxPeriod > 0)
  3147. {
  3148. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3149. {
  3150. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3151. }
  3152. }
  3153. }
  3154. }
  3155. }
  3156. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  3157. {
  3158. if(txProfile.ChargingSchedule.Duration != -1)
  3159. {
  3160. 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?
  3161. 0:
  3162. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3163. }
  3164. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3165. {
  3166. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3167. {
  3168. 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?
  3169. 0:
  3170. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3171. if(idxPeriod > 0)
  3172. {
  3173. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3174. {
  3175. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3176. }
  3177. }
  3178. }
  3179. }
  3180. }
  3181. else
  3182. {
  3183. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  3184. {
  3185. if(txProfile.ChargingSchedule.Duration != -1)
  3186. {
  3187. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3188. 0:
  3189. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3190. }
  3191. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3192. {
  3193. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3194. {
  3195. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3196. 0:
  3197. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3198. if(idxPeriod > 0)
  3199. {
  3200. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3201. {
  3202. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3203. }
  3204. }
  3205. }
  3206. }
  3207. }
  3208. else
  3209. {
  3210. if(txProfile.ChargingSchedule.Duration != -1)
  3211. {
  3212. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3213. 0:
  3214. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3215. }
  3216. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3217. {
  3218. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3219. {
  3220. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3221. 0:
  3222. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3223. if(idxPeriod > 0)
  3224. {
  3225. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3226. {
  3227. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3228. }
  3229. }
  3230. }
  3231. }
  3232. }
  3233. }
  3234. /*
  3235. DEBUG_INFO("txProfile after align.\n");
  3236. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  3237. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  3238. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  3239. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  3240. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  3241. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  3242. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  3243. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3244. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  3245. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  3246. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  3247. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3248. {
  3249. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3250. {
  3251. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3252. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3253. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3254. }
  3255. }*/
  3256. }
  3257. if(defaultTxProfile.ChargingProfileId != -1)
  3258. {
  3259. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  3260. {
  3261. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3262. {
  3263. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3264. 0:
  3265. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3266. }
  3267. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3268. {
  3269. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3270. {
  3271. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3272. 0:
  3273. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3274. if(idxPeriod > 0)
  3275. {
  3276. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3277. {
  3278. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3279. }
  3280. }
  3281. }
  3282. }
  3283. }
  3284. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  3285. {
  3286. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3287. {
  3288. 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?
  3289. 0:
  3290. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3291. }
  3292. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3293. {
  3294. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3295. {
  3296. 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?
  3297. 0:
  3298. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3299. if(idxPeriod > 0)
  3300. {
  3301. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3302. {
  3303. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3304. }
  3305. }
  3306. }
  3307. }
  3308. }
  3309. else
  3310. {
  3311. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  3312. {
  3313. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3314. {
  3315. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3316. 0:
  3317. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3318. }
  3319. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3320. {
  3321. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3322. {
  3323. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3324. 0:
  3325. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3326. if(idxPeriod > 0)
  3327. {
  3328. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3329. {
  3330. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3331. }
  3332. }
  3333. }
  3334. }
  3335. }
  3336. else
  3337. {
  3338. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3339. {
  3340. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3341. 0:
  3342. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3343. }
  3344. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3345. {
  3346. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3347. {
  3348. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3349. 0:
  3350. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3351. if(idxPeriod > 0)
  3352. {
  3353. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3354. {
  3355. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3356. }
  3357. }
  3358. }
  3359. }
  3360. }
  3361. }
  3362. /*
  3363. DEBUG_INFO("defaultTxProfile after align.\n");
  3364. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3365. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3366. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3367. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3368. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3369. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3370. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3371. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3372. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3373. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3374. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3375. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3376. {
  3377. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3378. {
  3379. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3380. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3381. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3382. }
  3383. }
  3384. DEBUG_INFO("------------------------------------\n");*/
  3385. }
  3386. if(maxProfile.ChargingProfileId != -1)
  3387. {
  3388. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3389. {
  3390. if(maxProfile.ChargingSchedule.Duration != -1)
  3391. {
  3392. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3393. 0:
  3394. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3395. }
  3396. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3397. {
  3398. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3399. {
  3400. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3401. 0:
  3402. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3403. if(idxPeriod > 0)
  3404. {
  3405. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3406. {
  3407. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3408. }
  3409. }
  3410. }
  3411. }
  3412. }
  3413. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3414. {
  3415. if(maxProfile.ChargingSchedule.Duration != -1)
  3416. {
  3417. 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?
  3418. 0:
  3419. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3420. }
  3421. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3422. {
  3423. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3424. {
  3425. 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?
  3426. 0:
  3427. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3428. if(idxPeriod > 0)
  3429. {
  3430. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3431. {
  3432. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3433. }
  3434. }
  3435. }
  3436. }
  3437. }
  3438. else
  3439. {
  3440. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3441. {
  3442. if(maxProfile.ChargingSchedule.Duration != -1)
  3443. {
  3444. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3445. 0:
  3446. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3447. }
  3448. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3449. {
  3450. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3451. {
  3452. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3453. 0:
  3454. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3455. if(idxPeriod > 0)
  3456. {
  3457. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3458. {
  3459. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3460. }
  3461. }
  3462. }
  3463. }
  3464. }
  3465. else
  3466. {
  3467. if(maxProfile.ChargingSchedule.Duration != -1)
  3468. {
  3469. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3470. 0:
  3471. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3472. }
  3473. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3474. {
  3475. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3476. {
  3477. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3478. 0:
  3479. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3480. if(idxPeriod > 0)
  3481. {
  3482. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3483. {
  3484. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3485. }
  3486. }
  3487. }
  3488. }
  3489. }
  3490. }
  3491. /*
  3492. DEBUG_INFO("MaxProfile after align.\n");
  3493. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3494. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3495. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3496. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3497. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3498. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3499. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3500. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3501. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3502. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3503. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3504. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3505. {
  3506. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3507. {
  3508. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3509. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3510. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3511. }
  3512. }
  3513. DEBUG_INFO("------------------------------------\n");*/
  3514. }
  3515. /*
  3516. * Merge to conposite schedule
  3517. */
  3518. //DEBUG_INFO("====================================\n");
  3519. // Find each profile period quantity
  3520. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3521. {
  3522. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3523. limitMax = idx+1;
  3524. }
  3525. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3526. {
  3527. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3528. limitDef = idx+1;
  3529. }
  3530. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3531. {
  3532. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3533. limitTx = idx+1;
  3534. }
  3535. // TxProfile found, composite schedule based on it
  3536. if(txProfile.ChargingProfileId != -1)
  3537. {
  3538. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3539. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3540. {
  3541. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3542. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3543. (txProfile.ChargingSchedule.Duration > 0))
  3544. {
  3545. if(maxProfile.ChargingProfileId != -1)
  3546. {
  3547. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3548. {
  3549. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3550. {
  3551. if((maxProfile.ChargingSchedule.Duration > 0))
  3552. {
  3553. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3554. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3555. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3556. }
  3557. else
  3558. {
  3559. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3560. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3561. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3562. }
  3563. }
  3564. if(idxMaxPeriod == (limitMax-1))
  3565. {
  3566. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3567. {
  3568. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3569. {
  3570. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3571. compositePeriodIdx++;
  3572. }
  3573. else
  3574. {
  3575. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3576. }
  3577. }
  3578. }
  3579. }
  3580. }
  3581. else
  3582. {
  3583. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3584. {
  3585. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3586. compositePeriodIdx++;
  3587. }
  3588. else
  3589. {
  3590. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3591. }
  3592. }
  3593. }
  3594. if(idxTxPeriod == (limitTx-1))
  3595. {
  3596. if(defaultTxProfile.ChargingProfileId != -1)
  3597. {
  3598. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3599. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3600. {
  3601. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3602. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3603. (defaultTxProfile.ChargingSchedule.Duration>0))
  3604. {
  3605. if(maxProfile.ChargingProfileId != -1)
  3606. {
  3607. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3608. {
  3609. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3610. {
  3611. if((maxProfile.ChargingSchedule.Duration > 0))
  3612. {
  3613. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3614. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3615. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3616. }
  3617. else
  3618. {
  3619. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3620. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3621. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3622. }
  3623. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3624. {
  3625. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3626. {
  3627. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3628. compositePeriodIdx++;
  3629. }
  3630. else
  3631. {
  3632. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3633. }
  3634. }
  3635. // Delete duplicate period
  3636. if(compositePeriodIdx > 1)
  3637. {
  3638. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3639. {
  3640. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3641. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3642. compositePeriodIdx -= 1;
  3643. }
  3644. }
  3645. }
  3646. else
  3647. {
  3648. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3649. {
  3650. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3651. compositePeriodIdx++;
  3652. }
  3653. else
  3654. {
  3655. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3656. }
  3657. break;
  3658. }
  3659. }
  3660. }
  3661. else
  3662. {
  3663. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3664. {
  3665. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3666. compositePeriodIdx++;
  3667. }
  3668. else
  3669. {
  3670. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3671. }
  3672. }
  3673. }
  3674. }
  3675. }
  3676. }
  3677. }
  3678. }
  3679. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3680. else if(defaultTxProfile.ChargingProfileId != -1)
  3681. {
  3682. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3683. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3684. {
  3685. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3686. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3687. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3688. {
  3689. if(maxProfile.ChargingProfileId != -1)
  3690. {
  3691. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3692. {
  3693. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3694. {
  3695. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3696. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3697. if((maxProfile.ChargingSchedule.Duration > 0))
  3698. {
  3699. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3700. }
  3701. else
  3702. {
  3703. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3704. }
  3705. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3706. {
  3707. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3708. {
  3709. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3710. compositePeriodIdx++;
  3711. }
  3712. else
  3713. {
  3714. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3715. }
  3716. }
  3717. // Delete duplicate period
  3718. if(compositePeriodIdx > 1)
  3719. {
  3720. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3721. {
  3722. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3723. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3724. compositePeriodIdx -= 1;
  3725. }
  3726. }
  3727. }
  3728. else
  3729. {
  3730. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3731. {
  3732. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3733. compositePeriodIdx++;
  3734. }
  3735. else
  3736. {
  3737. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3738. }
  3739. break;
  3740. }
  3741. }
  3742. }
  3743. else
  3744. {
  3745. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3746. {
  3747. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3748. compositePeriodIdx++;
  3749. }
  3750. else
  3751. {
  3752. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3753. }
  3754. }
  3755. }
  3756. }
  3757. }
  3758. // Fill other period by MaxProfile
  3759. if(maxProfile.ChargingProfileId != -1)
  3760. {
  3761. if(compositePeriodIdx==0)
  3762. {
  3763. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3764. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3765. {
  3766. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3767. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3768. (maxProfile.ChargingSchedule.Duration > 0))
  3769. {
  3770. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3771. {
  3772. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3773. compositePeriodIdx++;
  3774. }
  3775. else
  3776. {
  3777. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3778. }
  3779. }
  3780. }
  3781. }
  3782. else
  3783. {
  3784. int lastCompositePeriodIdx = compositePeriodIdx;
  3785. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3786. {
  3787. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3788. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3789. (maxProfile.ChargingSchedule.Duration > 0))
  3790. {
  3791. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3792. {
  3793. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3794. {
  3795. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3796. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3797. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3798. }
  3799. else
  3800. {
  3801. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3802. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3803. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3804. }
  3805. }
  3806. if(tmpPeriod.Limit != -1)
  3807. {
  3808. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3809. {
  3810. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3811. {
  3812. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3813. compositePeriodIdx++;
  3814. }
  3815. else
  3816. {
  3817. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3818. }
  3819. }
  3820. // Delete duplicate period
  3821. if(compositePeriodIdx > 1)
  3822. {
  3823. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3824. {
  3825. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3826. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3827. compositePeriodIdx -= 1;
  3828. }
  3829. }
  3830. }
  3831. }
  3832. }
  3833. }
  3834. }
  3835. compositeProfile.ChargingSchedule.Duration = durationReq;
  3836. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3837. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3838. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  3839. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  3840. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3841. {
  3842. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3843. {
  3844. compositeProfile.ChargingProfileId = 1;
  3845. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3846. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3847. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3848. }
  3849. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3850. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3851. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3852. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3853. }
  3854. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3855. if(line)
  3856. free(line);
  3857. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3858. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3859. }
  3860. //==========================================
  3861. // Init all share memory
  3862. //==========================================
  3863. int InitShareMemory()
  3864. {
  3865. int result = PASS;
  3866. int MeterSMId;
  3867. //creat ShmSysConfigAndInfo
  3868. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3869. {
  3870. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3871. result = FAIL;
  3872. }
  3873. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3874. {
  3875. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3876. result = FAIL;
  3877. }
  3878. else
  3879. {}
  3880. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3881. {
  3882. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3883. result = FAIL;
  3884. }
  3885. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3886. {
  3887. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3888. result = FAIL;
  3889. }
  3890. else
  3891. {}
  3892. //creat ShmPsuData
  3893. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3894. {
  3895. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3896. result = FAIL;
  3897. }
  3898. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3899. {
  3900. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3901. result = FAIL;
  3902. }
  3903. else
  3904. {}
  3905. //creat ShmOCPP16Data
  3906. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3907. {
  3908. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3909. result = FAIL;
  3910. }
  3911. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3912. {
  3913. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3914. result = FAIL;
  3915. }
  3916. else
  3917. {}
  3918. /****************************** For Initial Settings************************************************/
  3919. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3920. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3921. // allocate Configuration memory address
  3922. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3923. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3924. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3925. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3926. //offline MeterValue Interval
  3927. TempMeterValueInterval = 0;
  3928. return result;
  3929. }
  3930. int ProcessShareMemory()
  3931. {
  3932. int result = PASS;
  3933. if(InitShareMemory() == FAIL)
  3934. {
  3935. DEBUG_ERROR("InitShareMemory NG\n");
  3936. if(ShmStatusCodeData!=NULL)
  3937. {
  3938. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3939. }
  3940. result = FAIL;
  3941. }
  3942. // Model name parsing
  3943. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3944. {
  3945. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3946. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3947. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3948. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3949. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3950. ) // 'D' means DC
  3951. {
  3952. // DO series
  3953. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3954. {
  3955. SystemInitial += 1;
  3956. gunTotalNumber += 1;
  3957. gunType[gun_index] = GUN_TYPE_DO;
  3958. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3959. {
  3960. case Gun_Type_Chademo:
  3961. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3962. break;
  3963. case Gun_Type_CCS_2:
  3964. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3965. break;
  3966. case Gun_Type_GB:
  3967. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3968. break;
  3969. case Gun_Type_AC:
  3970. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3971. break;
  3972. default:
  3973. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3974. break;
  3975. }
  3976. }
  3977. }
  3978. else
  3979. {
  3980. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3981. {
  3982. SystemInitial += 1;
  3983. gunTotalNumber += 1;
  3984. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3985. {
  3986. case Gun_Type_Chademo:
  3987. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3988. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3989. break;
  3990. case Gun_Type_CCS_2:
  3991. gunType[gun_index] = GUN_TYPE_CCS;
  3992. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3993. break;
  3994. case Gun_Type_GB:
  3995. gunType[gun_index] = GUN_TYPE_GBT;
  3996. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3997. break;
  3998. case Gun_Type_AC:
  3999. gunType[gun_index] = GUN_TYPE_AC;
  4000. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  4001. break;
  4002. default:
  4003. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  4004. break;
  4005. }
  4006. }
  4007. }
  4008. }
  4009. else
  4010. {
  4011. DEBUG_ERROR("Model name parsing fail.\n");
  4012. result = FAIL;
  4013. }
  4014. if(result != PASS)sleep(5);
  4015. return result;
  4016. }
  4017. void checkRemoteStart(uint8_t connectorIdInt)
  4018. {
  4019. uint8_t tempIndex;
  4020. int result = PASS;
  4021. char cmdBuf[512];
  4022. //check Transaction active
  4023. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  4024. {
  4025. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4026. {
  4027. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4028. }
  4029. else
  4030. {
  4031. tempIndex = connectorIdInt -1;
  4032. }
  4033. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4034. {
  4035. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4036. {
  4037. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4038. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4039. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4040. {
  4041. //Reserved
  4042. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  4043. }
  4044. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4045. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4046. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4047. {
  4048. //Reserved
  4049. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  4050. result = FAIL;
  4051. goto end;
  4052. }
  4053. else
  4054. {
  4055. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4056. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  4057. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  4058. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  4059. {
  4060. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  4061. result = FAIL;
  4062. goto end;
  4063. }
  4064. }//END FOR ELSE
  4065. }
  4066. }// END FOR CHAdeMO_QUANTITY
  4067. }
  4068. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  4069. {
  4070. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4071. {
  4072. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4073. }
  4074. else
  4075. {
  4076. tempIndex = connectorIdInt -1;
  4077. }
  4078. for (int index = 0; index < CCS_QUANTITY; index++)
  4079. {
  4080. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4081. {
  4082. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4083. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4084. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4085. {
  4086. //Reserved
  4087. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  4088. }
  4089. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4090. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4091. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4092. {
  4093. //Reserved
  4094. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  4095. result = FAIL;
  4096. goto end;
  4097. }
  4098. else
  4099. {
  4100. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4101. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4102. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4103. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4104. {
  4105. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  4106. result = FAIL;
  4107. goto end;
  4108. }
  4109. }// END FOR ELSE
  4110. }
  4111. }// END FOR CCS_QUANTITY
  4112. }
  4113. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  4114. {
  4115. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4116. {
  4117. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4118. }
  4119. else
  4120. {
  4121. tempIndex = connectorIdInt -1;
  4122. }
  4123. for (int index = 0; index < GB_QUANTITY; index++)
  4124. {
  4125. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  4126. {
  4127. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4128. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4129. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4130. {
  4131. //Reserved
  4132. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  4133. }
  4134. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4135. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4136. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4137. {
  4138. //Reserved
  4139. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  4140. result = FAIL;
  4141. goto end;
  4142. }
  4143. else
  4144. {
  4145. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4146. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4147. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4148. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4149. {
  4150. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  4151. result = FAIL;
  4152. goto end;
  4153. }
  4154. }// END FOR ELSE
  4155. }
  4156. } // END FOR GB_QUANTITY
  4157. }
  4158. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  4159. {
  4160. tempIndex = connectorIdInt -1;
  4161. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4162. {
  4163. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  4164. {
  4165. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4166. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4167. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4168. {
  4169. //Reserved
  4170. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  4171. }
  4172. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4173. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4174. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4175. {
  4176. //Reserved
  4177. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  4178. result = FAIL;
  4179. goto end;
  4180. }
  4181. else
  4182. {
  4183. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4184. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4185. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4186. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4187. {
  4188. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  4189. result = FAIL;
  4190. goto end;
  4191. }
  4192. }// END FOR ELSE
  4193. }
  4194. } // END FOR GB_QUANTITY
  4195. }
  4196. else
  4197. {
  4198. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  4199. {
  4200. tempIndex = 2;
  4201. }
  4202. else
  4203. {
  4204. tempIndex = connectorIdInt -1;
  4205. }
  4206. for (int index = 0; index < AC_QUANTITY; index++)
  4207. {
  4208. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  4209. {
  4210. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4211. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4212. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4213. {
  4214. //Reserved
  4215. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  4216. }
  4217. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4218. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4219. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4220. {
  4221. //Reserved
  4222. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  4223. result = FAIL;
  4224. goto end;
  4225. }
  4226. else
  4227. {
  4228. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4229. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4230. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4231. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4232. {
  4233. DEBUG_WARN("AC connector not allow start cause busy.\n");
  4234. result = FAIL;
  4235. goto end;
  4236. }
  4237. }//END FOR ELSE
  4238. }
  4239. }// END FOR AC_QUANTITY
  4240. }
  4241. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  4242. {
  4243. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  4244. {
  4245. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  4246. {
  4247. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4248. system(cmdBuf);
  4249. }
  4250. }
  4251. else
  4252. {
  4253. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  4254. result = FAIL;
  4255. }
  4256. }
  4257. end:
  4258. if(result == PASS)
  4259. {
  4260. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  4261. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  4262. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4263. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  4264. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4265. }
  4266. }
  4267. void CheckSystemValue(void)
  4268. {
  4269. char filenmae[100]={0};
  4270. char str[100]={0};
  4271. int tempIndex = 0;
  4272. //===============================
  4273. // send Heartbeat
  4274. //===============================
  4275. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  4276. {
  4277. //parameter for test
  4278. sendHeartbeatRequest(0);
  4279. //===========================
  4280. // Reset Waiting Time
  4281. //===========================
  4282. HeartBeatWithNOResponse += 1;
  4283. }
  4284. //===============================
  4285. // Credit deduct report
  4286. //===============================
  4287. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  4288. {
  4289. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo,
  4290. ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice,
  4291. ShmOCPP16Data->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.vemData,
  4292. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.RRN,
  4293. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.storeId);
  4294. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  4295. }
  4296. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  4297. {
  4298. OCPP_query_deduct_info();
  4299. refreshStartTimer(&clientTime.TcciQueryDeduct);
  4300. }
  4301. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4302. {
  4303. // ClockAlign MeterValue
  4304. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  4305. {
  4306. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4307. {
  4308. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4309. {
  4310. tempIndex = ((gun_index==2) ? 1: 0);
  4311. }
  4312. else
  4313. {
  4314. tempIndex = gun_index;
  4315. }
  4316. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4317. {
  4318. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4319. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4320. {
  4321. reqClockAlignMeter[gun_index] = 1;
  4322. }
  4323. }// End for CHAdeMO
  4324. }
  4325. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4326. {
  4327. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4328. {
  4329. tempIndex = ((gun_index==2) ? 1: 0);
  4330. }
  4331. else
  4332. {
  4333. tempIndex = gun_index;
  4334. }
  4335. for (int index = 0; index < CCS_QUANTITY; index++)
  4336. {
  4337. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4338. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4339. {
  4340. reqClockAlignMeter[gun_index] = 1;
  4341. }
  4342. } // End for CCS
  4343. }
  4344. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4345. {
  4346. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4347. {
  4348. tempIndex = ((gun_index==2) ? 1: 0);
  4349. }
  4350. else
  4351. {
  4352. tempIndex = gun_index;
  4353. }
  4354. for (int index = 0; index < GB_QUANTITY; index++)
  4355. {
  4356. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4357. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4358. {
  4359. reqClockAlignMeter[gun_index] = 1;
  4360. }
  4361. }// End for GB
  4362. }
  4363. else if(gunType[gun_index] == GUN_TYPE_DO)
  4364. {
  4365. tempIndex = gun_index;
  4366. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4367. {
  4368. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4369. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4370. {
  4371. reqClockAlignMeter[gun_index] = 1;
  4372. }
  4373. }
  4374. }
  4375. else
  4376. {
  4377. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4378. {
  4379. tempIndex = 2;
  4380. }
  4381. else
  4382. {
  4383. tempIndex = gun_index;
  4384. }
  4385. for (int index = 0; index < AC_QUANTITY; index++)
  4386. {
  4387. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4388. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4389. {
  4390. reqClockAlignMeter[gun_index] = 1;
  4391. }
  4392. }//End for AC
  4393. }
  4394. }
  4395. }
  4396. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4397. {
  4398. //==========================================
  4399. // Check remote start without connector id
  4400. //==========================================
  4401. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4402. {
  4403. int connectorIdInt = -1;
  4404. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4405. {
  4406. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4407. {
  4408. connectorIdInt = (gun_index+1);
  4409. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4410. checkRemoteStart(connectorIdInt);
  4411. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4412. break;
  4413. }
  4414. }
  4415. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4416. {
  4417. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4418. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4419. }
  4420. }
  4421. //==========================================
  4422. // csu trigger DataTransferReq
  4423. //==========================================
  4424. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4425. {
  4426. sendDataTransferRequest(gun_index);
  4427. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  4428. if((ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq) && (strstr((char *)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ID_ReaderStatus") != NULL))
  4429. ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4430. }
  4431. //==========================================
  4432. // CSU Trigger Authorize Request
  4433. //==========================================
  4434. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4435. {
  4436. sendAuthorizeRequest(0);
  4437. authorizeRetryTimes = authorizeRetryTimes + 1;
  4438. if(authorizeRetryTimes < 3)
  4439. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4440. }
  4441. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4442. {
  4443. authorizeRetryTimes = 0;
  4444. SetOcppConnStatus(FALSE);
  4445. server_sign = FALSE;
  4446. }
  4447. 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))
  4448. {
  4449. sendAuthorizeRequest(0);
  4450. }
  4451. //==========================================
  4452. // Charger start transaction
  4453. //==========================================
  4454. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4455. {
  4456. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4457. sendStartTransactionRequest(gun_index);
  4458. refreshStartTimer(&clientTime.StartTransaction);
  4459. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4460. storeTempStopTransaction(gun_index);
  4461. }
  4462. //==========================================
  4463. // Charger stop transaction
  4464. //==========================================
  4465. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4466. {
  4467. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4468. sendStopTransactionRequest(gun_index);
  4469. OCPP_updatePeriodEnergy(gun_index);
  4470. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  4471. refreshStartTimer(&clientTime.StopTransaction);
  4472. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4473. }
  4474. //==========================================
  4475. // Charger status report
  4476. //==========================================
  4477. //--- Check Mode Change ---//
  4478. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4479. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4480. {
  4481. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4482. {
  4483. tempIndex = ((gun_index==2) ? 1: 0);
  4484. }
  4485. else
  4486. {
  4487. tempIndex = gun_index;
  4488. }
  4489. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4490. {
  4491. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4492. {
  4493. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4494. {
  4495. // Sent unplug message for California pricing logic
  4496. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  4497. {
  4498. uint8_t ts[20];
  4499. getNowDatetime(ts);
  4500. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4501. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4502. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4503. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4504. }
  4505. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4506. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4507. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4508. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4509. {
  4510. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4511. if((access(filenmae,F_OK))!=-1)
  4512. {
  4513. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4514. sprintf(str,"rm -f %s",filenmae);
  4515. system(str);
  4516. }
  4517. }
  4518. }
  4519. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4520. #if 1 // for TempStopTransaction
  4521. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4522. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4523. {
  4524. checkTempStopTransaction(gun_index);
  4525. }
  4526. #endif
  4527. }
  4528. }
  4529. }
  4530. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4531. {
  4532. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4533. {
  4534. tempIndex = ((gun_index==2) ? 1: 0);
  4535. }
  4536. else
  4537. {
  4538. tempIndex = gun_index;
  4539. }
  4540. for (int index = 0; index < CCS_QUANTITY; index++)
  4541. {
  4542. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4543. {
  4544. 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]*/ )
  4545. {
  4546. // Sent unplug message for California pricing logic
  4547. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  4548. {
  4549. uint8_t ts[20];
  4550. getNowDatetime(ts);
  4551. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4552. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4553. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4554. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4555. }
  4556. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4557. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4558. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4559. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4560. {
  4561. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4562. if((access(filenmae,F_OK))!=-1)
  4563. {
  4564. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4565. sprintf(str,"rm -f %s",filenmae);
  4566. system(str);
  4567. }
  4568. }
  4569. }
  4570. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4571. #if 1 // for TempStopTransaction
  4572. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4573. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4574. {
  4575. checkTempStopTransaction(gun_index);
  4576. }
  4577. #endif
  4578. }
  4579. }
  4580. }
  4581. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4582. {
  4583. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4584. {
  4585. tempIndex = ((gun_index==2) ? 1: 0);
  4586. }
  4587. else
  4588. {
  4589. tempIndex = gun_index;
  4590. }
  4591. for (int index = 0; index < GB_QUANTITY; index++)
  4592. {
  4593. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4594. {
  4595. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4596. {
  4597. // Sent unplug message for California pricing logic
  4598. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  4599. {
  4600. uint8_t ts[20];
  4601. getNowDatetime(ts);
  4602. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4603. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4604. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4605. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4606. }
  4607. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4608. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4609. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4610. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4611. {
  4612. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4613. if((access(filenmae,F_OK))!=-1)
  4614. {
  4615. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4616. sprintf(str,"rm -f %s",filenmae);
  4617. system(str);
  4618. }
  4619. }
  4620. }
  4621. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4622. #if 1 // for TempStopTransaction
  4623. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4624. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4625. {
  4626. checkTempStopTransaction(gun_index);
  4627. }
  4628. #endif
  4629. }
  4630. }
  4631. }
  4632. else if(gunType[gun_index] == GUN_TYPE_DO)
  4633. {
  4634. tempIndex = gun_index;
  4635. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4636. {
  4637. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4638. {
  4639. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4640. {
  4641. // Sent unplug message for California pricing logic
  4642. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  4643. {
  4644. uint8_t ts[20];
  4645. getNowDatetime(ts);
  4646. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4647. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4648. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4649. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4650. }
  4651. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4652. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4653. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4654. 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
  4655. {
  4656. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4657. if((access(filenmae,F_OK))!=-1)
  4658. {
  4659. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4660. sprintf(str,"rm -f %s",filenmae);
  4661. system(str);
  4662. }
  4663. }
  4664. }
  4665. 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);
  4666. #if 1 // for TempStopTransaction
  4667. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4668. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4669. {
  4670. checkTempStopTransaction(gun_index);
  4671. }
  4672. #endif
  4673. }
  4674. }
  4675. }
  4676. else
  4677. {
  4678. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4679. {
  4680. tempIndex = 2;
  4681. }
  4682. else
  4683. {
  4684. tempIndex = gun_index;
  4685. }
  4686. for (int index = 0; index < AC_QUANTITY; index++)
  4687. {
  4688. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4689. {
  4690. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4691. {
  4692. // Sent unplug message for California pricing logic
  4693. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  4694. {
  4695. uint8_t ts[20];
  4696. getNowDatetime(ts);
  4697. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4698. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4699. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4700. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4701. }
  4702. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4703. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4704. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4705. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4706. {
  4707. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4708. if((access(filenmae,F_OK))!=-1)
  4709. {
  4710. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4711. sprintf(str,"rm -f %s",filenmae);
  4712. system(str);
  4713. }
  4714. }
  4715. }
  4716. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4717. #if 1 // for TempStopTransaction
  4718. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4719. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4720. {
  4721. checkTempStopTransaction(gun_index);
  4722. }
  4723. #endif
  4724. }
  4725. }// END
  4726. }
  4727. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) &&
  4728. (
  4729. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4730. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4731. )
  4732. )
  4733. {
  4734. if(SystemInitial > 0)
  4735. SystemInitial -= 1;
  4736. sendStatusNotificationRequest(gun_index);
  4737. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4738. }
  4739. //==============================================
  4740. // TCCI reader status report
  4741. //==============================================
  4742. if(ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1)
  4743. {
  4744. reportReaderStatus(gun_index);
  4745. //ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4746. }
  4747. //==============================================
  4748. // CSU Trigger Smart Charging Profile
  4749. //==============================================
  4750. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4751. {
  4752. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  4753. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4754. }
  4755. //==============================================
  4756. // Meter report
  4757. //==============================================
  4758. // Trigger MeterValue
  4759. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4760. {
  4761. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4762. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4763. }
  4764. // Clock-aligned Meter value
  4765. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4766. {
  4767. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4768. reqClockAlignMeter[gun_index] = 0;
  4769. }
  4770. // Sample period MeterValue
  4771. if(((getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>3?(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):3))))
  4772. {
  4773. //check Transaction active
  4774. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4775. {
  4776. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4777. {
  4778. tempIndex = ((gun_index==2) ? 1: 0);
  4779. }
  4780. else
  4781. {
  4782. tempIndex = gun_index;
  4783. }
  4784. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4785. {
  4786. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4787. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4788. {
  4789. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4790. {
  4791. reqSampleMeter[gun_index] = 1;
  4792. }
  4793. }
  4794. }// End for CHAdeMO
  4795. }
  4796. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4797. {
  4798. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4799. {
  4800. tempIndex = ((gun_index==2) ? 1: 0);
  4801. }
  4802. else
  4803. {
  4804. tempIndex = gun_index;
  4805. }
  4806. for (int index = 0; index < CCS_QUANTITY; index++)
  4807. {
  4808. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4809. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4810. {
  4811. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4812. {
  4813. reqSampleMeter[gun_index] = 1;
  4814. }
  4815. }
  4816. } // End for CCS
  4817. }
  4818. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4819. {
  4820. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4821. {
  4822. tempIndex = ((gun_index==2) ? 1: 0);
  4823. }
  4824. else
  4825. {
  4826. tempIndex = gun_index;
  4827. }
  4828. for (int index = 0; index < GB_QUANTITY; index++)
  4829. {
  4830. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4831. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4832. {
  4833. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4834. {
  4835. reqSampleMeter[gun_index] = 1;
  4836. }
  4837. }
  4838. }// End for GB
  4839. }
  4840. else if(gunType[gun_index] == GUN_TYPE_DO)
  4841. {
  4842. tempIndex = gun_index;
  4843. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4844. {
  4845. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4846. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4847. {
  4848. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4849. {
  4850. reqSampleMeter[gun_index] = 1;
  4851. }
  4852. }
  4853. }
  4854. }
  4855. else
  4856. {
  4857. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4858. {
  4859. tempIndex = 2;
  4860. }
  4861. else
  4862. {
  4863. tempIndex = gun_index;
  4864. }
  4865. for (int index = 0; index < AC_QUANTITY; index++)
  4866. {
  4867. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4868. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4869. {
  4870. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4871. {
  4872. reqSampleMeter[gun_index] = 1;
  4873. }
  4874. }
  4875. }//End for AC
  4876. }
  4877. if(reqSampleMeter[gun_index] == 1)
  4878. {
  4879. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4880. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4881. storeTempStopTransaction(gun_index);
  4882. reqSampleMeter[gun_index] = 0;
  4883. }
  4884. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4885. }
  4886. //==============================================
  4887. // Check Connector reserved
  4888. //==============================================
  4889. //===============================
  4890. // Check if Reserve is expired
  4891. //===============================
  4892. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  4893. {
  4894. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  4895. {
  4896. DEBUG_INFO("reserve expired.\n");
  4897. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  4898. }
  4899. }//END OF Check if Reserve is expired
  4900. //==========================================
  4901. // csu trigger FirmwareStatusNotificationReq
  4902. //==========================================
  4903. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4904. {
  4905. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  4906. }
  4907. //==========================================
  4908. // csu trigger DiagnosticsStatusNotificationReq
  4909. //==========================================
  4910. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4911. {
  4912. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  4913. }
  4914. //==========================================
  4915. // csu trigger CancelReservationConf
  4916. //==========================================
  4917. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4918. {
  4919. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  4920. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4921. }
  4922. //==========================================
  4923. // csu trigger ChangeAvailabilityConf
  4924. //==========================================
  4925. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4926. {
  4927. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  4928. }
  4929. //==========================================
  4930. // csu trigger UnlockConnectorConf
  4931. //==========================================
  4932. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4933. {
  4934. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  4935. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4936. }
  4937. //==========================================
  4938. // csu trigger ReserveNowConf
  4939. //==========================================
  4940. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4941. {
  4942. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  4943. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4944. }
  4945. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  4946. {
  4947. sendSignCertificateRequest();
  4948. }
  4949. }
  4950. }
  4951. //==========================================
  4952. // send request routine
  4953. //==========================================
  4954. int sendAuthorizeRequest(int gun_index)
  4955. {
  4956. mtrace();
  4957. int result = FAIL;
  4958. char message[100]={0};
  4959. char guid[37];
  4960. char tempdata[65]={0};
  4961. DEBUG_INFO("sendAuthorizeRequest...\n");
  4962. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4963. //Local Authorize
  4964. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  4965. {
  4966. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4967. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4968. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4969. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4970. result = PASS;
  4971. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4972. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4973. authorizeRetryTimes = 0;
  4974. return result;
  4975. }
  4976. 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))||
  4977. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4978. {
  4979. // Query from cache
  4980. DEBUG_INFO("Authorize from cache.\n");
  4981. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4982. // Query from list
  4983. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4984. {
  4985. DEBUG_INFO("Authorize from list.\n");
  4986. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4987. }
  4988. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4989. {
  4990. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4991. {
  4992. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4993. }
  4994. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4995. {
  4996. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4997. }
  4998. if(!GetOcppConnStatus())
  4999. {
  5000. DEBUG_INFO("off-line Local Authorization Fail.\n");
  5001. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5002. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5003. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  5004. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5005. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5006. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5007. authorizeRetryTimes = 0;
  5008. return result;
  5009. }
  5010. }
  5011. else
  5012. {
  5013. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  5014. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5015. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5016. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  5017. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  5018. else
  5019. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  5020. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5021. result = PASS;
  5022. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5023. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5024. authorizeRetryTimes = 0;
  5025. return result;
  5026. }
  5027. }
  5028. //initialize struct Authorize
  5029. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  5030. //get data from shared memory
  5031. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5032. random_uuid(guid);
  5033. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  5034. LWS_Send(message);
  5035. sprintf(tempdata, "Authorize,%d", gun_index);
  5036. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5037. {
  5038. result = PASS;
  5039. DEBUG_INFO("Authorize mapItem pass\n");
  5040. }
  5041. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5042. return result;
  5043. }
  5044. int sendBootNotificationRequest(void)
  5045. {
  5046. mtrace();
  5047. int result = FAIL;
  5048. char message[500]={0}, payload[700]={0};
  5049. char guid[37]={0};
  5050. char tempdata[65]={0};
  5051. // Fill BootNotification fields
  5052. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  5053. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  5054. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  5055. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5056. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  5057. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  5058. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  5059. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  5060. ShmOCPP16Data->ChargeBoxId
  5061. ,ShmSysConfigAndInfo->SysConfig.ModelName
  5062. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  5063. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  5064. ,ShmOCPP16Data->BootNotification.CpFwVersion
  5065. ,ShmOCPP16Data->BootNotification.CpIccid
  5066. ,ShmOCPP16Data->BootNotification.CpImsi);
  5067. random_uuid(guid);
  5068. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  5069. LWS_Send(message);
  5070. sprintf(tempdata, "BootNotification,0");
  5071. 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*/)
  5072. {
  5073. result = PASS;
  5074. }
  5075. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5076. strcpy(queuedata,message);
  5077. return result;
  5078. }
  5079. int sendDataTransferRequest(int gun_index)
  5080. {
  5081. mtrace();
  5082. char message[1000]={0};
  5083. char guid[37]={0};
  5084. char tempdata[65]={0};
  5085. int result = FAIL;
  5086. random_uuid(guid);
  5087. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5088. MESSAGE_TYPE_CALL,
  5089. guid,
  5090. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5091. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5092. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5093. LWS_Send(message);
  5094. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5095. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5096. {
  5097. result = PASS;
  5098. DEBUG_INFO("DataTransfer mapItem pass\n");
  5099. }
  5100. return result;
  5101. }
  5102. int sendDiagnosticsStatusNotificationRequest(char *status)
  5103. {
  5104. mtrace();
  5105. int result = FAIL;
  5106. char message[110]={0};
  5107. char guid[37]={0};
  5108. char tempdata[65]={0};
  5109. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  5110. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  5111. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  5112. random_uuid(guid);
  5113. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  5114. LWS_SendNow(message);
  5115. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  5116. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5117. {
  5118. result = PASS;
  5119. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  5120. }
  5121. //#ifdef SystemLogMessage
  5122. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  5123. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5124. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  5125. //#endif
  5126. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  5127. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  5128. //record status
  5129. if(strcmp(status,"Idle")==0)
  5130. {
  5131. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  5132. }
  5133. else if(strcmp(status,"Uploaded")==0)
  5134. {
  5135. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  5136. }
  5137. else if(strcmp(status,"UploadFailed")==0)
  5138. {
  5139. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  5140. }
  5141. else if(strcmp(status,"Uploading")==0)
  5142. {
  5143. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  5144. }
  5145. return result;
  5146. }
  5147. int sendFirmwareStatusNotificationRequest(char *status)
  5148. {
  5149. mtrace();
  5150. int result = FAIL;
  5151. char message[110]={0};
  5152. char guid[37]={0};
  5153. char tempdata[65]={0};
  5154. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  5155. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  5156. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  5157. random_uuid(guid);
  5158. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  5159. LWS_SendNow(message);
  5160. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5161. 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*/)
  5162. {
  5163. result = PASS;
  5164. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  5165. }
  5166. //#ifdef SystemLogMessage
  5167. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  5168. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5169. //#endif
  5170. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  5171. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  5172. //record status
  5173. if(strcmp(status,"Downloaded")==0)
  5174. {
  5175. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  5176. }
  5177. else if(strcmp(status,"DownloadFailed")==0)
  5178. {
  5179. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  5180. }
  5181. else if(strcmp(status,"Downloading")==0)
  5182. {
  5183. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  5184. }
  5185. else if(strcmp(status,"Idle")==0)
  5186. {
  5187. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  5188. }
  5189. else if(strcmp(status,"InstallationFailed")==0)
  5190. {
  5191. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  5192. }
  5193. else if(strcmp(status,"Installing")==0)
  5194. {
  5195. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  5196. }
  5197. else if(strcmp(status,"Installed")==0)
  5198. {
  5199. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  5200. }
  5201. return result;
  5202. }
  5203. int sendHeartbeatRequest(int gun_index)
  5204. {
  5205. mtrace();
  5206. int result = FAIL;
  5207. char message[80]={0};
  5208. char guid[37]={0};
  5209. char tempdata[65]={0};
  5210. random_uuid(guid);
  5211. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  5212. , MESSAGE_TYPE_CALL
  5213. , guid );
  5214. LWS_Send(message);
  5215. sprintf(tempdata, "Heartbeat,%d", 0);
  5216. 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*/)
  5217. {
  5218. result = PASS;
  5219. }
  5220. return result;
  5221. }
  5222. int sendStartTransactionRequest(int gun_index)
  5223. {
  5224. mtrace();
  5225. int result = FAIL;
  5226. char message[250]={0};
  5227. char guid[37]={0};
  5228. struct timeval tmnow;
  5229. struct tm *tm;
  5230. char buf[28];//, usec_buf[6];
  5231. char tempdata[65]={0};
  5232. int tempIndex = 0;
  5233. DEBUG_INFO("sendStartTransactionRequest...\n");
  5234. gettimeofday(&tmnow, NULL);
  5235. time_t t;
  5236. t = time(NULL);
  5237. /*UTC time and date*/
  5238. tm = gmtime(&t);
  5239. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5240. #if 0 // remove temporally
  5241. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5242. strcat(buf,".");
  5243. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5244. strcat(buf,usec_buf);
  5245. #endif
  5246. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  5247. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  5248. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5249. // clear StartTransaction Response
  5250. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  5251. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  5252. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  5253. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  5254. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5255. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5256. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5257. {
  5258. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5259. {
  5260. tempIndex = ((gun_index==2) ? 1: 0);
  5261. }
  5262. else
  5263. {
  5264. tempIndex = gun_index;
  5265. }
  5266. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5267. {
  5268. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5269. {
  5270. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5271. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  5272. }
  5273. }
  5274. }
  5275. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5276. {
  5277. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5278. {
  5279. tempIndex = ((gun_index==2) ? 1: 0);
  5280. }
  5281. else
  5282. {
  5283. tempIndex = gun_index;
  5284. }
  5285. for (int index = 0; index < CCS_QUANTITY; index++)
  5286. {
  5287. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5288. {
  5289. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5290. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  5291. }
  5292. }
  5293. }
  5294. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5295. {
  5296. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5297. {
  5298. tempIndex = ((gun_index==2) ? 1: 0);
  5299. }
  5300. else
  5301. {
  5302. tempIndex = gun_index;
  5303. }
  5304. for (int index = 0; index < GB_QUANTITY; index++)
  5305. {
  5306. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5307. {
  5308. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5309. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  5310. }
  5311. }
  5312. }
  5313. else if(gunType[gun_index] == GUN_TYPE_DO)
  5314. {
  5315. tempIndex = gun_index;
  5316. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5317. {
  5318. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5319. {
  5320. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5321. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5322. }
  5323. }
  5324. }
  5325. else
  5326. {
  5327. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5328. {
  5329. tempIndex = 2;
  5330. }
  5331. else
  5332. {
  5333. tempIndex = gun_index;
  5334. }
  5335. for (int index = 0; index < AC_QUANTITY; index++)
  5336. {
  5337. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5338. {
  5339. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5340. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5341. }
  5342. }
  5343. }
  5344. random_uuid(guid);
  5345. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5346. {
  5347. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5348. , gun_index +1
  5349. , MESSAGE_TYPE_CALL
  5350. , guid
  5351. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5352. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5353. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5354. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5355. }
  5356. else
  5357. {
  5358. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5359. , gun_index +1
  5360. , MESSAGE_TYPE_CALL
  5361. , guid
  5362. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5363. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5364. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5365. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  5366. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5367. }
  5368. #if 1
  5369. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5370. 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*/)
  5371. {
  5372. result = PASS;
  5373. }
  5374. #endif
  5375. strcpy(queuedata, message);
  5376. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5377. OCPP_insert_transaction_msg(YES, queuedata);
  5378. return result;
  5379. }
  5380. int sendStatusNotificationRequest(int gun_index)
  5381. {
  5382. mtrace();
  5383. int result = FAIL;
  5384. char message[600]={0};
  5385. char guid[37];
  5386. int currentStatus = 0;
  5387. struct timeval tmnow;
  5388. struct tm *tm;
  5389. char buf[28];//, usec_buf[6];
  5390. char tempdata[65]={0};
  5391. int tempIndex = 0;
  5392. uint8_t isStateChanged = TRUE;
  5393. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5394. gettimeofday(&tmnow, NULL);
  5395. time_t t;
  5396. t = time(NULL);
  5397. /*UTC time and date*/
  5398. tm = gmtime(&t);
  5399. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5400. #if 0 // remove temporally
  5401. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5402. strcat(buf,".");
  5403. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5404. strcat(buf,usec_buf);
  5405. #endif
  5406. //printf("%s",buf);
  5407. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5408. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5409. // it's option
  5410. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  5411. /*
  5412. enum _SYSTEM_STATUS
  5413. {
  5414. S_BOOTING = 0,
  5415. S_IDLE, = 1
  5416. S_AUTHORIZING, =2
  5417. S_REASSIGN_CHECK, =3
  5418. S_REASSIGN, =4
  5419. S_PRECHARGE, =5
  5420. S_PREPARING_FOR_EV, =6
  5421. S_PREPARING_FOR_EVSE, =7
  5422. S_CHARGING, =8
  5423. S_TERMINATING, =9
  5424. S_COMPLETE, =10
  5425. S_ALARM, =11
  5426. S_FAULT =12
  5427. }
  5428. */
  5429. //check Transaction active
  5430. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5431. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5432. {
  5433. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5434. {
  5435. tempIndex = ((gun_index==2) ? 1: 0);
  5436. }
  5437. else
  5438. {
  5439. tempIndex = gun_index;
  5440. }
  5441. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5442. {
  5443. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5444. {
  5445. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5446. {
  5447. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5448. {
  5449. currentStatus = Preparing; //OCPP Status: Preparing
  5450. }
  5451. else
  5452. {
  5453. currentStatus = Available; //OCPP Status: Available
  5454. }
  5455. }
  5456. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5457. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5458. ) //S_PRECHARGE
  5459. {
  5460. currentStatus = Preparing; //OCPP Status: Preparing
  5461. }
  5462. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5463. {
  5464. currentStatus = Charging; //OCPP Status: Charging
  5465. }
  5466. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5467. {
  5468. currentStatus = Finishing; //OCPP Status: Finishing
  5469. }
  5470. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5471. {
  5472. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5473. }
  5474. 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
  5475. {
  5476. currentStatus = Unavailable; //OCPP Status: Unavailable
  5477. }
  5478. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5479. {
  5480. currentStatus = Faulted; //OCPP Status: Faulted
  5481. }
  5482. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5483. {
  5484. currentStatus = Reserved; //OCPP Status: Reserved
  5485. }
  5486. } //end of the same index
  5487. }//end of for CHAdeMO_QUANTITY
  5488. }
  5489. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5490. {
  5491. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5492. {
  5493. tempIndex = ((gun_index==2) ? 1: 0);
  5494. }
  5495. else
  5496. {
  5497. tempIndex = gun_index;
  5498. }
  5499. for (int index = 0; index < CCS_QUANTITY; index++)
  5500. {
  5501. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5502. {
  5503. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5504. {
  5505. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5506. {
  5507. currentStatus = Preparing; //OCPP Status: Preparing
  5508. }
  5509. else
  5510. {
  5511. currentStatus = Available; //OCPP Status: Available
  5512. }
  5513. }
  5514. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5515. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5516. ) //S_PRECHARGE
  5517. {
  5518. currentStatus = Preparing; //OCPP Status: Preparing
  5519. }
  5520. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5521. {
  5522. currentStatus = Charging; //OCPP Status: Charging
  5523. }
  5524. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5525. {
  5526. currentStatus = Finishing; //OCPP Status: Finishing
  5527. }
  5528. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5529. {
  5530. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5531. }
  5532. 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
  5533. {
  5534. currentStatus = Unavailable; //OCPP Status : Unavailable
  5535. }
  5536. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5537. {
  5538. currentStatus = Faulted; //OCPP Status: Faulted
  5539. }
  5540. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5541. {
  5542. currentStatus = Reserved; //OCPP Status: Reserved
  5543. }
  5544. } //end of the same index
  5545. } // end of for CCS_QUANTITY
  5546. }
  5547. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5548. {
  5549. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5550. {
  5551. tempIndex = ((gun_index==2) ? 1: 0);
  5552. }
  5553. else
  5554. {
  5555. tempIndex = gun_index;
  5556. }
  5557. for (int index = 0; index < GB_QUANTITY; index++)
  5558. {
  5559. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5560. {
  5561. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5562. {
  5563. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5564. {
  5565. currentStatus = Preparing; //OCPP Status: Preparing
  5566. }
  5567. else
  5568. {
  5569. currentStatus = Available; //OCPP Status: Available
  5570. }
  5571. }
  5572. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5573. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5574. ) //S_PRECHARGE
  5575. {
  5576. currentStatus = Preparing; //OCPP Status: Preparing
  5577. }
  5578. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5579. {
  5580. currentStatus = Charging; //OCPP Status: Charging
  5581. }
  5582. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5583. {
  5584. currentStatus = Finishing; //OCPP Status: Finishing
  5585. }
  5586. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5587. {
  5588. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5589. }
  5590. 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
  5591. {
  5592. currentStatus = Unavailable; //OCPP Status: Unavailable
  5593. }
  5594. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5595. {
  5596. currentStatus = Faulted; //OCPP Status: Faulted
  5597. }
  5598. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5599. {
  5600. currentStatus = Reserved; //OCPP Status: Reserved
  5601. }
  5602. } //end of the same index
  5603. } // end of for GB_QUANTITY
  5604. }
  5605. else if(gunType[gun_index] == GUN_TYPE_DO)
  5606. {
  5607. tempIndex = gun_index;
  5608. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5609. {
  5610. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5611. {
  5612. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5613. {
  5614. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5615. {
  5616. currentStatus = Preparing; //OCPP Status: Preparing
  5617. }
  5618. else
  5619. {
  5620. currentStatus = Available; //OCPP Status: Available
  5621. }
  5622. }
  5623. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5624. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5625. ) //S_PRECHARGE
  5626. {
  5627. currentStatus = Preparing; //OCPP Status: Preparing
  5628. }
  5629. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5630. {
  5631. currentStatus = Charging; //OCPP Status: Charging
  5632. }
  5633. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5634. {
  5635. currentStatus = Finishing; //OCPP Status: Finishing
  5636. }
  5637. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5638. {
  5639. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5640. }
  5641. 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
  5642. {
  5643. currentStatus = Unavailable; //OCPP Status: Unavailable
  5644. }
  5645. 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
  5646. {
  5647. currentStatus = Faulted; //OCPP Status: Faulted
  5648. }
  5649. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5650. {
  5651. currentStatus = Reserved; //OCPP Status: Reserved
  5652. }
  5653. } //end of the same index
  5654. }
  5655. }
  5656. else
  5657. {
  5658. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5659. {
  5660. tempIndex = 2;
  5661. }
  5662. else
  5663. {
  5664. tempIndex = gun_index;
  5665. }
  5666. for (int index = 0; index < AC_QUANTITY; index++)
  5667. {
  5668. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5669. {
  5670. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5671. {
  5672. 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))
  5673. {
  5674. currentStatus = Preparing; //OCPP Status: Preparing
  5675. }
  5676. else
  5677. {
  5678. currentStatus = Available; //OCPP Status: Available
  5679. }
  5680. }
  5681. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5682. {
  5683. currentStatus = Preparing; //OCPP Status: Preparing
  5684. }
  5685. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5686. {
  5687. currentStatus = Charging; //OCPP Status: Charging
  5688. }
  5689. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5690. {
  5691. currentStatus = Finishing; //OCPP Status: Finishing
  5692. }
  5693. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5694. {
  5695. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5696. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5697. else
  5698. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5699. }
  5700. 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
  5701. {
  5702. currentStatus = Unavailable; //OCPP Status: Unavailable
  5703. }
  5704. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5705. {
  5706. currentStatus = Faulted; //OCPP Status: Faulted
  5707. }
  5708. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5709. {
  5710. currentStatus = Reserved; //OCPP Status: Reserved
  5711. }
  5712. }//end of the same index
  5713. }//end of for AC_QUANTITY
  5714. }
  5715. //it's option
  5716. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5717. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5718. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5719. {
  5720. isStateChanged = FALSE;
  5721. }
  5722. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5723. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  5724. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5725. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5726. random_uuid(guid);
  5727. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5728. , MESSAGE_TYPE_CALL
  5729. , guid
  5730. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  5731. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  5732. , ShmOCPP16Data->StatusNotification[gun_index].Info
  5733. , ShmOCPP16Data->StatusNotification[gun_index].Status
  5734. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  5735. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  5736. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  5737. if((server_sign == TRUE) && isStateChanged)
  5738. {
  5739. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5740. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5741. LWS_Send(message);
  5742. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5743. 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*/)
  5744. {
  5745. //DEBUG_ERROR("statusNotification mapitem pass");
  5746. result = PASS;
  5747. }
  5748. }
  5749. else
  5750. {
  5751. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5752. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5753. result = PASS;
  5754. }
  5755. return result;
  5756. }
  5757. int sendStopTransactionRequest(int gun_index)
  5758. {
  5759. mtrace();
  5760. int result = FAIL;
  5761. //char message[1500]={0};
  5762. char guid[37]={0};
  5763. char tempdata[65]={0};
  5764. int tempIndex = 0;
  5765. char TempStopTransaction[256];
  5766. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  5767. //int idx_sample=0;
  5768. DEBUG_INFO("sendStopTransactionRequest \n");
  5769. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5770. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  5771. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5772. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5773. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5774. {
  5775. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5776. {
  5777. tempIndex = ((gun_index==2) ? 1: 0);
  5778. }
  5779. else
  5780. {
  5781. tempIndex = gun_index;
  5782. }
  5783. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5784. {
  5785. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5786. {
  5787. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5788. }
  5789. }// END OF CHAdeMO_QUANTITY
  5790. }
  5791. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5792. {
  5793. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5794. {
  5795. tempIndex = ((gun_index==2) ? 1: 0);
  5796. }
  5797. else
  5798. {
  5799. tempIndex = gun_index;
  5800. }
  5801. for (int index = 0; index < CCS_QUANTITY; index++)
  5802. {
  5803. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5804. {
  5805. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5806. }
  5807. }// END OF CCS_QUANTITY
  5808. }
  5809. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5810. {
  5811. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5812. {
  5813. tempIndex = ((gun_index==2) ? 1: 0);
  5814. }
  5815. else
  5816. {
  5817. tempIndex = gun_index;
  5818. }
  5819. for (int index = 0; index < GB_QUANTITY; index++)
  5820. {
  5821. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5822. {
  5823. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5824. }
  5825. }// END OF GB_QUANTITY
  5826. }
  5827. else if(gunType[gun_index] == GUN_TYPE_DO)
  5828. {
  5829. tempIndex = gun_index;
  5830. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5831. {
  5832. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5833. {
  5834. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5835. }
  5836. }// END OF GB_QUANTITY
  5837. }
  5838. else
  5839. {
  5840. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5841. {
  5842. tempIndex = 2;
  5843. }
  5844. else
  5845. {
  5846. tempIndex = gun_index;
  5847. }
  5848. for (int index = 0; index < AC_QUANTITY; index++)
  5849. {
  5850. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5851. {
  5852. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5853. }
  5854. }// END OF AC_QUANTITY
  5855. }
  5856. //====================================== Stop Transaction Time =====================================================
  5857. struct timeval tmnow;
  5858. struct tm *tm;
  5859. char buf[28];//, usec_buf[6];
  5860. gettimeofday(&tmnow, NULL);
  5861. time_t t;
  5862. t = time(NULL);
  5863. /*UTC time and date*/
  5864. tm = gmtime(&t);
  5865. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5866. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  5867. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  5868. random_uuid(guid);
  5869. /***********************************transactionData******************************************************/
  5870. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5871. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5872. //=================================
  5873. // Transaction_Begin
  5874. //=================================
  5875. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5876. {
  5877. //============================================ Energy.Active.Import.Interval ================================
  5878. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5879. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5880. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5881. 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*/]);
  5882. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5883. 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))
  5884. {
  5885. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5886. }
  5887. else
  5888. {
  5889. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5890. }
  5891. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5892. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5893. }
  5894. //=================================
  5895. // Transaction_End
  5896. //=================================
  5897. // ================================= Current.Import L1 ===============================================
  5898. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5899. {
  5900. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5901. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5902. {
  5903. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5904. {
  5905. tempIndex = ((gun_index==2) ? 1: 0);
  5906. }
  5907. else
  5908. {
  5909. tempIndex = gun_index;
  5910. }
  5911. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5912. {
  5913. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5914. {
  5915. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5916. }
  5917. }// End of for CHAdeMO_QUANTITY
  5918. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5919. }
  5920. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5921. {
  5922. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5923. {
  5924. tempIndex = ((gun_index==2) ? 1: 0);
  5925. }
  5926. else
  5927. {
  5928. tempIndex = gun_index;
  5929. }
  5930. for (int index = 0; index < CCS_QUANTITY; index++)
  5931. {
  5932. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5933. {
  5934. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5935. }
  5936. }// End of for CCS_QUANTITY
  5937. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5938. }
  5939. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5940. {
  5941. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5942. {
  5943. tempIndex = ((gun_index==2) ? 1: 0);
  5944. }
  5945. else
  5946. {
  5947. tempIndex = gun_index;
  5948. }
  5949. for (int index = 0; index < GB_QUANTITY; index++)
  5950. {
  5951. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5952. {
  5953. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5954. }
  5955. }// End of for GB_QUANTITY
  5956. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5957. }
  5958. else if(gunType[gun_index] == GUN_TYPE_DO)
  5959. {
  5960. tempIndex = gun_index;
  5961. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5962. {
  5963. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5964. {
  5965. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5966. }
  5967. }
  5968. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5969. }
  5970. else
  5971. {
  5972. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5973. {
  5974. tempIndex = 2;
  5975. }
  5976. else
  5977. {
  5978. tempIndex = gun_index;
  5979. }
  5980. for (int index = 0; index < AC_QUANTITY; index++)
  5981. {
  5982. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5983. {
  5984. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5985. }
  5986. }// End of for AC_QUANTITY
  5987. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5988. }
  5989. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5990. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5991. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5992. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5993. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5994. }
  5995. // ================================= Energy.Active.Import.Interval ==============================================
  5996. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5997. {
  5998. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5999. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6000. {
  6001. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6002. {
  6003. tempIndex = ((gun_index==2) ? 1: 0);
  6004. }
  6005. else
  6006. {
  6007. tempIndex = gun_index;
  6008. }
  6009. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6010. {
  6011. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6012. {
  6013. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  6014. }
  6015. }// END OF CHAdeMO_QUANTITY
  6016. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6017. }
  6018. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6019. {
  6020. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6021. {
  6022. tempIndex = ((gun_index==2) ? 1: 0);
  6023. }
  6024. else
  6025. {
  6026. tempIndex = gun_index;
  6027. }
  6028. for (int index = 0; index < CCS_QUANTITY; index++)
  6029. {
  6030. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6031. {
  6032. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  6033. }
  6034. }// END OF CCS_QUANTITY
  6035. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6036. }
  6037. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6038. {
  6039. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6040. {
  6041. tempIndex = ((gun_index==2) ? 1: 0);
  6042. }
  6043. else
  6044. {
  6045. tempIndex = gun_index;
  6046. }
  6047. for (int index = 0; index < GB_QUANTITY; index++)
  6048. {
  6049. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6050. {
  6051. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  6052. }
  6053. }// END OF GB_QUANTITY
  6054. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6055. }
  6056. else if(gunType[gun_index] == GUN_TYPE_DO)
  6057. {
  6058. tempIndex = gun_index;
  6059. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6060. {
  6061. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6062. {
  6063. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  6064. }
  6065. }
  6066. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6067. }
  6068. else
  6069. {
  6070. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6071. {
  6072. tempIndex = 2;
  6073. }
  6074. else
  6075. {
  6076. tempIndex = gun_index;
  6077. }
  6078. for (int index = 0; index < AC_QUANTITY; index++)
  6079. {
  6080. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6081. {
  6082. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  6083. }
  6084. }// END OF AC_QUANTITY
  6085. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  6086. }
  6087. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6088. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  6089. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  6090. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  6091. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6092. }
  6093. //=================================== Power.Active.Import ==================================================
  6094. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  6095. {
  6096. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6097. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6098. {
  6099. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6100. {
  6101. tempIndex = ((gun_index==2) ? 1: 0);
  6102. }
  6103. else
  6104. {
  6105. tempIndex = gun_index;
  6106. }
  6107. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6108. {
  6109. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6110. {
  6111. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6112. }
  6113. } // End for CHAdeMO_QUANTITY
  6114. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6115. }
  6116. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6117. {
  6118. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6119. {
  6120. tempIndex = ((gun_index==2) ? 1: 0);
  6121. }
  6122. else
  6123. {
  6124. tempIndex = gun_index;
  6125. }
  6126. for (int index = 0; index < CCS_QUANTITY; index++)
  6127. {
  6128. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6129. {
  6130. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6131. }
  6132. } // END for CCS_QUANTITY
  6133. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6134. }
  6135. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6136. {
  6137. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6138. {
  6139. tempIndex = ((gun_index==2) ? 1: 0);
  6140. }
  6141. else
  6142. {
  6143. tempIndex = gun_index;
  6144. }
  6145. for (int index = 0; index < GB_QUANTITY; index++)
  6146. {
  6147. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6148. {
  6149. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6150. }
  6151. }// END for GB_QUANTITY
  6152. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6153. }
  6154. else if(gunType[gun_index] == GUN_TYPE_DO)
  6155. {
  6156. tempIndex = gun_index;
  6157. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6158. {
  6159. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6160. {
  6161. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6162. }
  6163. }
  6164. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6165. }
  6166. else
  6167. {
  6168. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6169. {
  6170. tempIndex = 2;
  6171. }
  6172. else
  6173. {
  6174. tempIndex = gun_index;
  6175. }
  6176. for (int index = 0; index < AC_QUANTITY; index++)
  6177. {
  6178. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6179. {
  6180. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6181. }
  6182. } // END for AC_QUANTITY
  6183. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  6184. }
  6185. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6186. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  6187. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  6188. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  6189. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  6190. }
  6191. //============================ Voltage L1 ====================================
  6192. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6193. {
  6194. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6195. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6196. {
  6197. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6198. {
  6199. tempIndex = ((gun_index==2) ? 1: 0);
  6200. }
  6201. else
  6202. {
  6203. tempIndex = gun_index;
  6204. }
  6205. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6206. {
  6207. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6208. {
  6209. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6210. }
  6211. } // END OF FOR CHAdeMO_QUANTITY
  6212. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6213. }
  6214. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6215. {
  6216. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6217. {
  6218. tempIndex = ((gun_index==2) ? 1: 0);
  6219. }
  6220. else
  6221. {
  6222. tempIndex = gun_index;
  6223. }
  6224. for (int index = 0; index < CCS_QUANTITY; index++)
  6225. {
  6226. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6227. {
  6228. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6229. }
  6230. } // END OF FOR CCS_QUANTITY
  6231. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6232. }
  6233. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6234. {
  6235. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6236. {
  6237. tempIndex = ((gun_index==2) ? 1: 0);
  6238. }
  6239. else
  6240. {
  6241. tempIndex = gun_index;
  6242. }
  6243. for (int index = 0; index < GB_QUANTITY; index++)
  6244. {
  6245. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6246. {
  6247. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6248. }
  6249. } // END OF FOR GB_QUANTITY
  6250. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6251. }
  6252. else if(gunType[gun_index] == GUN_TYPE_DO)
  6253. {
  6254. tempIndex = gun_index;
  6255. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6256. {
  6257. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6258. {
  6259. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6260. }
  6261. }
  6262. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6263. }
  6264. else
  6265. {
  6266. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6267. {
  6268. tempIndex = 2;
  6269. }
  6270. else
  6271. {
  6272. tempIndex = gun_index;
  6273. }
  6274. for (int index = 0; index < AC_QUANTITY; index++)
  6275. {
  6276. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6277. {
  6278. 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
  6279. }
  6280. } // END OF FOR AC_QUANTITY
  6281. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  6282. }
  6283. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6284. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  6285. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  6286. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  6287. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6288. }
  6289. //====================== End SoC ================================
  6290. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6291. {
  6292. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6293. 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))
  6294. {
  6295. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6296. {
  6297. tempIndex = ((gun_index==2) ? 1: 0);
  6298. }
  6299. else
  6300. {
  6301. tempIndex = gun_index;
  6302. }
  6303. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6304. {
  6305. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6306. {
  6307. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6308. {
  6309. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  6310. }
  6311. }
  6312. }
  6313. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6314. {
  6315. for (int index = 0; index < CCS_QUANTITY; index++)
  6316. {
  6317. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6318. {
  6319. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  6320. }
  6321. }
  6322. }
  6323. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6324. {
  6325. for (int index = 0; index < GB_QUANTITY; index++)
  6326. {
  6327. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6328. {
  6329. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6330. }
  6331. }
  6332. }
  6333. else if(gunType[gun_index] == GUN_TYPE_DO)
  6334. {
  6335. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6336. {
  6337. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6338. {
  6339. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6340. }
  6341. }
  6342. }
  6343. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6344. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6345. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6346. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6347. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6348. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6349. } // END FOR DC CASE
  6350. }
  6351. // ================================= Current.Import L2 ===============================================
  6352. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6353. {
  6354. // AC 3 phse L2 current
  6355. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6356. {
  6357. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6358. {
  6359. tempIndex = 2;
  6360. }
  6361. else
  6362. {
  6363. tempIndex = gun_index;
  6364. }
  6365. for (int index = 0; index < AC_QUANTITY; index++)
  6366. {
  6367. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6368. {
  6369. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6370. }
  6371. }// End of for AC_QUANTITY
  6372. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6373. }
  6374. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6375. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6376. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6377. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6378. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6379. }
  6380. // ================================= Current.Import L3 ===============================================
  6381. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6382. {
  6383. // AC 3 phse L3 current
  6384. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6385. {
  6386. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6387. {
  6388. tempIndex = 2;
  6389. }
  6390. else
  6391. {
  6392. tempIndex = gun_index;
  6393. }
  6394. for (int index = 0; index < AC_QUANTITY; index++)
  6395. {
  6396. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6397. {
  6398. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6399. }
  6400. }// End of for AC_QUANTITY
  6401. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6402. }
  6403. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6404. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6405. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6406. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6407. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6408. }
  6409. //============================ Voltage L2 ====================================
  6410. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6411. {
  6412. // AC 3 phse L2 voltage
  6413. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6414. {
  6415. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6416. {
  6417. tempIndex = 2;
  6418. }
  6419. else
  6420. {
  6421. tempIndex = gun_index;
  6422. }
  6423. for (int index = 0; index < AC_QUANTITY; index++)
  6424. {
  6425. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6426. {
  6427. 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
  6428. }
  6429. } // END OF FOR AC_QUANTITY
  6430. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6431. }
  6432. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6433. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6434. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6435. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6436. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6437. }
  6438. //============================ Voltage L3 ====================================
  6439. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6440. {
  6441. // AC 3 phse L3 voltage
  6442. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6443. {
  6444. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6445. {
  6446. tempIndex = 2;
  6447. }
  6448. else
  6449. {
  6450. tempIndex = gun_index;
  6451. }
  6452. for (int index = 0; index < AC_QUANTITY; index++)
  6453. {
  6454. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6455. {
  6456. 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
  6457. }
  6458. } // END OF FOR AC_QUANTITY
  6459. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6460. }
  6461. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6462. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6463. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6464. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6465. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6466. }
  6467. //====================== Start SoC ================================
  6468. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6469. {
  6470. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6471. 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))
  6472. {
  6473. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6474. {
  6475. tempIndex = ((gun_index==2) ? 1: 0);
  6476. }
  6477. else
  6478. {
  6479. tempIndex = gun_index;
  6480. }
  6481. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6482. {
  6483. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6484. {
  6485. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6486. {
  6487. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6488. }
  6489. }
  6490. }
  6491. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6492. {
  6493. for (int index = 0; index < CCS_QUANTITY; index++)
  6494. {
  6495. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6496. {
  6497. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6498. }
  6499. }
  6500. }
  6501. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6502. {
  6503. for (int index = 0; index < GB_QUANTITY; index++)
  6504. {
  6505. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6506. {
  6507. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6508. }
  6509. }
  6510. }
  6511. else if(gunType[gun_index] == GUN_TYPE_DO)
  6512. {
  6513. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6514. {
  6515. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6516. {
  6517. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6518. }
  6519. }
  6520. }
  6521. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6522. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6523. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6524. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6525. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6526. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6527. } // END FOR DC CASE
  6528. }
  6529. //================================================ Message create ====================================================
  6530. json_object *StopTransaction = json_object_new_object();
  6531. json_object *transactionDatas = json_object_new_array();
  6532. json_object *sampledValues = json_object_new_array();
  6533. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6534. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6535. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6536. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6537. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6538. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6539. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6540. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  6541. {
  6542. json_object *transactionData = json_object_new_object();
  6543. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6544. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6545. {
  6546. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6547. {
  6548. json_object *sampledValue = json_object_new_object();
  6549. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6550. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6551. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6552. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6553. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6554. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6555. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6556. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6557. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6558. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6559. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6560. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6561. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6562. json_object_array_add(sampledValues, sampledValue);
  6563. }
  6564. }
  6565. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6566. json_object_array_add(transactionDatas, transactionData);
  6567. }
  6568. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6569. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6570. ,MESSAGE_TYPE_CALL
  6571. ,guid
  6572. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6573. json_object_put(StopTransaction);
  6574. #if 1 // for TempStopTransaction
  6575. //Delete TempStopTransaction
  6576. if((access(TempStopTransaction,F_OK))!=-1)
  6577. {
  6578. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6579. }
  6580. #endif
  6581. #if 1
  6582. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6583. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6584. {
  6585. result = PASS;
  6586. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6587. }
  6588. #endif
  6589. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6590. OCPP_insert_transaction_msg(NO, queuedata);
  6591. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6592. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6593. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6594. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6595. {
  6596. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6597. }
  6598. //for test
  6599. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6600. return result;
  6601. }
  6602. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6603. {
  6604. mtrace();
  6605. int result = FAIL;
  6606. char guid[37]={0};
  6607. char tempdata[65]={0};
  6608. int tempIndex = 0;
  6609. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6610. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6611. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6612. //set value
  6613. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6614. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6615. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6616. -1);
  6617. random_uuid(guid);
  6618. //UTC Date time
  6619. struct timeval tmnow;
  6620. struct tm *tm;
  6621. char buf[28];//, usec_buf[6];
  6622. gettimeofday(&tmnow, NULL);
  6623. time_t t;
  6624. t = time(NULL);
  6625. /*UTC time and date*/
  6626. tm = gmtime(&t);
  6627. if(dataType == ReadingContext_Sample_Clock)
  6628. {
  6629. struct tm *tmTarget;
  6630. struct timeb tbTarget;
  6631. tbTarget.time = mktime(tm);
  6632. tbTarget.time -= (atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6633. tmTarget = gmtime(&tbTarget.time);
  6634. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6635. }
  6636. else
  6637. {
  6638. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6639. }
  6640. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6641. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6642. //********************************(1)Current.Import L1************************************************/
  6643. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6644. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6645. (dataType == ReadingContext_Trigger))
  6646. {
  6647. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6648. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6649. {
  6650. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6651. {
  6652. tempIndex = ((gun_index==2) ? 1: 0);
  6653. }
  6654. else
  6655. {
  6656. tempIndex = gun_index;
  6657. }
  6658. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6659. {
  6660. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6661. {
  6662. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6663. }
  6664. }
  6665. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6666. }
  6667. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6668. {
  6669. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6670. {
  6671. tempIndex = ((gun_index==2) ? 1: 0);
  6672. }
  6673. else
  6674. {
  6675. tempIndex = gun_index;
  6676. }
  6677. for (int index = 0; index < CCS_QUANTITY; index++)
  6678. {
  6679. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6680. {
  6681. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6682. }
  6683. }
  6684. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6685. }
  6686. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6687. {
  6688. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6689. {
  6690. tempIndex = ((gun_index==2) ? 1: 0);
  6691. }
  6692. else
  6693. {
  6694. tempIndex = gun_index;
  6695. }
  6696. for (int index = 0; index < GB_QUANTITY; index++)
  6697. {
  6698. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6699. {
  6700. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6701. }
  6702. }
  6703. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6704. }
  6705. else if(gunType[gun_index] == GUN_TYPE_DO)
  6706. {
  6707. tempIndex = gun_index;
  6708. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6709. {
  6710. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6711. {
  6712. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6713. }
  6714. }
  6715. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6716. }
  6717. else
  6718. {
  6719. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6720. {
  6721. tempIndex = 2;
  6722. }
  6723. else
  6724. {
  6725. tempIndex = gun_index;
  6726. }
  6727. for (int index = 0; index < AC_QUANTITY; index++)
  6728. {
  6729. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6730. {
  6731. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6732. }
  6733. }
  6734. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6735. }
  6736. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6737. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6738. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6739. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6740. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6741. }
  6742. //********************************(2)Energy.Active.Import.Register ************************************************/
  6743. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6744. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6745. (dataType == ReadingContext_Trigger))
  6746. {
  6747. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6748. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6749. {
  6750. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6751. {
  6752. tempIndex = ((gun_index==2) ? 1: 0);
  6753. }
  6754. else
  6755. {
  6756. tempIndex = gun_index;
  6757. }
  6758. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6759. {
  6760. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6761. {
  6762. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6763. }
  6764. }
  6765. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  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[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6782. }
  6783. }
  6784. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6785. }
  6786. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6787. {
  6788. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6789. {
  6790. tempIndex = ((gun_index==2) ? 1: 0);
  6791. }
  6792. else
  6793. {
  6794. tempIndex = gun_index;
  6795. }
  6796. for (int index = 0; index < GB_QUANTITY; index++)
  6797. {
  6798. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6799. {
  6800. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6801. }
  6802. }
  6803. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6804. }
  6805. else if(gunType[gun_index] == GUN_TYPE_DO)
  6806. {
  6807. tempIndex = gun_index;
  6808. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6809. {
  6810. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6811. {
  6812. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6813. }
  6814. }
  6815. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6816. }
  6817. else
  6818. {
  6819. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6820. {
  6821. tempIndex = 2;
  6822. }
  6823. else
  6824. {
  6825. tempIndex = gun_index;
  6826. }
  6827. for (int index = 0; index < AC_QUANTITY; index++)
  6828. {
  6829. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6830. {
  6831. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6832. }
  6833. }
  6834. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6835. }
  6836. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6837. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6838. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6839. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6840. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6841. }
  6842. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6843. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6844. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6845. (dataType == ReadingContext_Trigger))
  6846. {
  6847. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6848. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6849. {
  6850. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6851. {
  6852. tempIndex = ((gun_index==2) ? 1: 0);
  6853. }
  6854. else
  6855. {
  6856. tempIndex = gun_index;
  6857. }
  6858. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6859. {
  6860. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6861. {
  6862. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6863. }
  6864. } // END OF FOR CHAdeMO_QUANTITY
  6865. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6866. }
  6867. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6868. {
  6869. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6870. {
  6871. tempIndex = ((gun_index==2) ? 1: 0);
  6872. }
  6873. else
  6874. {
  6875. tempIndex = gun_index;
  6876. }
  6877. for (int index = 0; index < CCS_QUANTITY; index++)
  6878. {
  6879. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6880. {
  6881. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6882. }
  6883. } // END OF CCS_QUANTITY
  6884. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6885. }
  6886. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6887. {
  6888. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6889. {
  6890. tempIndex = ((gun_index==2) ? 1: 0);
  6891. }
  6892. else
  6893. {
  6894. tempIndex = gun_index;
  6895. }
  6896. for (int index = 0; index < GB_QUANTITY; index++)
  6897. {
  6898. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6899. {
  6900. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6901. }
  6902. } // END OF GB_QUANTITY
  6903. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6904. }
  6905. else if(gunType[gun_index] == GUN_TYPE_DO)
  6906. {
  6907. tempIndex = gun_index;
  6908. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6909. {
  6910. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6911. {
  6912. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6913. }
  6914. }
  6915. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6916. }
  6917. else
  6918. {
  6919. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6920. {
  6921. tempIndex = 2;
  6922. }
  6923. else
  6924. {
  6925. tempIndex = gun_index;
  6926. }
  6927. for (int index = 0; index < AC_QUANTITY; index++)
  6928. {
  6929. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6930. {
  6931. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6932. }
  6933. }
  6934. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6935. }
  6936. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6937. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6938. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6939. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6940. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6941. }
  6942. //********************************(4)Power.Active.Import************************************************/
  6943. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6944. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6945. (dataType == ReadingContext_Trigger))
  6946. {
  6947. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6948. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6949. {
  6950. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6951. {
  6952. tempIndex = ((gun_index==2) ? 1: 0);
  6953. }
  6954. else
  6955. {
  6956. tempIndex = gun_index;
  6957. }
  6958. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6959. {
  6960. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6961. {
  6962. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6963. }
  6964. } // END OF FOR
  6965. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6966. }
  6967. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6968. {
  6969. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6970. {
  6971. tempIndex = ((gun_index==2) ? 1: 0);
  6972. }
  6973. else
  6974. {
  6975. tempIndex = gun_index;
  6976. }
  6977. for (int index = 0; index < CCS_QUANTITY; index++)
  6978. {
  6979. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6980. {
  6981. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6982. }
  6983. }
  6984. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6985. }
  6986. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6987. {
  6988. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6989. {
  6990. tempIndex = ((gun_index==2) ? 1: 0);
  6991. }
  6992. else
  6993. {
  6994. tempIndex = gun_index;
  6995. }
  6996. for (int index = 0; index < GB_QUANTITY; index++)
  6997. {
  6998. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6999. {
  7000. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7001. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  7002. }
  7003. }
  7004. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7005. }
  7006. else if(gunType[gun_index] == GUN_TYPE_DO)
  7007. {
  7008. tempIndex = gun_index;
  7009. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7010. {
  7011. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7012. {
  7013. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7014. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  7015. }
  7016. }
  7017. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7018. }
  7019. else
  7020. {
  7021. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7022. {
  7023. tempIndex = 2;
  7024. }
  7025. else
  7026. {
  7027. tempIndex = gun_index;
  7028. }
  7029. for (int index = 0; index < AC_QUANTITY; index++)
  7030. {
  7031. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7032. {
  7033. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  7034. }
  7035. }
  7036. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  7037. }
  7038. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  7039. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  7040. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  7041. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  7042. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  7043. }
  7044. //***********************************************(5)VOLTAGE L1******************************************************/
  7045. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7046. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7047. (dataType == ReadingContext_Trigger))
  7048. {
  7049. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7050. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7051. {
  7052. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7053. {
  7054. tempIndex = ((gun_index==2) ? 1: 0);
  7055. }
  7056. else
  7057. {
  7058. tempIndex = gun_index;
  7059. }
  7060. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7061. {
  7062. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7063. {
  7064. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  7065. }
  7066. }
  7067. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7068. }
  7069. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7070. {
  7071. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7072. {
  7073. tempIndex = ((gun_index==2) ? 1: 0);
  7074. }
  7075. else
  7076. {
  7077. tempIndex = gun_index;
  7078. }
  7079. for (int index = 0; index < CCS_QUANTITY; index++)
  7080. {
  7081. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7082. {
  7083. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  7084. }
  7085. }
  7086. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7087. }
  7088. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7089. {
  7090. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7091. {
  7092. tempIndex = ((gun_index==2) ? 1: 0);
  7093. }
  7094. else
  7095. {
  7096. tempIndex = gun_index;
  7097. }
  7098. for (int index = 0; index < GB_QUANTITY; index++)
  7099. {
  7100. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7101. {
  7102. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  7103. }
  7104. }
  7105. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7106. }
  7107. else if(gunType[gun_index] == GUN_TYPE_DO)
  7108. {
  7109. tempIndex = gun_index;
  7110. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7111. {
  7112. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7113. {
  7114. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  7115. }
  7116. }
  7117. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7118. }
  7119. else
  7120. {
  7121. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7122. {
  7123. tempIndex = 2;
  7124. }
  7125. else
  7126. {
  7127. tempIndex = gun_index;
  7128. }
  7129. for (int index = 0; index < AC_QUANTITY; index++)
  7130. {
  7131. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7132. {
  7133. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  7134. }
  7135. }
  7136. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  7137. }
  7138. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  7139. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  7140. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  7141. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  7142. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7143. }
  7144. //***********************************************(6)SOC******************************************************/
  7145. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7146. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7147. (dataType == ReadingContext_Trigger))
  7148. {
  7149. 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))
  7150. {
  7151. //idx_sample=5;
  7152. //sampledValue = NULL;
  7153. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7154. {
  7155. tempIndex = ((gun_index==2) ? 1: 0);
  7156. }
  7157. else
  7158. {
  7159. tempIndex = gun_index;
  7160. }
  7161. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7162. {
  7163. //tempIndex = ((gun_index==2) ? 1: 0);
  7164. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7165. {
  7166. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7167. {
  7168. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  7169. }
  7170. }
  7171. }
  7172. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7173. {
  7174. //tempIndex = ((gun_index==2) ? 1: 0);
  7175. for (int index = 0; index < CCS_QUANTITY; index++)
  7176. {
  7177. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7178. {
  7179. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  7180. }
  7181. }
  7182. }
  7183. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7184. {
  7185. //tempIndex = ((gun_index==2) ? 1: 0);
  7186. for (int index = 0; index < GB_QUANTITY; index++)
  7187. {
  7188. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7189. {
  7190. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  7191. }
  7192. }
  7193. }
  7194. else if(gunType[gun_index] == GUN_TYPE_DO)
  7195. {
  7196. //tempIndex = ((gun_index==2) ? 1: 0);
  7197. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7198. {
  7199. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7200. {
  7201. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  7202. }
  7203. }
  7204. }
  7205. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  7206. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  7207. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  7208. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  7209. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  7210. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  7211. }
  7212. }
  7213. //********************************(7)Current.Import L2************************************************/
  7214. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7215. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7216. (dataType == ReadingContext_Trigger))
  7217. {
  7218. // Only for AC 3 phase
  7219. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7220. {
  7221. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7222. {
  7223. tempIndex = 2;
  7224. }
  7225. else
  7226. {
  7227. tempIndex = gun_index;
  7228. }
  7229. for (int index = 0; index < AC_QUANTITY; index++)
  7230. {
  7231. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7232. {
  7233. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7234. }
  7235. }
  7236. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7237. }
  7238. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7239. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7240. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7241. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7242. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7243. }
  7244. //********************************(8)Current.Import L3************************************************/
  7245. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7246. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7247. (dataType == ReadingContext_Trigger))
  7248. {
  7249. // Only for AC 3 phase
  7250. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7251. {
  7252. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7253. {
  7254. tempIndex = 2;
  7255. }
  7256. else
  7257. {
  7258. tempIndex = gun_index;
  7259. }
  7260. for (int index = 0; index < AC_QUANTITY; index++)
  7261. {
  7262. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7263. {
  7264. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7265. }
  7266. }
  7267. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7268. }
  7269. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7270. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7271. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7272. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7273. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7274. }
  7275. //***********************************************(9)VOLTAGE L2******************************************************/
  7276. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7277. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7278. (dataType == ReadingContext_Trigger))
  7279. {
  7280. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7281. {
  7282. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7283. {
  7284. tempIndex = 2;
  7285. }
  7286. else
  7287. {
  7288. tempIndex = gun_index;
  7289. }
  7290. for (int index = 0; index < AC_QUANTITY; index++)
  7291. {
  7292. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7293. {
  7294. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7295. }
  7296. }
  7297. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7298. }
  7299. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7300. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7301. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7302. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7303. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7304. }
  7305. //***********************************************(10)VOLTAGE L3******************************************************/
  7306. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7307. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7308. (dataType == ReadingContext_Trigger))
  7309. {
  7310. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7311. {
  7312. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7313. {
  7314. tempIndex = 2;
  7315. }
  7316. else
  7317. {
  7318. tempIndex = gun_index;
  7319. }
  7320. for (int index = 0; index < AC_QUANTITY; index++)
  7321. {
  7322. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7323. {
  7324. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7325. }
  7326. }
  7327. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7328. }
  7329. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7330. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7331. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7332. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7333. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7334. }
  7335. //***********************************************(11)Current.Offered******************************************************/
  7336. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7337. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7338. (dataType == ReadingContext_Trigger))
  7339. {
  7340. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7341. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7342. {
  7343. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7344. {
  7345. tempIndex = ((gun_index==2) ? 1: 0);
  7346. }
  7347. else
  7348. {
  7349. tempIndex = gun_index;
  7350. }
  7351. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7352. {
  7353. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7354. {
  7355. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7356. }
  7357. } // END OF FOR CHAdeMO_QUANTITY
  7358. }
  7359. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7360. {
  7361. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7362. {
  7363. tempIndex = ((gun_index==2) ? 1: 0);
  7364. }
  7365. else
  7366. {
  7367. tempIndex = gun_index;
  7368. }
  7369. for (int index = 0; index < CCS_QUANTITY; index++)
  7370. {
  7371. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7372. {
  7373. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7374. }
  7375. } // END OF CCS_QUANTITY
  7376. }
  7377. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7378. {
  7379. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7380. {
  7381. tempIndex = ((gun_index==2) ? 1: 0);
  7382. }
  7383. else
  7384. {
  7385. tempIndex = gun_index;
  7386. }
  7387. for (int index = 0; index < GB_QUANTITY; index++)
  7388. {
  7389. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7390. {
  7391. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7392. }
  7393. } // END OF GB_QUANTITY
  7394. }
  7395. else if(gunType[gun_index] == GUN_TYPE_DO)
  7396. {
  7397. tempIndex = gun_index;
  7398. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7399. {
  7400. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7401. {
  7402. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7403. }
  7404. }
  7405. }
  7406. else
  7407. {
  7408. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7409. {
  7410. tempIndex = 2;
  7411. }
  7412. else
  7413. {
  7414. tempIndex = gun_index;
  7415. }
  7416. for (int index = 0; index < AC_QUANTITY; index++)
  7417. {
  7418. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7419. {
  7420. uint16_t currentOffer;
  7421. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7422. {
  7423. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7424. }
  7425. else
  7426. {
  7427. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7428. }
  7429. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7430. }
  7431. }
  7432. }
  7433. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7434. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7435. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7436. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7437. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7438. }
  7439. //***********************************************(12)Power.Offered******************************************************/
  7440. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7441. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7442. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7443. {
  7444. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7445. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7446. {
  7447. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7448. {
  7449. tempIndex = ((gun_index==2) ? 1: 0);
  7450. }
  7451. else
  7452. {
  7453. tempIndex = gun_index;
  7454. }
  7455. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7456. {
  7457. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7458. {
  7459. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7460. }
  7461. } // END OF FOR CHAdeMO_QUANTITY
  7462. }
  7463. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7464. {
  7465. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7466. {
  7467. tempIndex = ((gun_index==2) ? 1: 0);
  7468. }
  7469. else
  7470. {
  7471. tempIndex = gun_index;
  7472. }
  7473. for (int index = 0; index < CCS_QUANTITY; index++)
  7474. {
  7475. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7476. {
  7477. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7478. }
  7479. } // END OF CCS_QUANTITY
  7480. }
  7481. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7482. {
  7483. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7484. {
  7485. tempIndex = ((gun_index==2) ? 1: 0);
  7486. }
  7487. else
  7488. {
  7489. tempIndex = gun_index;
  7490. }
  7491. for (int index = 0; index < GB_QUANTITY; index++)
  7492. {
  7493. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7494. {
  7495. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7496. }
  7497. } // END OF GB_QUANTITY
  7498. }
  7499. else if(gunType[gun_index] == GUN_TYPE_DO)
  7500. {
  7501. tempIndex = gun_index;
  7502. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7503. {
  7504. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7505. {
  7506. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7507. }
  7508. }
  7509. }
  7510. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7511. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7512. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7513. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7514. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7515. }
  7516. // Message create ====================================================================================================
  7517. if(TRUE)
  7518. {
  7519. json_object *MeterValueReq = json_object_new_object();
  7520. json_object *MeterValues = json_object_new_array();
  7521. json_object *sampledValues = json_object_new_array();
  7522. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7523. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7524. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7525. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7526. {
  7527. json_object *MeterValue = json_object_new_object();
  7528. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7529. {
  7530. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7531. {
  7532. json_object *sampledValue = json_object_new_object();
  7533. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7534. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7535. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7536. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7537. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7538. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7539. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7540. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7541. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7542. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7543. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7544. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7545. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7546. json_object_array_add(sampledValues, sampledValue);
  7547. }
  7548. }
  7549. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7550. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7551. json_object_array_add(MeterValues, MeterValue);
  7552. }
  7553. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7554. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7555. ,gun_index + 1
  7556. ,MESSAGE_TYPE_CALL
  7557. ,guid
  7558. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7559. json_object_put(MeterValueReq);
  7560. }
  7561. // Put request guid to hash map
  7562. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7563. 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*/)
  7564. {
  7565. result = PASS;
  7566. //DEBUG_INFO("MeterValues mapitem pass\n");
  7567. }
  7568. if((dataType != ReadingContext_Trigger) &&
  7569. (dataType != ReadingContext_Sample_Clock) &&
  7570. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7571. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7572. else
  7573. {
  7574. if(FirstHeartBeat)
  7575. LWS_Send(queuedata +2);
  7576. }
  7577. return result;
  7578. }
  7579. int sendLogStatusNotificationRequest(char *status)
  7580. {
  7581. mtrace();
  7582. int result = PASS;
  7583. char message[4096]={0};
  7584. char guid[37]={0};
  7585. char tempdata[128]={0};
  7586. json_object *LogStatusNotification = json_object_new_object();
  7587. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7588. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7589. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7590. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7591. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7592. random_uuid(guid);
  7593. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7594. json_object_put(LogStatusNotification);
  7595. LWS_Send(message);
  7596. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7597. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7598. {
  7599. result = PASS;
  7600. }
  7601. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7602. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7603. return result;
  7604. }
  7605. int sendSecurityEventNotificationRequest()
  7606. {
  7607. mtrace();
  7608. int result = PASS;
  7609. char message[4096]={0};
  7610. char guid[37]={0};
  7611. char tempdata[128]={0};
  7612. json_object *SecurityEventNotification = json_object_new_object();
  7613. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7614. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7615. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7616. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7617. random_uuid(guid);
  7618. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7619. json_object_put(SecurityEventNotification);
  7620. LWS_Send(message);
  7621. sprintf(tempdata, "SecurityEventNotification,0");
  7622. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7623. {
  7624. result = PASS;
  7625. }
  7626. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7627. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7628. return result;
  7629. }
  7630. int sendSignCertificateRequest()
  7631. {
  7632. mtrace();
  7633. int result = PASS;
  7634. char message[4096]={0};
  7635. char guid[37]={0};
  7636. char tempdata[128]={0};
  7637. json_object *SignCertificate = json_object_new_object();
  7638. DEBUG_INFO("sendSignCertificateRequest...\n");
  7639. // Read csr file content
  7640. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7641. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  7642. char *line = NULL;
  7643. size_t len = 0;
  7644. while(getline(&line, &len, fp) != -1)
  7645. {
  7646. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7647. {
  7648. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7649. }
  7650. }
  7651. fclose(fp);
  7652. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7653. random_uuid(guid);
  7654. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7655. json_object_put(SignCertificate);
  7656. LWS_Send(message);
  7657. sprintf(tempdata, "SignCertificate,0");
  7658. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7659. {
  7660. result = PASS;
  7661. }
  7662. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7663. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7664. return result;
  7665. }
  7666. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7667. {
  7668. mtrace();
  7669. int result = PASS;
  7670. char message[110]={0};
  7671. char guid[37]={0};
  7672. char tempdata[65]={0};
  7673. json_object *FirmwareStatusNotification = json_object_new_object();
  7674. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7675. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7676. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7677. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7678. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7679. random_uuid(guid);
  7680. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7681. json_object_put(FirmwareStatusNotification);
  7682. LWS_Send(message);
  7683. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7684. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7685. {
  7686. result = PASS;
  7687. }
  7688. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7689. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7690. return result;
  7691. }
  7692. //==========================================
  7693. // send confirm routine
  7694. //==========================================
  7695. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7696. {
  7697. mtrace();
  7698. int result = FAIL;
  7699. char message[100]={0};
  7700. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7701. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7702. LWS_Send(message);
  7703. result = TRUE;
  7704. return result;
  7705. }
  7706. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7707. {
  7708. mtrace();
  7709. int result = FAIL;
  7710. char message[100]={0};
  7711. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7712. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7713. LWS_Send(message);
  7714. result = TRUE;
  7715. return result;
  7716. }
  7717. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7718. {
  7719. mtrace();
  7720. int result = FAIL;
  7721. char message[100]={0};
  7722. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7723. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7724. LWS_Send(message);
  7725. result = TRUE;
  7726. return result;
  7727. }
  7728. int sendClearCacheConfirmation(char *uuid,char *payload)
  7729. {
  7730. mtrace();
  7731. int result = FAIL;
  7732. char message[500]={0};
  7733. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7734. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7735. LWS_Send(message);
  7736. return result;
  7737. }
  7738. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7739. {
  7740. mtrace();
  7741. int result = FAIL;
  7742. char message[500]={0};
  7743. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7744. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7745. LWS_Send(message);
  7746. return result;
  7747. }
  7748. int sendDataTransferConfirmation(char *uuid,char *payload)
  7749. {
  7750. mtrace();
  7751. char statusStr[20]={0};
  7752. char dataStr[10]={0};
  7753. char sstr[20]={0};
  7754. int c = 0;
  7755. char *loc;
  7756. int result = FAIL;
  7757. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7758. /**********************status**************************/
  7759. loc = strstr(payload, "status");
  7760. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7761. c = 0;
  7762. while (loc[3+strlen("status")+c] != '\"')
  7763. {
  7764. sstr[c] = loc[3+strlen("status")+c];
  7765. c++;
  7766. }
  7767. sstr[c] = '\0';
  7768. strcpy(statusStr, sstr);
  7769. /**********************data**************************/
  7770. loc = strstr(payload, "data");
  7771. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7772. c = 0;
  7773. while (loc[3+strlen("data")+c] != '\"')
  7774. {
  7775. sstr[c] = loc[3+strlen("data")+c];
  7776. c++;
  7777. }
  7778. sstr[c] = '\0';
  7779. strcpy(dataStr, sstr);
  7780. return result;
  7781. }
  7782. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7783. {
  7784. mtrace();
  7785. int result = FAIL;
  7786. char message[1000]={0};
  7787. int CompositeScheduleIndex = 0;
  7788. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7789. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7790. if(nPeriod == 0)
  7791. {
  7792. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7793. {
  7794. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7795. ,MESSAGE_TYPE_CALLRESULT
  7796. ,uuid
  7797. ,payload
  7798. ,connectorIdInt);
  7799. }
  7800. else
  7801. {
  7802. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7803. ,MESSAGE_TYPE_CALLRESULT
  7804. ,uuid
  7805. ,payload
  7806. ,connectorIdInt
  7807. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7808. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7809. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7810. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7811. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7812. }
  7813. }
  7814. else
  7815. {
  7816. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7817. ,MESSAGE_TYPE_CALLRESULT
  7818. ,uuid
  7819. ,payload
  7820. ,connectorIdInt
  7821. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7822. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7823. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7824. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7825. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7826. {
  7827. if (idx_sample == 0)
  7828. {
  7829. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7830. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7831. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7832. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7833. }
  7834. else
  7835. {
  7836. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7837. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7838. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7839. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7840. }
  7841. }
  7842. sprintf(message + strlen(message), "]}}]");
  7843. }
  7844. LWS_Send(message);
  7845. result = TRUE;
  7846. return result;
  7847. }
  7848. int sendGetConfigurationConfirmation(char *uuid)
  7849. {
  7850. mtrace();
  7851. int result = FAIL;
  7852. int MaxKeySupported = 0;
  7853. int sentConfigurationNumber= 0;
  7854. int sentunConfigurationNumber= 0;
  7855. char message[1024*10]={0};
  7856. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7857. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7858. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7859. ,MESSAGE_TYPE_CALLRESULT
  7860. ,uuid );
  7861. //configuration key
  7862. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7863. {
  7864. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7865. {
  7866. if (sentConfigurationNumber == 0)
  7867. {
  7868. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7869. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7870. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7871. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7872. }
  7873. else
  7874. {
  7875. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7876. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7877. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7878. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7879. }
  7880. sentConfigurationNumber = sentConfigurationNumber + 1;
  7881. }
  7882. }
  7883. sprintf(message + strlen(message), "]");
  7884. if(UnknownKeynum != 0)
  7885. {
  7886. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7887. //unkown key
  7888. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7889. {
  7890. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7891. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7892. if(sentunConfigurationNumber == 0)
  7893. {
  7894. sprintf(message + strlen(message), "\"%s\""
  7895. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7896. }
  7897. else
  7898. {
  7899. sprintf(message + strlen(message), ",\"%s\""
  7900. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7901. }
  7902. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7903. }
  7904. sprintf(message + strlen(message), "]");
  7905. }
  7906. sprintf(message + strlen(message), "}]");
  7907. LWS_Send(message);
  7908. return result;
  7909. }
  7910. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7911. {
  7912. mtrace();
  7913. int result = FAIL;
  7914. char message[400]={0};
  7915. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7916. if(strcmp(payload,"")==0)
  7917. {
  7918. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7919. }
  7920. else
  7921. {
  7922. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7923. }
  7924. LWS_Send(message);
  7925. result = TRUE;
  7926. return result;
  7927. }
  7928. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7929. {
  7930. mtrace();
  7931. int result = FAIL;
  7932. char message[80]={0};
  7933. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7934. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  7935. LWS_Send(message);
  7936. result = TRUE;
  7937. return result;
  7938. }
  7939. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7940. {
  7941. mtrace();
  7942. int result = FAIL;
  7943. char message[80]={0};
  7944. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7945. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7946. LWS_Send(message);
  7947. result = TRUE;
  7948. return result;
  7949. }
  7950. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7951. {
  7952. mtrace();
  7953. int result = FAIL;
  7954. char message[80]={0};
  7955. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7956. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7957. LWS_Send(message);
  7958. result = TRUE;
  7959. return result;
  7960. }
  7961. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7962. {
  7963. mtrace();
  7964. int result = FAIL;
  7965. char message[80]={0};
  7966. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7967. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7968. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7969. LWS_Send(message);
  7970. result = TRUE;
  7971. return result;
  7972. }
  7973. int sendResetConfirmation(char *uuid,char *payload)
  7974. {
  7975. mtrace();
  7976. int result = FAIL;
  7977. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7978. char message[80]={0};
  7979. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  7980. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7981. LWS_Send(message);
  7982. result = TRUE;
  7983. return result;
  7984. }
  7985. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7986. {
  7987. mtrace();
  7988. int result = FAIL;
  7989. char message[500]={0};
  7990. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7991. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7992. LWS_Send(message);
  7993. result = TRUE;
  7994. return result;
  7995. }
  7996. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7997. {
  7998. mtrace();
  7999. int result = FAIL;
  8000. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  8001. char message[80]={0};
  8002. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  8003. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8004. LWS_Send(message);
  8005. result = TRUE;
  8006. return result;
  8007. }
  8008. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  8009. {
  8010. mtrace();
  8011. int result = FAIL;
  8012. char message[80]={0};
  8013. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  8014. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8015. LWS_Send(message);
  8016. result = TRUE;
  8017. return result;
  8018. }
  8019. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  8020. {
  8021. mtrace();
  8022. int result = FAIL;
  8023. char message[80]={0};
  8024. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8025. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  8026. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8027. LWS_Send(message);
  8028. result = TRUE;
  8029. return result;
  8030. }
  8031. int sendUpdateFirmwareConfirmation(char *uuid)
  8032. {
  8033. mtrace();
  8034. int result = FAIL;
  8035. char message[60]={0};
  8036. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8037. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  8038. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8039. LWS_Send(message);
  8040. result = TRUE;
  8041. return result;
  8042. }
  8043. int sendCertificateSignedConfirmation(char *uuid)
  8044. {
  8045. mtrace();
  8046. int result = PASS;
  8047. char message[4096]={0};
  8048. json_object *CertificateSigned = json_object_new_object();
  8049. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  8050. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  8051. sprintf(message,"[%d,\"%s\",%s]"
  8052. ,MESSAGE_TYPE_CALLRESULT
  8053. ,uuid
  8054. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  8055. json_object_put(CertificateSigned);
  8056. LWS_Send(message);
  8057. return result;
  8058. }
  8059. int sendDeleteCertificateConfirmation(char *uuid)
  8060. {
  8061. mtrace();
  8062. int result = PASS;
  8063. char message[4096]={0};
  8064. json_object *DeleteCertificate = json_object_new_object();
  8065. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  8066. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  8067. sprintf(message,"[%d,\"%s\",%s]"
  8068. ,MESSAGE_TYPE_CALLRESULT
  8069. ,uuid
  8070. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  8071. json_object_put(DeleteCertificate);
  8072. LWS_Send(message);
  8073. return result;
  8074. }
  8075. int sendExtendedTriggerMessageConfirmation(char *uuid)
  8076. {
  8077. mtrace();
  8078. int result = PASS;
  8079. char message[4096]={0};
  8080. json_object *ExtendedTriggerMessage = json_object_new_object();
  8081. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  8082. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  8083. sprintf(message,"[%d,\"%s\",%s]"
  8084. ,MESSAGE_TYPE_CALLRESULT
  8085. ,uuid
  8086. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  8087. json_object_put(ExtendedTriggerMessage);
  8088. LWS_Send(message);
  8089. return result;
  8090. }
  8091. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  8092. {
  8093. mtrace();
  8094. int result = PASS;
  8095. char message[4096]={0};
  8096. json_object *GetInstalledCertificateIds = json_object_new_object();
  8097. json_object *certificateHashDataDatas = json_object_new_array();
  8098. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  8099. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  8100. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  8101. {
  8102. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  8103. {
  8104. json_object *certificateHashData = json_object_new_object();
  8105. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  8106. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  8107. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  8108. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  8109. json_object_array_add(certificateHashDataDatas, certificateHashData);
  8110. }
  8111. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  8112. }
  8113. else
  8114. {
  8115. json_object_put(certificateHashDataDatas);
  8116. }
  8117. sprintf(message,"[%d,\"%s\",%s]"
  8118. ,MESSAGE_TYPE_CALLRESULT
  8119. ,uuid
  8120. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  8121. json_object_put(GetInstalledCertificateIds);
  8122. LWS_Send(message);
  8123. return result;
  8124. }
  8125. int sendGetLogConfirmation(char *uuid)
  8126. {
  8127. mtrace();
  8128. int result = PASS;
  8129. char message[4096]={0};
  8130. json_object *GetLog = json_object_new_object();
  8131. DEBUG_INFO("sendGetLogConfirmation...\n");
  8132. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  8133. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  8134. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  8135. sprintf(message,"[%d,\"%s\",%s]"
  8136. ,MESSAGE_TYPE_CALLRESULT
  8137. ,uuid
  8138. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  8139. json_object_put(GetLog);
  8140. LWS_Send(message);
  8141. return result;
  8142. }
  8143. int sendInstallCertificateConfirmation(char *uuid)
  8144. {
  8145. mtrace();
  8146. int result = PASS;
  8147. char message[4096]={0};
  8148. json_object *InstallCertificate = json_object_new_object();
  8149. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  8150. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  8151. sprintf(message,"[%d,\"%s\",%s]"
  8152. ,MESSAGE_TYPE_CALLRESULT
  8153. ,uuid
  8154. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  8155. json_object_put(InstallCertificate);
  8156. LWS_Send(message);
  8157. return result;
  8158. }
  8159. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  8160. {
  8161. mtrace();
  8162. int result = PASS;
  8163. char message[4096]={0};
  8164. json_object *SignedUpdateFirmware = json_object_new_object();
  8165. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  8166. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  8167. sprintf(message,"[%d,\"%s\",%s]"
  8168. ,MESSAGE_TYPE_CALLRESULT
  8169. ,uuid
  8170. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  8171. json_object_put(SignedUpdateFirmware);
  8172. LWS_Send(message);
  8173. return result;
  8174. }
  8175. int sendUnknownConfirmation(char *uuid)
  8176. {
  8177. mtrace();
  8178. int result = PASS;
  8179. char message[256]={0};
  8180. DEBUG_INFO("sendUnknownConfirmation...\n");
  8181. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  8182. LWS_Send(message);
  8183. return result;
  8184. }
  8185. //==========================================
  8186. // Handle server request routine Start
  8187. //==========================================
  8188. int handleCancelReservationRequest(char *uuid, char *payload)
  8189. {
  8190. mtrace();
  8191. int result = FAIL;
  8192. int gunNO = 0;
  8193. int reservationIdInt = -1;
  8194. char comfirmstr[20];
  8195. DEBUG_INFO("handleCancelReservationRequest...\n");
  8196. json_object *CancelReservation;
  8197. CancelReservation = json_tokener_parse(payload);
  8198. if(!is_error(CancelReservation))
  8199. {
  8200. // Required data
  8201. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  8202. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  8203. }
  8204. json_object_put(CancelReservation);
  8205. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  8206. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8207. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  8208. if(reservationIdInt != -1)
  8209. {
  8210. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8211. //check Transaction active
  8212. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8213. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8214. {
  8215. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  8216. {
  8217. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8218. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8219. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8220. {
  8221. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8222. }
  8223. else
  8224. {
  8225. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8226. }
  8227. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8228. goto end;
  8229. }
  8230. }
  8231. for (int index = 0; index < CCS_QUANTITY; index++)
  8232. {
  8233. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8234. {
  8235. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8236. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8237. if(gunType[2] == GUN_TYPE_CCS)
  8238. {
  8239. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8240. }
  8241. else
  8242. {
  8243. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8244. }
  8245. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8246. goto end;
  8247. }
  8248. }
  8249. for (int index = 0; index < GB_QUANTITY; index++)
  8250. {
  8251. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8252. {
  8253. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8254. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8255. if(gunType[2] == GUN_TYPE_GBT)
  8256. {
  8257. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8258. }
  8259. else
  8260. {
  8261. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8262. }
  8263. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8264. goto end;
  8265. }
  8266. }
  8267. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8268. {
  8269. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8270. {
  8271. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8272. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8273. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8274. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8275. goto end;
  8276. }
  8277. }
  8278. for (int index = 0; index < AC_QUANTITY; index++)
  8279. {
  8280. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8281. {
  8282. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8283. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8284. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8285. {
  8286. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8287. }
  8288. else
  8289. {
  8290. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8291. }
  8292. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8293. goto end;
  8294. }
  8295. }
  8296. }
  8297. //The reservationId does NOT match the reservationId
  8298. sendCancelReservationConfirmation(uuid, comfirmstr);
  8299. end:
  8300. // Fill in ocpp packet uuid
  8301. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  8302. return result;
  8303. }
  8304. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8305. {
  8306. mtrace();
  8307. int result = FAIL;
  8308. int gunIndex = -1;
  8309. char typeStr[16]={0};
  8310. char comfirmstr[20];
  8311. int specificId = FALSE;
  8312. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8313. json_object *ChangeAvailability;
  8314. ChangeAvailability = json_tokener_parse(payload);
  8315. if(!is_error(ChangeAvailability))
  8316. {
  8317. // Required data
  8318. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8319. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8320. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8321. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8322. }
  8323. json_object_put(ChangeAvailability);
  8324. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8325. {
  8326. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8327. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8328. }
  8329. else if(gunIndex == 0)
  8330. {
  8331. for(int i=0; i < gunTotalNumber; i++)
  8332. {
  8333. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8334. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8335. }
  8336. }
  8337. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8338. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8339. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8340. {
  8341. specificId = TRUE;
  8342. }
  8343. if(specificId == FALSE)
  8344. goto end;
  8345. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8346. {
  8347. //----------------------gunIndex is 0 ------------------------------------------------//
  8348. if(gunIndex == 0)
  8349. {
  8350. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8351. {
  8352. for(int i=0; i < gunTotalNumber; i++)
  8353. {
  8354. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8355. {
  8356. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8357. {
  8358. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8359. {
  8360. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8361. goto end;
  8362. }
  8363. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8364. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8365. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8366. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8367. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8368. {
  8369. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8370. goto end;
  8371. }
  8372. }
  8373. }//END FOR CHAdeMO_QUANTITY
  8374. for (int index = 0; index < CCS_QUANTITY; index++)
  8375. {
  8376. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8377. {
  8378. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8379. {
  8380. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8381. goto end;
  8382. }
  8383. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8384. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8385. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8386. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8387. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8388. {
  8389. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8390. goto end;
  8391. }
  8392. }
  8393. }//END FOR CCS_QUANTITY
  8394. for (int index = 0; index < GB_QUANTITY; index++)
  8395. {
  8396. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8397. {
  8398. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8399. {
  8400. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8401. goto end;
  8402. }
  8403. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8404. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8405. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8406. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8407. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8408. {
  8409. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8410. goto end;
  8411. }
  8412. }
  8413. }// END FOR GB_QUANTITY
  8414. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8415. {
  8416. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8417. {
  8418. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8419. {
  8420. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8421. goto end;
  8422. }
  8423. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8424. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8425. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8426. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8427. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8428. {
  8429. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8430. goto end;
  8431. }
  8432. }
  8433. }// END FOR GENERAL_GUN_QUANTITY
  8434. for (int index = 0; index < AC_QUANTITY; index++)
  8435. {
  8436. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8437. {
  8438. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8439. {
  8440. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8441. goto end;
  8442. }
  8443. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8444. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8445. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8446. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8447. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8448. {
  8449. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8450. goto end;
  8451. }
  8452. }
  8453. }//END FOR AC_QUANTITY
  8454. }// END FOR gunTotalNumber
  8455. }
  8456. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8457. {
  8458. for(int i=0; i < gunTotalNumber; i++)
  8459. {
  8460. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8461. {
  8462. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8463. goto end;
  8464. }
  8465. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8466. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8467. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8468. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8469. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8470. {
  8471. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8472. goto end;
  8473. }
  8474. }
  8475. }
  8476. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8477. goto end;
  8478. }
  8479. //----------------------gunIndex is not 0 ------------------------------------------------//
  8480. //check Transaction active
  8481. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8482. {
  8483. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8484. {
  8485. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8486. {
  8487. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8488. goto end;
  8489. }
  8490. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8491. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8492. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8493. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8494. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8495. {
  8496. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8497. goto end;
  8498. }
  8499. else
  8500. {
  8501. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8502. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8503. goto end;
  8504. }
  8505. }
  8506. }//END FOR CHAdeMO_QUANTITY
  8507. for (int index = 0; index < CCS_QUANTITY; index++)
  8508. {
  8509. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8510. {
  8511. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8512. {
  8513. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8514. goto end;
  8515. }
  8516. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8517. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8518. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8519. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8520. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8521. {
  8522. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8523. goto end;
  8524. }
  8525. else
  8526. {
  8527. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8528. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8529. goto end;
  8530. }
  8531. }
  8532. }//END FOR CCS_QUANTITY
  8533. for (int index = 0; index < GB_QUANTITY; index++)
  8534. {
  8535. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8536. {
  8537. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8538. {
  8539. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8540. goto end;
  8541. }
  8542. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8543. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8544. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8545. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8546. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8547. {
  8548. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8549. goto end;
  8550. }
  8551. else
  8552. {
  8553. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8554. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8555. goto end;
  8556. }
  8557. }
  8558. }// END FOR GB_QUANTITY
  8559. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8560. {
  8561. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8562. {
  8563. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8564. {
  8565. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8566. goto end;
  8567. }
  8568. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8569. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8570. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8571. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8572. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8573. {
  8574. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8575. goto end;
  8576. }
  8577. else
  8578. {
  8579. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8580. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8581. goto end;
  8582. }
  8583. }
  8584. }// END FOR GENERAL_GUN_QUANTITY
  8585. for (int index = 0; index < AC_QUANTITY; index++)
  8586. {
  8587. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8588. {
  8589. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8590. {
  8591. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8592. goto end;
  8593. }
  8594. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8595. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8596. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8597. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8598. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8599. {
  8600. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8601. goto end;
  8602. }
  8603. else
  8604. {
  8605. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8606. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8607. goto end;
  8608. }
  8609. }
  8610. }//END FOR AC_QUANTITY
  8611. }//END FOR AvailabilityTypeStr[Inoperative]
  8612. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8613. {
  8614. //----------------------gunIndex is 0 ------------------------------------------------//
  8615. if(gunIndex == 0)
  8616. {
  8617. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8618. {
  8619. for(int i=0; i < gunTotalNumber; i++)
  8620. {
  8621. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8622. {
  8623. 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
  8624. {
  8625. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8626. goto end;
  8627. }
  8628. }//END FOR CHAdeMO_QUANTITY
  8629. for (int index = 0; index < CCS_QUANTITY; index++)
  8630. {
  8631. 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
  8632. {
  8633. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8634. goto end;
  8635. }
  8636. }//END FOR CCS_QUANTITY
  8637. for (int index = 0; index < GB_QUANTITY; index++)
  8638. {
  8639. 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
  8640. {
  8641. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8642. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8643. goto end;
  8644. }
  8645. }// END FOR GB_QUANTITY
  8646. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8647. {
  8648. 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
  8649. {
  8650. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8651. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8652. goto end;
  8653. }
  8654. }// END FOR GENERAL_GUN_QUANTITY
  8655. for (int index = 0; index < AC_QUANTITY; index++)
  8656. {
  8657. 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
  8658. {
  8659. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8660. goto end;
  8661. }
  8662. }//END FOR CHAdeMO_QUANTITY
  8663. }// END FOR gunTotalNumber
  8664. }
  8665. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8666. {
  8667. for(int i=0; i < gunTotalNumber; i++)
  8668. {
  8669. for (int index = 0; index < AC_QUANTITY; index++)
  8670. {
  8671. 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
  8672. {
  8673. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8674. goto end;
  8675. }
  8676. }//END FOR CHAdeMO_QUANTITY
  8677. } // END FOR gunTotalNumber
  8678. }
  8679. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8680. goto end;
  8681. }
  8682. //----------------------gunIndex is not 0 ------------------------------------------------//
  8683. //check Transaction active
  8684. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8685. {
  8686. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8687. {
  8688. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8689. goto end;
  8690. }
  8691. }//END FOR CHAdeMO_QUANTITY
  8692. for (int index = 0; index < CCS_QUANTITY; index++)
  8693. {
  8694. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8695. {
  8696. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8697. goto end;
  8698. }
  8699. }//END FOR CCS_QUANTITY
  8700. for (int index = 0; index < GB_QUANTITY; index++)
  8701. {
  8702. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8703. {
  8704. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8705. goto end;
  8706. }
  8707. }// END FOR GB_QUANTITY
  8708. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8709. {
  8710. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8711. {
  8712. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8713. goto end;
  8714. }
  8715. }// END FOR GENERAL_GUN_QUANTITY
  8716. for (int index = 0; index < AC_QUANTITY; index++)
  8717. {
  8718. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8719. {
  8720. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8721. goto end;
  8722. }
  8723. }//END FOR AC_QUANTITY
  8724. }//END FOR AvailabilityTypeStr[Operative]
  8725. end:
  8726. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8727. {
  8728. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8729. }
  8730. else
  8731. {
  8732. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8733. }
  8734. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8735. {
  8736. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8737. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8738. }
  8739. else if(gunIndex == 0)
  8740. {
  8741. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8742. {
  8743. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8744. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8745. }
  8746. }
  8747. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8748. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8749. return result;
  8750. }
  8751. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8752. {
  8753. mtrace();
  8754. int valueInvalid = NO;
  8755. int result = FAIL;
  8756. char keystr[40]={0};
  8757. char valuestr[501]={0}; //value should be limited in 500 bytes
  8758. char comfirmstr[20]={0};
  8759. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8760. json_object *ChangeConfiguration;
  8761. ChangeConfiguration = json_tokener_parse(payload);
  8762. if(!is_error(ChangeConfiguration))
  8763. {
  8764. // Required data
  8765. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8766. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8767. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8768. {
  8769. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8770. }
  8771. else
  8772. {
  8773. valueInvalid = YES;
  8774. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8775. }
  8776. }
  8777. json_object_put(ChangeConfiguration);
  8778. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  8779. {
  8780. DEBUG_ERROR("Payload is null or value is invalid.\n");
  8781. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8782. }
  8783. else
  8784. {
  8785. int status = setKeyValue(keystr, valuestr);
  8786. switch(status)
  8787. {
  8788. case ConfigurationStatus_Accepted:
  8789. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8790. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  8791. StoreConfigurationTable();
  8792. break;
  8793. case RebootRequired:
  8794. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8795. StoreConfigurationTable();
  8796. break;
  8797. case NotSupported:
  8798. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8799. break;
  8800. case ConfigurationStatus_Rejected:
  8801. default:
  8802. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8803. break;
  8804. }
  8805. }
  8806. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8807. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  8808. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8809. {
  8810. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8811. SetOcppConnStatus(FALSE);
  8812. }
  8813. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8814. {
  8815. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8816. }
  8817. return result;
  8818. }
  8819. int handleClearCacheRequest(char *uuid, char *payload)
  8820. {
  8821. mtrace();
  8822. int result = FAIL;
  8823. char comfirmstr[20];
  8824. char rmFileCmd[100]={0};
  8825. struct stat stats;
  8826. DEBUG_INFO("handleClearCacheRequest...\n");
  8827. stat("/Storage/OCPP", &stats);
  8828. // Check for directory existence
  8829. if (S_ISDIR(stats.st_mode) == 1)
  8830. {}
  8831. else
  8832. {
  8833. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8834. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  8835. system(rmFileCmd);
  8836. }
  8837. if(OCPP_cleanLocalCache())
  8838. {
  8839. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8840. }
  8841. else
  8842. {
  8843. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8844. }
  8845. sendClearCacheConfirmation(uuid, comfirmstr);
  8846. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8847. return result;
  8848. }
  8849. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8850. {
  8851. mtrace();
  8852. int result = FAIL;
  8853. int resultRename;
  8854. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8855. char chargingProfilePurposeStr[26]={0};
  8856. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8857. char tempchargingProfilePurposeStr[26]={0};
  8858. char str[100]={0};
  8859. char fname[200]={0};
  8860. char comfirmstr[20]={0};
  8861. char word[1600]={0};
  8862. int clearflag = FALSE;
  8863. int chargingProfileIdIsNULL = FALSE;
  8864. int connectorIsNULL = FALSE;
  8865. int chargingProfilePurposeIsNULL = FALSE;
  8866. int stackLevelIsNULL = FALSE;
  8867. //int GotoEnd = FALSE;
  8868. FILE *fptr1, *fptr2;
  8869. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  8870. int n_chargingProfile=0;
  8871. int isEmptyFile = FALSE;
  8872. char sLineWord[1600]={0};
  8873. char chargingProfiles[10][100]={0};
  8874. int ChargeProfileCount = 0;
  8875. int ch;
  8876. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8877. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8878. json_object *ClearChargingProfile;
  8879. ClearChargingProfile = json_tokener_parse(payload);
  8880. if(!is_error(ClearChargingProfile))
  8881. {
  8882. // Optional data
  8883. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8884. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8885. else
  8886. chargingProfileIdIsNULL = TRUE;
  8887. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8888. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8889. else
  8890. connectorIsNULL = TRUE;
  8891. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8892. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8893. else
  8894. chargingProfilePurposeIsNULL = TRUE;
  8895. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8896. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8897. else
  8898. stackLevelIsNULL = TRUE;
  8899. }
  8900. json_object_put(ClearChargingProfile);
  8901. if(connectorIsNULL == FALSE)
  8902. {
  8903. switch(connectorIdInt)
  8904. {
  8905. case 0:
  8906. if(chargingProfilePurposeIsNULL == TRUE)
  8907. {
  8908. int l = 0;
  8909. strcpy(fname, ChargePointMaxProfile_JSON);
  8910. if((access(fname,F_OK))!=-1)
  8911. {
  8912. strcpy(chargingProfiles[l], fname);
  8913. l = l + 1;
  8914. }
  8915. strcpy(fname, TxDefaultProfile_0_JSON);
  8916. if((access(fname,F_OK))!=-1)
  8917. {
  8918. strcpy(chargingProfiles[l], fname);
  8919. l = l + 1;
  8920. }
  8921. ChargeProfileCount = l;
  8922. }
  8923. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8924. {
  8925. strcpy(fname, ChargePointMaxProfile_JSON);
  8926. if((access(fname,F_OK))!=-1)
  8927. {
  8928. strcpy(chargingProfiles[0], fname);
  8929. ChargeProfileCount = 1;
  8930. }
  8931. }
  8932. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8933. {
  8934. strcpy(fname, TxDefaultProfile_0_JSON);
  8935. if((access(fname,F_OK))!=-1)
  8936. {
  8937. strcpy(chargingProfiles[0], fname);
  8938. ChargeProfileCount = 1;
  8939. }
  8940. }
  8941. break;
  8942. default:
  8943. if(chargingProfilePurposeIsNULL == TRUE)
  8944. {
  8945. int m = 0;
  8946. memset(fname, 0, ARRAY_SIZE(fname));
  8947. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8948. if((access(fname,F_OK))!=-1)
  8949. {
  8950. strcpy(chargingProfiles[m], fname);
  8951. m = m + 1;
  8952. }
  8953. memset(fname, 0, ARRAY_SIZE(fname));
  8954. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8955. if((access(fname,F_OK))!=-1)
  8956. {
  8957. strcpy(chargingProfiles[m], fname);
  8958. m = m + 1;
  8959. }
  8960. ChargeProfileCount = m;
  8961. }
  8962. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8963. {
  8964. //strcpy(fname, TxDefaultProfile_1_JSON);
  8965. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8966. if((access(fname,F_OK))!=-1)
  8967. {
  8968. strcpy(chargingProfiles[0], fname);
  8969. ChargeProfileCount = 1;
  8970. }
  8971. }
  8972. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8973. {
  8974. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8975. if((access(fname,F_OK))!=-1)
  8976. {
  8977. strcpy(chargingProfiles[0], fname);
  8978. ChargeProfileCount = 1;
  8979. }
  8980. //strcpy(fname, TxProfile_1_JSON);
  8981. }
  8982. //strcpy(fname, ChargePointMaxProfile_JSON );
  8983. break;
  8984. }
  8985. }
  8986. else // Check all Charging Profiles
  8987. {
  8988. int i = 0;
  8989. char fnametemp[200]={0};
  8990. ChargeProfileCount = 0;
  8991. //Check ChargePointMaxProfile.json exit
  8992. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8993. {
  8994. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  8995. i = i + 1;
  8996. }
  8997. //Check TxDefaultProfile_0.json exit
  8998. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8999. {
  9000. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  9001. i = i + 1;
  9002. }
  9003. //Check TxDefaultProfile_%d.json
  9004. for(int j=1; j <= gunTotalNumber; j++)
  9005. {
  9006. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9007. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9008. if((access(fnametemp,F_OK))!=-1)
  9009. {
  9010. strcpy(chargingProfiles[i], fnametemp);
  9011. i = i + 1;
  9012. }
  9013. }
  9014. //Check TxProfile_%d.json
  9015. for(int j=1; j <= gunTotalNumber; j++)
  9016. {
  9017. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9018. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9019. if((access(fnametemp,F_OK))!=-1)
  9020. {
  9021. strcpy(chargingProfiles[i], fnametemp);
  9022. i = i + 1;
  9023. }
  9024. }
  9025. ChargeProfileCount = i;
  9026. }// End connectorIsNULL is TRUE
  9027. if(ChargeProfileCount == 0)
  9028. {
  9029. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9030. goto end;
  9031. }
  9032. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  9033. {
  9034. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9035. goto end;
  9036. }
  9037. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  9038. {
  9039. memset(str, 0, ARRAY_SIZE(str));
  9040. // clear temp file
  9041. sprintf(str,"rm -f %s",temp);
  9042. system(str);
  9043. for(int k=0; k < ChargeProfileCount; k++)
  9044. {
  9045. memset(str, 0, ARRAY_SIZE(str));
  9046. //clear file in C
  9047. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9048. system(str);
  9049. }
  9050. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9051. goto end;
  9052. }
  9053. else if(connectorIsNULL == TRUE)
  9054. {
  9055. for(int k=0; k < ChargeProfileCount; k++)
  9056. {
  9057. fptr1 = fopen(chargingProfiles[k], "r");
  9058. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  9059. //Check Charging Profile Count
  9060. while(fscanf(fptr1, "%s", word) != EOF)
  9061. {
  9062. //DEBUG_INFO("word=%s\n",word);
  9063. if(strstr(word, "chargingProfileId")!= NULL)
  9064. {
  9065. //DEBUG_INFO("test chargingProfileId \n");
  9066. n_chargingProfile = n_chargingProfile + 1;
  9067. //DEBUG_INFO("chargingProfileId Found\n");
  9068. }
  9069. }
  9070. rewind(fptr1);
  9071. //search Charging Profile Element
  9072. //int i= 0;
  9073. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9074. {
  9075. json_object *tmpProfilee;
  9076. tmpProfilee = json_tokener_parse(sLineWord);
  9077. if(!is_error(tmpProfilee))
  9078. {
  9079. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9080. {
  9081. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9082. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9083. }
  9084. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9085. {
  9086. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9087. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9088. }
  9089. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9090. {
  9091. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9092. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9093. }
  9094. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9095. {
  9096. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9097. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9098. }
  9099. }
  9100. json_object_put(tmpProfilee);
  9101. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9102. {
  9103. //------- not write to fptr2-------//
  9104. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9105. //clearflag = TRUE;
  9106. }
  9107. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9108. {
  9109. //------- not write to fptr2-------//
  9110. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9111. }
  9112. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9113. {
  9114. //------- not write to fptr2-------//
  9115. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9116. }
  9117. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  9118. {
  9119. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9120. }
  9121. else
  9122. {
  9123. fprintf(fptr2, sLineWord);//writing data into file
  9124. }
  9125. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9126. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9127. if(clearflag == TRUE)
  9128. {
  9129. fclose(fptr1);
  9130. fclose(fptr2);
  9131. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9132. system(str);
  9133. // clear temp file
  9134. sprintf(str,"rm -f %s",temp);
  9135. system(str);
  9136. }
  9137. else
  9138. {
  9139. fclose(fptr1);
  9140. fclose(fptr2);
  9141. memset(str, 0, ARRAY_SIZE(str));
  9142. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9143. system(str);
  9144. resultRename = rename(temp, chargingProfiles[k]);
  9145. if(resultRename == 0)
  9146. {
  9147. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  9148. }
  9149. else
  9150. {
  9151. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  9152. }
  9153. if(comfirmstr[0]== 0)
  9154. {
  9155. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9156. }
  9157. //Check chargingProfile is empty file
  9158. /*------ Read the file ----------------*/
  9159. fptr1=fopen(chargingProfiles[k],"r");
  9160. ch=fgetc(fptr1);
  9161. rewind(fptr1);
  9162. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9163. if(ch!=EOF)
  9164. {
  9165. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9166. {
  9167. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9168. if(sLineWord[0]=='\0')
  9169. {
  9170. isEmptyFile = TRUE;
  9171. break;
  9172. }
  9173. else
  9174. {
  9175. isEmptyFile = FALSE;
  9176. break;
  9177. }
  9178. }
  9179. }
  9180. else
  9181. isEmptyFile = TRUE;
  9182. fclose(fptr1);
  9183. if(isEmptyFile == TRUE)
  9184. {
  9185. memset(str, 0, ARRAY_SIZE(str));
  9186. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9187. system(str);
  9188. }
  9189. }
  9190. }// End of while(int k=0; k < ChargePointCount; k++)
  9191. }
  9192. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  9193. {
  9194. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  9195. for(int k=0; k < ChargeProfileCount; k++)
  9196. {
  9197. fptr1 = fopen(chargingProfiles[k], "r");
  9198. fptr2 = fopen(temp, "w+");
  9199. //Check Charging Profile Count
  9200. while(fscanf(fptr1, "%s", word) != EOF)
  9201. {
  9202. //DEBUG_INFO("word=%s\n",word);
  9203. if(strstr(word, "chargingProfileId")!= NULL)
  9204. {
  9205. n_chargingProfile = n_chargingProfile + 1;
  9206. }
  9207. }
  9208. rewind(fptr1);
  9209. //search Charging Profile Element
  9210. //int i= 0;
  9211. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9212. {
  9213. json_object *tmpProfilee;
  9214. tmpProfilee = json_tokener_parse(sLineWord);
  9215. if(!is_error(tmpProfilee))
  9216. {
  9217. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9218. {
  9219. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9220. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9221. }
  9222. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9223. {
  9224. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9225. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9226. }
  9227. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9228. {
  9229. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9230. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9231. }
  9232. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9233. {
  9234. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9235. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9236. }
  9237. }
  9238. json_object_put(tmpProfilee);
  9239. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9240. {
  9241. //------- not write to fptr2-------//
  9242. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9243. //clearflag = TRUE;
  9244. }
  9245. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9246. {
  9247. //------- not write to fptr2-------//
  9248. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9249. }
  9250. else if(stackLevelIsNULL == TRUE)
  9251. {
  9252. //Clear Whole File
  9253. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9254. clearflag = TRUE;
  9255. break;
  9256. }
  9257. else
  9258. {
  9259. fprintf(fptr2, sLineWord);//writing data into file
  9260. }
  9261. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9262. }
  9263. if(clearflag == TRUE)
  9264. {
  9265. fclose(fptr1);
  9266. fclose(fptr2);
  9267. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9268. system(str);
  9269. // clear temp file
  9270. sprintf(str,"rm -f %s",temp);
  9271. system(str);
  9272. }
  9273. else
  9274. {
  9275. fclose(fptr1);
  9276. fclose(fptr2);
  9277. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9278. system(str);
  9279. resultRename = rename(temp, chargingProfiles[k]);
  9280. if(resultRename == 0)
  9281. {
  9282. DEBUG_INFO("File ChargingProfile renamed successfully");
  9283. }
  9284. else
  9285. {
  9286. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9287. }
  9288. if(comfirmstr[0]== 0)
  9289. {
  9290. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9291. }
  9292. //Check chargingProfile is empty file
  9293. /*------ Read the file ----------------*/
  9294. fptr1=fopen(chargingProfiles[k],"r");
  9295. ch=fgetc(fptr1);
  9296. rewind(fptr1);
  9297. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9298. if(ch!=EOF)
  9299. {
  9300. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9301. {
  9302. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9303. if(sLineWord[0]=='\0')
  9304. {
  9305. isEmptyFile = TRUE;
  9306. break;
  9307. }
  9308. else
  9309. {
  9310. isEmptyFile = FALSE;
  9311. break;
  9312. }
  9313. }
  9314. }
  9315. else
  9316. isEmptyFile = TRUE;
  9317. fclose(fptr1);
  9318. if(isEmptyFile == TRUE)
  9319. {
  9320. memset(str, 0, ARRAY_SIZE(str));
  9321. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9322. system(str);
  9323. }
  9324. /*------- End of reading ---------------*/
  9325. }
  9326. } // while(int k=0; k < ChargeProfileCount; k++)
  9327. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9328. end:
  9329. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9330. {
  9331. if(connectorIdInt == 0)
  9332. {
  9333. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9334. {
  9335. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9336. }
  9337. }
  9338. else
  9339. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9340. }
  9341. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9342. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9343. return result;
  9344. }
  9345. void createFirmwareVersionByDataTransfer(void)
  9346. {
  9347. json_object *FirmwareDataTransfer = json_object_new_object();
  9348. // AC & DC model
  9349. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9350. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9351. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9352. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9353. // DC model
  9354. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9355. {
  9356. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9357. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9358. (gunType[3] != GUN_TYPE_UNKNOWN))
  9359. {
  9360. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9361. }
  9362. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9363. {
  9364. // DS DM DW
  9365. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9366. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9367. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9368. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9369. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9370. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9371. }
  9372. else
  9373. {
  9374. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9375. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9376. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9377. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9378. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9379. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9380. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9381. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9382. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9383. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9384. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9385. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9386. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9387. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9388. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9389. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9390. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9391. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9392. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9393. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9394. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9395. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9396. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9397. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9398. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9399. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9400. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9401. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9402. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9403. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9404. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9405. }
  9406. }
  9407. // 4G model
  9408. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9409. {
  9410. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9411. }
  9412. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9413. json_object_put(FirmwareDataTransfer);
  9414. }
  9415. int handleDataTransferRequest(char *uuid, char *payload)
  9416. {
  9417. mtrace();
  9418. json_object *response = json_object_new_object();
  9419. int result = FAIL;
  9420. char tempvendorId[255]={0};
  9421. char tempmessageId[50]={0};
  9422. char tempdata[512]={0};
  9423. char message[2048]={0};
  9424. DEBUG_INFO("handleDataTransferRequest...\n");
  9425. if((uuid != NULL) && (payload != NULL))
  9426. {
  9427. json_object *DataTransfer;
  9428. DataTransfer = json_tokener_parse(payload);
  9429. if(!is_error(DataTransfer))
  9430. {
  9431. // Required data
  9432. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9433. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9434. // Optional data
  9435. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9436. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9437. if(json_object_object_get(DataTransfer, "data") != NULL)
  9438. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9439. result = PASS;
  9440. }
  9441. json_object_put(DataTransfer);
  9442. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9443. {
  9444. // Send all moudle firmware version on EVSE
  9445. createFirmwareVersionByDataTransfer();
  9446. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9447. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9448. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9449. json_object_put(response);
  9450. }
  9451. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9452. {
  9453. system("/usr/bin/run_tmate_restart.sh &");
  9454. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9455. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9456. json_object_put(response);
  9457. }
  9458. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9459. {
  9460. json_object *data;
  9461. data = json_tokener_parse(tempdata);
  9462. if(!is_error(data))
  9463. {
  9464. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) <= gunTotalNumber))
  9465. {
  9466. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9467. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9468. if(json_object_object_get(data, "SOC") != NULL)
  9469. {
  9470. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9471. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9472. }
  9473. if(json_object_object_get(data, "Energy") != NULL)
  9474. {
  9475. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9476. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9477. }
  9478. if(json_object_object_get(data, "Duration") != NULL)
  9479. {
  9480. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9481. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9482. }
  9483. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9484. }
  9485. else
  9486. {
  9487. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9488. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9489. }
  9490. }
  9491. else
  9492. {
  9493. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9494. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9495. }
  9496. json_object_put(data);
  9497. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9498. json_object_put(response);
  9499. }
  9500. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9501. {
  9502. json_object *data;
  9503. data = json_tokener_parse(tempdata);
  9504. if(!is_error(data))
  9505. {
  9506. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9507. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9508. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9509. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9510. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9511. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9512. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9513. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9514. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9515. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9516. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9517. }
  9518. else
  9519. {
  9520. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9521. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9522. }
  9523. json_object_put(data);
  9524. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9525. json_object_put(response);
  9526. }
  9527. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9528. {
  9529. json_object *data;
  9530. data = json_tokener_parse(tempdata);
  9531. if(!is_error(data))
  9532. {
  9533. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9534. if(json_object_object_get(data, "idToken") != NULL)
  9535. {
  9536. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9537. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9538. }
  9539. if(json_object_object_get(data, "price") != NULL)
  9540. {
  9541. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9542. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9543. }
  9544. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9545. }
  9546. else
  9547. {
  9548. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9549. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9550. }
  9551. json_object_put(data);
  9552. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9553. json_object_put(response);
  9554. }
  9555. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9556. {
  9557. json_object *data;
  9558. data = json_tokener_parse(tempdata);
  9559. if(!is_error(data))
  9560. {
  9561. if(json_object_object_get(data, "txId") != NULL)
  9562. {
  9563. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9564. for(int idx = 0;idx<gunTotalNumber;idx++)
  9565. {
  9566. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9567. {
  9568. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9569. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9570. if(json_object_object_get(data, "description") != NULL)
  9571. {
  9572. // California pricing V1.0
  9573. DEBUG_INFO("California pricing V1.0\n");
  9574. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9575. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9576. }
  9577. else
  9578. {
  9579. // California pricing V1.1
  9580. DEBUG_INFO("California pricing V1.1\n");
  9581. if(json_object_object_get(data, "timestamp") != NULL)
  9582. {
  9583. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9584. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9585. }
  9586. if(json_object_object_get(data, "meterValue") != NULL)
  9587. {
  9588. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9589. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9590. }
  9591. if(json_object_object_get(data, "cost") != NULL)
  9592. {
  9593. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9594. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9595. }
  9596. if(json_object_object_get(data, "state") != NULL)
  9597. {
  9598. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9599. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9600. }
  9601. if(json_object_object_get(data, "chargingPrice") != NULL)
  9602. {
  9603. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9604. {
  9605. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9606. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9607. }
  9608. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9609. {
  9610. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9611. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9612. }
  9613. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9614. {
  9615. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9616. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9617. }
  9618. }
  9619. if(json_object_object_get(data, "idlePrice") != NULL)
  9620. {
  9621. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9622. {
  9623. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9624. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9625. }
  9626. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9627. {
  9628. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9629. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9630. }
  9631. }
  9632. if(json_object_object_get(data, "nextPeriod") != NULL)
  9633. {
  9634. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9635. {
  9636. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9637. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9638. }
  9639. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9640. {
  9641. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9642. {
  9643. 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")));
  9644. 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"));
  9645. }
  9646. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9647. {
  9648. 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")));
  9649. 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"));
  9650. }
  9651. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9652. {
  9653. 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")));
  9654. 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"));
  9655. }
  9656. }
  9657. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9658. {
  9659. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9660. {
  9661. 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")));
  9662. 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"));
  9663. }
  9664. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9665. {
  9666. 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")));
  9667. 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"));
  9668. }
  9669. }
  9670. }
  9671. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9672. {
  9673. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9674. {
  9675. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9676. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9677. }
  9678. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9679. {
  9680. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9681. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9682. }
  9683. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9684. {
  9685. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9686. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9687. }
  9688. }
  9689. }
  9690. }
  9691. }
  9692. }
  9693. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9694. }
  9695. else
  9696. {
  9697. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9698. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9699. }
  9700. json_object_put(data);
  9701. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9702. json_object_put(response);
  9703. }
  9704. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9705. {
  9706. json_object *data;
  9707. data = json_tokener_parse(tempdata);
  9708. if(!is_error(data))
  9709. {
  9710. if(json_object_object_get(data, "txId") != NULL)
  9711. {
  9712. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9713. for(int idx = 0;idx<gunTotalNumber;idx++)
  9714. {
  9715. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9716. {
  9717. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9718. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9719. if(json_object_object_get(data, "description") != NULL)
  9720. {
  9721. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9722. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9723. }
  9724. }
  9725. }
  9726. }
  9727. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9728. }
  9729. else
  9730. {
  9731. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9732. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9733. }
  9734. json_object_put(data);
  9735. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9736. json_object_put(response);
  9737. }
  9738. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9739. {
  9740. json_object *data;
  9741. data = json_tokener_parse(tempdata);
  9742. if(!is_error(data))
  9743. {
  9744. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9745. if(json_object_object_get(data, "Content_Type") != NULL)
  9746. {
  9747. 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))
  9748. {
  9749. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9750. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9751. {
  9752. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9753. }
  9754. }
  9755. else
  9756. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9757. }
  9758. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9759. }
  9760. else
  9761. {
  9762. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9763. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9764. }
  9765. json_object_put(data);
  9766. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9767. json_object_put(response);
  9768. }
  9769. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9770. {
  9771. json_object *data;
  9772. data = json_tokener_parse(tempdata);
  9773. if(!is_error(data))
  9774. {
  9775. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9776. if(json_object_object_get(data, "ConnectorId") != NULL)
  9777. {
  9778. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9779. }
  9780. if(json_object_object_get(data, "SerialNo") != NULL)
  9781. {
  9782. sprintf((char *)ShmOCPP16Data->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9783. }
  9784. if(json_object_object_get(data, "Page_Index") != NULL)
  9785. {
  9786. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9787. }
  9788. if(json_object_object_get(data, "Duration") != NULL)
  9789. {
  9790. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9791. }
  9792. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9793. }
  9794. else
  9795. {
  9796. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9797. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9798. }
  9799. json_object_put(data);
  9800. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9801. json_object_put(response);
  9802. }
  9803. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9804. {
  9805. json_object *data;
  9806. data = json_tokener_parse(tempdata);
  9807. if(!is_error(data))
  9808. {
  9809. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9810. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9811. {
  9812. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9813. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9814. else
  9815. {
  9816. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9817. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9818. }
  9819. }
  9820. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9821. {
  9822. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9823. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9824. else
  9825. {
  9826. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9827. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9828. }
  9829. }
  9830. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9831. {
  9832. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9833. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9834. else
  9835. {
  9836. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9837. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9838. }
  9839. }
  9840. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9841. {
  9842. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9843. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9844. else
  9845. {
  9846. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9847. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9848. }
  9849. }
  9850. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9851. {
  9852. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9853. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9854. else
  9855. {
  9856. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9857. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9858. }
  9859. }
  9860. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9861. {
  9862. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9863. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9864. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9865. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9866. else
  9867. {
  9868. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9869. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9870. }
  9871. }
  9872. if(json_object_object_get(data, "isAuthentication") != NULL)
  9873. {
  9874. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9875. {
  9876. case 0:
  9877. case 1:
  9878. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9879. break;
  9880. default:
  9881. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9882. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9883. break;
  9884. }
  9885. }
  9886. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9887. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9888. }
  9889. else
  9890. {
  9891. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9892. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9893. }
  9894. json_object_put(data);
  9895. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9896. json_object_put(response);
  9897. }
  9898. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  9899. {
  9900. json_object *data;
  9901. data = json_tokener_parse(tempdata);
  9902. if(!is_error(data))
  9903. {
  9904. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9905. {
  9906. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  9907. {
  9908. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9909. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9910. }
  9911. else
  9912. {
  9913. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9914. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  9915. }
  9916. }
  9917. else
  9918. {
  9919. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9920. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9921. }
  9922. }
  9923. else
  9924. {
  9925. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9926. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9927. }
  9928. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9929. json_object_put(response);
  9930. }
  9931. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9932. {
  9933. json_object *data;
  9934. data = json_tokener_parse(tempdata);
  9935. if(!is_error(data))
  9936. {
  9937. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9938. if(json_object_object_get(data, "stationName") != NULL)
  9939. {
  9940. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9941. }
  9942. else
  9943. {
  9944. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9945. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9946. }
  9947. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9948. {
  9949. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  9950. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9951. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  9952. }
  9953. }
  9954. else
  9955. {
  9956. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9957. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9958. }
  9959. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9960. json_object_put(response);
  9961. }
  9962. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9963. {
  9964. json_object *data;
  9965. data = json_tokener_parse(tempdata);
  9966. if(!is_error(data))
  9967. {
  9968. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9969. if(json_object_object_get(data, "weatherId") != NULL)
  9970. {
  9971. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9972. }
  9973. else
  9974. {
  9975. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9976. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9977. }
  9978. if(json_object_object_get(data, "Temperature") != NULL)
  9979. {
  9980. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9981. }
  9982. else
  9983. {
  9984. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9985. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9986. }
  9987. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9988. {
  9989. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  9990. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9991. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  9992. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  9993. );
  9994. }
  9995. }
  9996. else
  9997. {
  9998. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9999. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  10000. }
  10001. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10002. json_object_put(response);
  10003. }
  10004. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  10005. {
  10006. json_object *data;
  10007. data = json_tokener_parse(tempdata);
  10008. if(!is_error(data))
  10009. {
  10010. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10011. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  10012. {
  10013. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  10014. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  10015. }
  10016. else
  10017. {
  10018. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10019. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  10020. }
  10021. }
  10022. else
  10023. {
  10024. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10025. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10026. }
  10027. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10028. json_object_put(response);
  10029. }
  10030. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  10031. {
  10032. json_object *data;
  10033. data = json_tokener_parse(tempdata);
  10034. if(!is_error(data))
  10035. {
  10036. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10037. {
  10038. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10039. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10040. if(gun_index < gunTotalNumber)
  10041. {
  10042. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10043. {
  10044. json_object *responsedata = json_object_new_object();
  10045. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  10046. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  10047. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  10048. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  10049. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  10050. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10051. }
  10052. else
  10053. {
  10054. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10055. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  10056. }
  10057. }
  10058. else
  10059. {
  10060. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10061. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  10062. }
  10063. }
  10064. else
  10065. {
  10066. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10067. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10068. }
  10069. }
  10070. else
  10071. {
  10072. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10073. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10074. }
  10075. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10076. json_object_put(response);
  10077. }
  10078. else
  10079. {
  10080. // Can not find valid message id
  10081. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  10082. }
  10083. }
  10084. else
  10085. {
  10086. // Payload is null
  10087. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  10088. }
  10089. LWS_Send(message);
  10090. return result;
  10091. }
  10092. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  10093. {
  10094. mtrace();
  10095. int result = FAIL;
  10096. int connectorIdInt, durationInt;
  10097. char chargingRateUnitStr[4]={0};
  10098. char comfirmstr[20];
  10099. int confirmPeriods = 0;
  10100. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  10101. json_object *GetCompositeSchedule;
  10102. GetCompositeSchedule = json_tokener_parse(payload);
  10103. if(!is_error(GetCompositeSchedule))
  10104. {
  10105. // Required data
  10106. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  10107. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  10108. else
  10109. connectorIdInt = -1;
  10110. if(json_object_object_get(GetCompositeSchedule, "duration"))
  10111. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  10112. else
  10113. durationInt = 86400;
  10114. // Optional data
  10115. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  10116. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  10117. }
  10118. json_object_put(GetCompositeSchedule);
  10119. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  10120. if((connectorIdInt == 0) ||
  10121. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  10122. {
  10123. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  10124. struct StructChargingProfile tmpProfile[1];
  10125. if(strstr(chargingRateUnitStr, "W") != NULL)
  10126. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  10127. else
  10128. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  10129. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10130. {
  10131. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10132. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10133. }
  10134. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  10135. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  10136. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  10137. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10138. {
  10139. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10140. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10141. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  10142. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  10143. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  10144. {
  10145. confirmPeriods = idx;
  10146. break;
  10147. }
  10148. }
  10149. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  10150. {
  10151. confirmPeriods += 1;
  10152. }
  10153. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  10154. }
  10155. else
  10156. {
  10157. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  10158. }
  10159. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  10160. return result;
  10161. }
  10162. int handleGetConfigurationRequest(char *uuid, char *payload)
  10163. {
  10164. mtrace();
  10165. int result = FAIL;
  10166. int MaxKeySupported = 0;
  10167. int n_keys = 0;
  10168. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  10169. DEBUG_INFO("handleGetConfigurationRequest...\n");
  10170. json_object *GetConfiguration;
  10171. GetConfiguration = json_tokener_parse(payload);
  10172. if(!is_error(GetConfiguration))
  10173. {
  10174. // Optional data
  10175. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10176. {
  10177. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10178. {
  10179. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10180. n_keys = idx + 1;
  10181. }
  10182. }
  10183. }
  10184. json_object_put(GetConfiguration);
  10185. UnknownKeynum = 0;
  10186. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10187. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10188. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10189. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10190. if(n_keys != 0)
  10191. {
  10192. for(int i=0;i<n_keys;i++)
  10193. {
  10194. getKeyValue(requestKey[i]);
  10195. }
  10196. }
  10197. else
  10198. {
  10199. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10200. getKeyValue("");
  10201. }
  10202. processUnkownKey();
  10203. sendGetConfigurationConfirmation(uuid);
  10204. return result;
  10205. }
  10206. static char fnamePlusPath[100]={0};
  10207. static char fnamePWithNoPath[60]={0};
  10208. void checkUploadLog(void)
  10209. {
  10210. FILE *fp;
  10211. /* Open the command for reading. */
  10212. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10213. if (fp == NULL) {
  10214. DEBUG_WARN("Failed to run command\n" );
  10215. exit(1);
  10216. }
  10217. int ftppathlen = 0;
  10218. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10219. int i = 0;
  10220. /* Read the output a line at a time - output it. */
  10221. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10222. if(i==0)
  10223. {
  10224. ftppathlen = strlen(fnamePlusPath);
  10225. DEBUG_INFO("%s\n", fnamePlusPath);
  10226. fnamePlusPath[ftppathlen]='\0';
  10227. break;
  10228. }
  10229. i= i+1;
  10230. }
  10231. /* close */
  10232. pclose(fp);
  10233. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10234. {
  10235. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10236. {
  10237. fnamePlusPath[k]='\0';
  10238. }
  10239. }
  10240. i=1;
  10241. //char fname[60]={0};
  10242. while(i < ftppathlen)
  10243. {
  10244. int len=ftppathlen-i;
  10245. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10246. {
  10247. DEBUG_INFO("compare '/' all right\n");
  10248. break;
  10249. }
  10250. i=i+1;
  10251. }
  10252. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  10253. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  10254. fnamePWithNoPath[i+1] = '\0';
  10255. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  10256. {
  10257. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  10258. {
  10259. fnamePWithNoPath[j]='\0';
  10260. }
  10261. }
  10262. FILE* fp1 = fopen(fnamePlusPath, "r");
  10263. if (fp1)
  10264. {
  10265. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  10266. // file exists
  10267. fclose(fp1);
  10268. }
  10269. else
  10270. {
  10271. // file doesn't exist
  10272. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  10273. }
  10274. }
  10275. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  10276. {
  10277. mtrace();
  10278. int result = FAIL;
  10279. time_t CurrentTime;
  10280. struct tm *tm;
  10281. pthread_t th_Status;
  10282. CurrentTime = time(NULL);
  10283. tm = localtime(&CurrentTime);
  10284. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  10285. 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);
  10286. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10287. if(!interLock.isGetDiagnosticGoing)
  10288. {
  10289. interLock.isGetDiagnosticGoing = 1;
  10290. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  10291. sleep(1);
  10292. }
  10293. else
  10294. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  10295. return result;
  10296. }
  10297. void* GetDiagnosticsProcess(void* data)
  10298. {
  10299. pthread_detach(pthread_self());
  10300. mtrace();
  10301. int retriesInt=0, retryIntervalInt=0;
  10302. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  10303. 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};
  10304. int port=0;
  10305. int isSuccess = FALSE;
  10306. char cmdBuf[2048];
  10307. struct tm *tmNow;
  10308. time_t CurrentTime;
  10309. struct tm tmStart;
  10310. struct tm tmStop;
  10311. CurrentTime = time(NULL);
  10312. tmNow=localtime(&CurrentTime);
  10313. uint16_t targetYear, targetMonth;
  10314. json_object *GetDiagnostics;
  10315. DEBUG_INFO("GetDiagnosticsProcess...\n");
  10316. GetDiagnostics = json_tokener_parse(data);
  10317. if(!is_error(GetDiagnostics))
  10318. {
  10319. // Required data
  10320. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  10321. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  10322. // Optional data
  10323. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  10324. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  10325. else
  10326. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  10327. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  10328. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  10329. else
  10330. retryIntervalInt = 30;
  10331. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  10332. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  10333. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  10334. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  10335. }
  10336. json_object_put(GetDiagnostics);
  10337. // Pack log to compress file
  10338. 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) &&
  10339. (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))
  10340. {
  10341. // Pack system log
  10342. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10343. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10344. targetYear = tmStart.tm_year;
  10345. targetMonth = tmStart.tm_mon;
  10346. do
  10347. {
  10348. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10349. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  10350. if(targetMonth+1>=13)
  10351. {
  10352. targetYear += 1;
  10353. targetMonth = 1;
  10354. }
  10355. else
  10356. {
  10357. targetMonth += 1;
  10358. }
  10359. }while((targetYear < (tmNow->tm_year+1900)) ||
  10360. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10361. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  10362. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  10363. system(cmdBuf);
  10364. // Pack charging & event log
  10365. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10366. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  10367. targetYear = tmStart.tm_year;
  10368. targetMonth = tmStart.tm_mon;
  10369. do
  10370. {
  10371. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10372. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  10373. if(targetMonth+1>=13)
  10374. {
  10375. targetYear += 1;
  10376. targetMonth = 1;
  10377. }
  10378. else
  10379. {
  10380. targetMonth += 1;
  10381. }
  10382. }while((targetYear < (tmNow->tm_year+1900)) ||
  10383. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10384. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10385. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10386. system(cmdBuf);
  10387. // Combine log file
  10388. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10389. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10390. }
  10391. else
  10392. {
  10393. system("exec /root/logPackTools 'log' 6");
  10394. }
  10395. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10396. system(cmdBuf);
  10397. checkUploadLog();
  10398. //****************location*******************/
  10399. if(strcmp(locationstr,"")==0)
  10400. {
  10401. DEBUG_INFO("location is <Empty>!\n");
  10402. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10403. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10404. goto end;
  10405. }
  10406. memset(protocol, 0, ARRAY_SIZE(protocol));
  10407. memset(user, 0, ARRAY_SIZE(user) );
  10408. memset(password, 0, ARRAY_SIZE(password));
  10409. memset(host, 0, ARRAY_SIZE(host));
  10410. memset(path, 0, ARRAY_SIZE(path));
  10411. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10412. memset(host1, 0, ARRAY_SIZE(host1));
  10413. memset(path1, 0, ARRAY_SIZE(path1));
  10414. /*location: ftp://user:password@host:port/path*/
  10415. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10416. if((access(fnamePlusPath,F_OK))!=-1)
  10417. {
  10418. DEBUG_INFO("fnamePlusPath exist.\n");
  10419. }
  10420. else
  10421. {
  10422. DEBUG_INFO("fnamePlusPath not exist!\n");
  10423. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10424. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10425. goto end;
  10426. }
  10427. if(strchr(locationstr,'@')==NULL)
  10428. {
  10429. sscanf(locationstr,
  10430. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10431. protocol, host, &port, path);
  10432. strcpy(user,"anonymous");
  10433. strcpy(password,"");
  10434. }
  10435. else
  10436. {
  10437. //DEBUG_INFO("pch=%s\n", pch);
  10438. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10439. protocol, user, password, host, &port, path);
  10440. }
  10441. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10442. {
  10443. DEBUG_INFO("protocol is not ftp/http ! \n");
  10444. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10445. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10446. goto end;
  10447. }
  10448. if(strncmp(locationstr,"http", 4) == 0)
  10449. {
  10450. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10451. sprintf(ftppath,"/%s", path);
  10452. do
  10453. {
  10454. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10455. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10456. sleep(3);
  10457. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10458. if(!isSuccess)
  10459. {
  10460. DEBUG_INFO("Diagnostics fail.\n");
  10461. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10462. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10463. sleep(retryIntervalInt);
  10464. }
  10465. else
  10466. {
  10467. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10468. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10469. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10470. }
  10471. retriesInt--;
  10472. }while((isSuccess == 0)&&(retriesInt >= 0));
  10473. }
  10474. else
  10475. {
  10476. sscanf(host,"%[^/]%s",host1, path1);
  10477. if(strlen(path) > 0)
  10478. sprintf(ftppath,"/%s", path);
  10479. else
  10480. sprintf(ftppath,"/%s", path1);
  10481. int ftppathlen=strlen(ftppath);
  10482. int i=1;
  10483. char filenametemp[50];
  10484. while(i < ftppathlen)
  10485. {
  10486. int len=ftppathlen-i;
  10487. if(ftppath[len]== 47) // '/' ascll code: 47
  10488. {
  10489. DEBUG_INFO("find '/' all right\n");
  10490. break;
  10491. }
  10492. i=i+1;
  10493. }
  10494. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10495. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10496. filenametemp[i+1] = 0;
  10497. if(port == 0)
  10498. port = 21;
  10499. do
  10500. {
  10501. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10502. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10503. sleep(3);
  10504. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10505. if(!isSuccess)
  10506. {
  10507. DEBUG_INFO("Diagnostics fail.\n");
  10508. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10509. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10510. sleep(retryIntervalInt);
  10511. }
  10512. else
  10513. {
  10514. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10515. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10516. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10517. }
  10518. retriesInt--;
  10519. }while((!isSuccess)&&(retriesInt >= 0));
  10520. }
  10521. end:
  10522. system("rm -f /mnt/*");
  10523. sleep(5);
  10524. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10525. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10526. interLock.isGetDiagnosticGoing = 0;
  10527. pthread_exit(NULL);
  10528. }
  10529. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10530. {
  10531. mtrace();
  10532. int result = FAIL;
  10533. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10534. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10535. {
  10536. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10537. locallistVersion = -1;
  10538. }
  10539. else
  10540. {
  10541. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10542. OCPP_getListVerion();
  10543. }
  10544. //from db.OCPP_getListVerion
  10545. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10546. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  10547. sendGetLocalListVersionConfirmation(uuid,"");
  10548. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  10549. return result;
  10550. }
  10551. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10552. {
  10553. mtrace();
  10554. int result = FAIL;
  10555. int connectorIdInt=-1;
  10556. int tempIndex = 0;
  10557. int connectorIdIsNULL, chargingProfileIsNULL;
  10558. char comfirmstr[20]={0};
  10559. char cmdBuf[512];
  10560. json_object *RemoteStartTransaction;
  10561. FILE *fp;
  10562. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10563. if(server_pending == TRUE)
  10564. {
  10565. return 0;
  10566. }
  10567. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10568. RemoteStartTransaction = json_tokener_parse(payload);
  10569. if(!is_error(RemoteStartTransaction))
  10570. {
  10571. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10572. {
  10573. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10574. }
  10575. else
  10576. {
  10577. connectorIdIsNULL = TRUE;
  10578. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10579. {
  10580. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10581. {
  10582. connectorIdIsNULL = FALSE;
  10583. connectorIdInt = (gun_index+1);
  10584. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10585. break;
  10586. }
  10587. }
  10588. }
  10589. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10590. {
  10591. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10592. // Required data
  10593. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10594. // Optional data
  10595. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10596. {
  10597. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10598. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10599. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10600. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10601. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10602. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10603. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10604. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10605. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10606. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10607. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10608. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10609. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10610. {
  10611. 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")));
  10612. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10613. 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"));
  10614. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10615. 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"));
  10616. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10617. 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")));
  10618. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10619. {
  10620. 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++)
  10621. {
  10622. 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"));
  10623. 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"));
  10624. 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)
  10625. 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"));
  10626. }
  10627. }
  10628. }
  10629. }
  10630. else
  10631. {
  10632. chargingProfileIsNULL = TRUE;
  10633. }
  10634. }
  10635. }
  10636. else
  10637. {
  10638. connectorIdIsNULL = TRUE;
  10639. }
  10640. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10641. {
  10642. DEBUG_WARN("Connector id is NULL\n.");
  10643. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10644. goto end;
  10645. }
  10646. /*
  10647. enum _SYSTEM_STATUS
  10648. {
  10649. S_BOOTING = 0,
  10650. S_IDLE, = 1
  10651. S_AUTHORIZING, = 2
  10652. S_REASSIGN_CHECK, = 3
  10653. S_REASSIGN, = 4
  10654. S_PRECHARGE, = 5
  10655. S_PREPARING_FOR_EV, = 6
  10656. S_PREPARING_FOR_EVSE, = 7
  10657. S_CHARGING, = 8
  10658. S_TERMINATING, = 9
  10659. S_COMPLETE, = 10
  10660. S_ALARM, = 11
  10661. S_FAULT = 12
  10662. }
  10663. */
  10664. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10665. {
  10666. //check Transaction active
  10667. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10668. {
  10669. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10670. {
  10671. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10672. }
  10673. else
  10674. {
  10675. tempIndex = connectorIdInt -1;
  10676. }
  10677. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10678. {
  10679. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10680. {
  10681. 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))
  10682. {
  10683. //Reserved
  10684. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10685. }
  10686. 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))
  10687. {
  10688. //Reserved
  10689. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10690. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10691. goto end;
  10692. }
  10693. else
  10694. {
  10695. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10696. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10697. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10698. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10699. {
  10700. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10701. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10702. goto end;
  10703. }
  10704. }//END FOR ELSE
  10705. }
  10706. }// END FOR CHAdeMO_QUANTITY
  10707. }
  10708. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10709. {
  10710. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10711. {
  10712. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10713. }
  10714. else
  10715. {
  10716. tempIndex = connectorIdInt -1;
  10717. }
  10718. for (int index = 0; index < CCS_QUANTITY; index++)
  10719. {
  10720. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10721. {
  10722. 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))
  10723. {
  10724. //Reserved
  10725. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10726. }
  10727. 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))
  10728. {
  10729. //Reserved
  10730. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10731. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10732. goto end;
  10733. }
  10734. else
  10735. {
  10736. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10737. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10738. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10739. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10740. {
  10741. DEBUG_WARN("CCS connector not allow start\n.");
  10742. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10743. goto end;
  10744. }
  10745. }// END FOR ELSE
  10746. }
  10747. }// END FOR CCS_QUANTITY
  10748. }
  10749. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10750. {
  10751. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10752. {
  10753. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10754. }
  10755. else
  10756. {
  10757. tempIndex = connectorIdInt -1;
  10758. }
  10759. for (int index = 0; index < GB_QUANTITY; index++)
  10760. {
  10761. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10762. {
  10763. 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))
  10764. {
  10765. //Reserved
  10766. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10767. }
  10768. 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))
  10769. {
  10770. //Reserved
  10771. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10772. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10773. goto end;
  10774. }
  10775. else
  10776. {
  10777. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10778. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10779. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10780. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10781. {
  10782. DEBUG_WARN("GB connector not allow start\n.");
  10783. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10784. goto end;
  10785. }
  10786. }// END FOR ELSE
  10787. }
  10788. } // END FOR GB_QUANTITY
  10789. }
  10790. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10791. {
  10792. tempIndex = connectorIdInt -1;
  10793. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10794. {
  10795. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10796. {
  10797. 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))
  10798. {
  10799. //Reserved
  10800. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10801. }
  10802. 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))
  10803. {
  10804. //Reserved
  10805. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10806. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10807. goto end;
  10808. }
  10809. else
  10810. {
  10811. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10812. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10813. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10814. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10815. {
  10816. DEBUG_WARN("GB connector not allow start\n.");
  10817. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10818. goto end;
  10819. }
  10820. }// END FOR ELSE
  10821. }
  10822. } // END FOR GB_QUANTITY
  10823. }
  10824. else
  10825. {
  10826. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10827. {
  10828. tempIndex = 2;
  10829. }
  10830. else
  10831. {
  10832. tempIndex = connectorIdInt -1;
  10833. }
  10834. for (int index = 0; index < AC_QUANTITY; index++)
  10835. {
  10836. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10837. {
  10838. 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))
  10839. {
  10840. //Reserved
  10841. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10842. }
  10843. 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))
  10844. {
  10845. //Reserved
  10846. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10847. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10848. goto end;
  10849. }
  10850. else
  10851. {
  10852. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10853. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10854. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10855. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10856. {
  10857. DEBUG_WARN("AC connector not allow start\n.");
  10858. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10859. goto end;
  10860. }
  10861. }//END FOR ELSE
  10862. }
  10863. }// END FOR AC_QUANTITY
  10864. }
  10865. if(chargingProfileIsNULL == FALSE)
  10866. {
  10867. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10868. {
  10869. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10870. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10871. //memset idTag
  10872. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10873. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10874. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10875. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10876. // Save profile to file
  10877. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10878. system(cmdBuf);
  10879. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10880. fp = fopen(cmdBuf, "w");
  10881. 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));
  10882. fclose(fp);
  10883. }
  10884. else
  10885. {
  10886. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10887. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10888. }
  10889. }
  10890. else
  10891. {
  10892. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10893. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10894. //memset idTag
  10895. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10896. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10897. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10898. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10899. }
  10900. }
  10901. else
  10902. {
  10903. DEBUG_WARN("Connector id over\n.");
  10904. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10905. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10906. }
  10907. end:
  10908. json_object_put(RemoteStartTransaction);
  10909. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10910. {
  10911. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10912. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10913. }
  10914. //OCPP send RemoteStartConfirmation by first.
  10915. sendRemoteStartConfirmation(uuid, comfirmstr);
  10916. return result;
  10917. }
  10918. int handleRemoteStartRequest(char *uuid, char *payload)
  10919. {
  10920. mtrace();
  10921. int result = PASS;
  10922. int connectorIdInt=-1;
  10923. int tempIndex = 0;
  10924. char comfirmstr[20]={0};
  10925. char cmdBuf[512];
  10926. json_object *RemoteStartTransaction;
  10927. FILE *fp;
  10928. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10929. if(server_pending == TRUE)
  10930. {
  10931. result = FAIL;
  10932. }
  10933. RemoteStartTransaction = json_tokener_parse(payload);
  10934. if(!is_error(RemoteStartTransaction))
  10935. {
  10936. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10937. {
  10938. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10939. }
  10940. else
  10941. {
  10942. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10943. {
  10944. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10945. {
  10946. connectorIdInt = (gun_index+1);
  10947. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10948. break;
  10949. }
  10950. }
  10951. }
  10952. if(connectorIdInt == 0)
  10953. {
  10954. DEBUG_WARN("Connector id shall not equal 0.\n");
  10955. result = FAIL;
  10956. }
  10957. else if(connectorIdInt == -1)
  10958. {
  10959. DEBUG_INFO("Connector id does not specific.\n");
  10960. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10961. {
  10962. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10963. // Required data
  10964. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10965. // Optional data
  10966. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10967. {
  10968. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10969. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10970. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10971. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10972. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10973. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10974. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10975. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10976. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10977. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10978. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10979. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10980. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10981. {
  10982. 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")));
  10983. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10984. 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"));
  10985. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10986. 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"));
  10987. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10988. 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")));
  10989. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10990. {
  10991. 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++)
  10992. {
  10993. 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"));
  10994. 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"));
  10995. 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)
  10996. 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"));
  10997. }
  10998. }
  10999. }
  11000. }
  11001. else
  11002. {
  11003. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  11004. }
  11005. }
  11006. }
  11007. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  11008. {
  11009. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  11010. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  11011. // Required data
  11012. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11013. // Optional data
  11014. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11015. {
  11016. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11017. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11018. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11019. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11020. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11021. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11022. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11023. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11024. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11025. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11026. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11027. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11028. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11029. {
  11030. 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")));
  11031. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11032. 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"));
  11033. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11034. 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"));
  11035. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11036. 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")));
  11037. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11038. {
  11039. 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++)
  11040. {
  11041. 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"));
  11042. 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"));
  11043. 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)
  11044. 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"));
  11045. }
  11046. }
  11047. }
  11048. }
  11049. else
  11050. {
  11051. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  11052. }
  11053. }
  11054. else
  11055. {
  11056. DEBUG_WARN("Connector id is over maximun value.\n");
  11057. result = FAIL;
  11058. }
  11059. }
  11060. if(result == PASS)
  11061. {
  11062. if(connectorIdInt > 0)
  11063. {
  11064. //check Transaction active
  11065. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11066. {
  11067. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11068. {
  11069. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11070. }
  11071. else
  11072. {
  11073. tempIndex = connectorIdInt -1;
  11074. }
  11075. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11076. {
  11077. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11078. {
  11079. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11080. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11081. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11082. {
  11083. //Reserved
  11084. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  11085. }
  11086. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11087. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11088. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11089. {
  11090. //Reserved
  11091. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  11092. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11093. goto end;
  11094. }
  11095. else
  11096. {
  11097. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11098. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  11099. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  11100. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  11101. {
  11102. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  11103. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11104. goto end;
  11105. }
  11106. }//END FOR ELSE
  11107. }
  11108. }// END FOR CHAdeMO_QUANTITY
  11109. }
  11110. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11111. {
  11112. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11113. {
  11114. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11115. }
  11116. else
  11117. {
  11118. tempIndex = connectorIdInt -1;
  11119. }
  11120. for (int index = 0; index < CCS_QUANTITY; index++)
  11121. {
  11122. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11123. {
  11124. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11125. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11126. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11127. {
  11128. //Reserved
  11129. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  11130. }
  11131. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11132. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11133. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11134. {
  11135. //Reserved
  11136. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  11137. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11138. goto end;
  11139. }
  11140. else
  11141. {
  11142. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11143. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11144. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11145. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11146. {
  11147. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11148. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11149. goto end;
  11150. }
  11151. }// END FOR ELSE
  11152. }
  11153. }// END FOR CCS_QUANTITY
  11154. }
  11155. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11156. {
  11157. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11158. {
  11159. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11160. }
  11161. else
  11162. {
  11163. tempIndex = connectorIdInt -1;
  11164. }
  11165. for (int index = 0; index < GB_QUANTITY; index++)
  11166. {
  11167. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11168. {
  11169. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11170. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11171. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11172. {
  11173. //Reserved
  11174. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11175. }
  11176. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11177. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11178. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11179. {
  11180. //Reserved
  11181. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11182. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11183. goto end;
  11184. }
  11185. else
  11186. {
  11187. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11188. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11189. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11190. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11191. {
  11192. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11193. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11194. goto end;
  11195. }
  11196. }// END FOR ELSE
  11197. }
  11198. } // END FOR GB_QUANTITY
  11199. }
  11200. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11201. {
  11202. tempIndex = connectorIdInt -1;
  11203. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11204. {
  11205. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11206. {
  11207. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11208. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11209. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11210. {
  11211. //Reserved
  11212. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11213. }
  11214. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11215. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11216. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11217. {
  11218. //Reserved
  11219. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11220. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11221. goto end;
  11222. }
  11223. else
  11224. {
  11225. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11226. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11227. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11228. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11229. {
  11230. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11231. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11232. goto end;
  11233. }
  11234. }// END FOR ELSE
  11235. }
  11236. } // END FOR GB_QUANTITY
  11237. }
  11238. else
  11239. {
  11240. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11241. {
  11242. tempIndex = 2;
  11243. }
  11244. else
  11245. {
  11246. tempIndex = connectorIdInt -1;
  11247. }
  11248. for (int index = 0; index < AC_QUANTITY; index++)
  11249. {
  11250. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11251. {
  11252. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11253. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11254. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11255. {
  11256. //Reserved
  11257. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11258. }
  11259. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11260. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11261. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11262. {
  11263. //Reserved
  11264. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11265. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11266. goto end;
  11267. }
  11268. else
  11269. {
  11270. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11271. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11272. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11273. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11274. {
  11275. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11276. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11277. goto end;
  11278. }
  11279. }//END FOR ELSE
  11280. }
  11281. }// END FOR AC_QUANTITY
  11282. }
  11283. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11284. {
  11285. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11286. {
  11287. // Save profile to file
  11288. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11289. system(cmdBuf);
  11290. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11291. fp = fopen(cmdBuf, "w");
  11292. 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));
  11293. fclose(fp);
  11294. }
  11295. else
  11296. {
  11297. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11298. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11299. goto end;
  11300. }
  11301. }
  11302. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11303. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11304. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11305. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11306. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11307. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11308. }
  11309. else
  11310. {
  11311. uint8_t isHasIdleConnector = FALSE;
  11312. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11313. {
  11314. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11315. {
  11316. isHasIdleConnector = TRUE;
  11317. break;
  11318. }
  11319. }
  11320. if(isHasIdleConnector == TRUE)
  11321. {
  11322. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11323. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11324. {
  11325. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11326. {
  11327. // Save profile to file
  11328. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11329. system(cmdBuf);
  11330. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11331. fp = fopen(cmdBuf, "w");
  11332. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11333. fclose(fp);
  11334. refreshStartTimer(&clientTime.RemoteStartWait);
  11335. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11336. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11337. }
  11338. else
  11339. {
  11340. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11341. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11342. }
  11343. }
  11344. else
  11345. {
  11346. refreshStartTimer(&clientTime.RemoteStartWait);
  11347. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11348. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11349. }
  11350. }
  11351. else
  11352. {
  11353. DEBUG_INFO("There is not any connector is idle.\n");
  11354. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11355. }
  11356. }
  11357. }
  11358. else
  11359. {
  11360. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11361. }
  11362. end:
  11363. json_object_put(RemoteStartTransaction);
  11364. sendRemoteStartConfirmation(uuid, comfirmstr);
  11365. return result;
  11366. }
  11367. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11368. {
  11369. mtrace();
  11370. int result = FAIL;
  11371. int match = FALSE;
  11372. int GunNO = 0;
  11373. int tempIndex = 0;
  11374. int transactionIdInt=0;
  11375. int transactionIdIsNULL= TRUE;
  11376. char comfirmstr[20];
  11377. json_object *RemoteStopTransaction;
  11378. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11379. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11380. if(server_pending == TRUE)
  11381. {
  11382. return 0;
  11383. }
  11384. RemoteStopTransaction = json_tokener_parse(payload);
  11385. if(!is_error(RemoteStopTransaction))
  11386. {
  11387. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11388. {
  11389. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11390. transactionIdIsNULL = FALSE;
  11391. }
  11392. }
  11393. json_object_put(RemoteStopTransaction);
  11394. if(transactionIdIsNULL == FALSE)
  11395. {
  11396. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11397. {
  11398. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11399. {
  11400. //check Transaction active
  11401. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11402. {
  11403. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11404. {
  11405. tempIndex = ((gun_index==2) ? 1: 0);
  11406. }
  11407. else
  11408. {
  11409. tempIndex = gun_index;
  11410. }
  11411. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11412. {
  11413. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11414. {
  11415. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11416. {
  11417. match = TRUE;
  11418. GunNO = gun_index;
  11419. }
  11420. }
  11421. }// END FOR CHAdeMO_QUANTITY
  11422. }
  11423. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11424. {
  11425. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11426. {
  11427. tempIndex = ((gun_index==2) ? 1: 0);
  11428. }
  11429. else
  11430. {
  11431. tempIndex = gun_index;
  11432. }
  11433. for (int index = 0; index < CCS_QUANTITY; index++)
  11434. {
  11435. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11436. {
  11437. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11438. {
  11439. match = TRUE;
  11440. GunNO = gun_index;
  11441. }
  11442. }
  11443. }// END FOR CCS_QUANTITY
  11444. }
  11445. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11446. {
  11447. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11448. {
  11449. tempIndex = ((gun_index==2) ? 1: 0);
  11450. }
  11451. else
  11452. {
  11453. tempIndex = gun_index;
  11454. }
  11455. for (int index = 0; index < GB_QUANTITY; index++)
  11456. {
  11457. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11458. {
  11459. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11460. {
  11461. match = TRUE;
  11462. GunNO = gun_index;
  11463. }
  11464. }
  11465. }// END FOR GB_QUANTITY
  11466. }
  11467. else if(gunType[gun_index] == GUN_TYPE_DO)
  11468. {
  11469. tempIndex = gun_index;
  11470. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11471. {
  11472. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11473. {
  11474. 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
  11475. {
  11476. match = TRUE;
  11477. GunNO = gun_index;
  11478. }
  11479. }
  11480. }// END FOR GB_QUANTITY
  11481. }
  11482. else
  11483. {
  11484. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11485. {
  11486. tempIndex = 2;
  11487. }
  11488. else
  11489. {
  11490. tempIndex = gun_index;
  11491. }
  11492. for (int index = 0; index < AC_QUANTITY; index++)
  11493. {
  11494. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11495. {
  11496. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11497. {
  11498. match = TRUE;
  11499. GunNO = gun_index;
  11500. }
  11501. }
  11502. }// END FOR CHAdeMO_QUANTITY
  11503. } // END FOR AC ELSE
  11504. }// CHECK IF ResponseTransactionId == transactionIdInt
  11505. }//END FOR
  11506. if( match == TRUE)
  11507. {
  11508. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11509. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11510. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11511. }
  11512. else
  11513. {
  11514. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11515. }
  11516. }
  11517. else
  11518. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11519. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11520. return result;
  11521. }
  11522. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11523. {
  11524. mtrace();
  11525. int result = FAIL;
  11526. int connectorIdInt=0, reservationIdInt=0;
  11527. int tempIndex = 0;
  11528. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  11529. char comfirmstr[20]={0};
  11530. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11531. int c = 0;
  11532. char *loc;
  11533. //char *ptr;
  11534. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11535. strcpy(sstrtemp, stringtrimspace(payload));
  11536. //***(1)connectorId ****/
  11537. c=0;
  11538. loc = strstr(sstrtemp, "connectorId");
  11539. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11540. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11541. {
  11542. sstr[c] = loc[strlen("connectorId")+2+c];
  11543. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11544. c++;
  11545. }
  11546. sstr[c] = '\0';
  11547. connectorIdInt = atoi(sstr);
  11548. //***(2)expiryDate ****/
  11549. loc = strstr(sstrtemp, "expiryDate");
  11550. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11551. c = 0;
  11552. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11553. {
  11554. sstr[c] = loc[3+strlen("expiryDate")+c];
  11555. c++;
  11556. }
  11557. sstr[c] = '\0';
  11558. strcpy(expiryDatestr, sstr);
  11559. //***(3)idTag ****/
  11560. loc = strstr(sstrtemp, "idTag");
  11561. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11562. c = 0;
  11563. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11564. {
  11565. sstr[c] = loc[3+strlen("idTag")+c];
  11566. c++;
  11567. }
  11568. sstr[c] = '\0';
  11569. strcpy(idTagstr, sstr);
  11570. //***(4)parentIdTag ****/
  11571. loc = strstr(sstrtemp, "parentIdTag");
  11572. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11573. c = 0;
  11574. if(loc == NULL)
  11575. {
  11576. strcpy(parentIdTagstr, "");
  11577. }
  11578. else
  11579. {
  11580. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11581. {
  11582. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11583. c++;
  11584. }
  11585. sstr[c] = '\0';
  11586. strcpy(parentIdTagstr, sstr);
  11587. }
  11588. //***(5)reservationId ****/
  11589. c=0;
  11590. loc = strstr(sstrtemp, "reservationId");
  11591. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11592. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11593. {
  11594. sstr[c] = loc[strlen("reservationId")+2+c];
  11595. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11596. c++;
  11597. }
  11598. sstr[c] = '\0';
  11599. reservationIdInt = atoi(sstr);
  11600. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11601. /*
  11602. enum SYSTEM_STATUS
  11603. {
  11604. SYS_MODE_BOOTING = 0,
  11605. SYS_MODE_IDLE = 1,
  11606. SYS_MODE_AUTHORIZING = 2,
  11607. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11608. SYS_MODE_REASSIGN = 4,
  11609. SYS_MODE_PREPARING = 5,
  11610. SYS_MODE_PREPARE_FOR_EV = 6,
  11611. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11612. SYS_MODE_CHARGING = 8,
  11613. SYS_MODE_TERMINATING = 9,
  11614. SYS_MODE_COMPLETE = 10,
  11615. SYS_MODE_ALARM = 11,
  11616. SYS_MODE_FAULT = 12,
  11617. SYS_MODE_RESERVATION = 13,
  11618. SYS_MODE_BOOKING = 14,
  11619. SYS_MODE_MAINTAIN = 15,
  11620. SYS_MODE_DEBUG = 16,
  11621. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11622. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11623. SYS_MODE_UPDATE = 19
  11624. };
  11625. */
  11626. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11627. {
  11628. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11629. goto end;
  11630. }
  11631. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11632. {
  11633. //check Transaction active
  11634. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11635. {
  11636. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11637. {
  11638. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11639. }
  11640. else
  11641. {
  11642. tempIndex = connectorIdInt -1;
  11643. }
  11644. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11645. {
  11646. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11647. {
  11648. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11649. {
  11650. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11651. {
  11652. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11653. {
  11654. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11655. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11656. }
  11657. 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'))
  11658. {
  11659. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11660. }
  11661. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11662. {
  11663. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11664. }
  11665. else
  11666. {
  11667. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11668. }
  11669. }
  11670. 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
  11671. {
  11672. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11673. }
  11674. }
  11675. else
  11676. {
  11677. //replace reservation
  11678. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11679. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11680. }
  11681. }
  11682. } // END FOR CHAdeMO_QUANTITY
  11683. }
  11684. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11685. {
  11686. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11687. {
  11688. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11689. }
  11690. else
  11691. {
  11692. tempIndex = connectorIdInt -1;
  11693. }
  11694. for (int index = 0; index < CCS_QUANTITY; index++)
  11695. {
  11696. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11697. {
  11698. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11699. {
  11700. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11701. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11702. {
  11703. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11704. {
  11705. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11706. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11707. }
  11708. 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'))
  11709. {
  11710. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11711. }
  11712. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11713. {
  11714. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11715. }
  11716. else
  11717. {
  11718. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11719. }
  11720. }
  11721. 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
  11722. {
  11723. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11724. }
  11725. }
  11726. else
  11727. {
  11728. //replace reservation
  11729. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11730. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11731. }
  11732. }
  11733. } // END FOR CCS_QUANTITY
  11734. }
  11735. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11736. {
  11737. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11738. {
  11739. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11740. }
  11741. else
  11742. {
  11743. tempIndex = connectorIdInt -1;
  11744. }
  11745. for (int index = 0; index < GB_QUANTITY; index++)
  11746. {
  11747. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11748. {
  11749. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11750. {
  11751. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11752. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11753. {
  11754. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11755. {
  11756. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11757. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11758. }
  11759. 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'))
  11760. {
  11761. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11762. }
  11763. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11764. {
  11765. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11766. }
  11767. else
  11768. {
  11769. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11770. }
  11771. }
  11772. 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
  11773. {
  11774. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11775. }
  11776. }
  11777. else
  11778. {
  11779. //replace reservation
  11780. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11781. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11782. }
  11783. }
  11784. }// END FOR GB_QUANTITY
  11785. }
  11786. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11787. {
  11788. tempIndex = connectorIdInt -1;
  11789. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11790. {
  11791. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11792. {
  11793. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11794. {
  11795. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11796. 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
  11797. {
  11798. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11799. {
  11800. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11801. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11802. }
  11803. 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'))
  11804. {
  11805. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11806. }
  11807. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11808. {
  11809. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11810. }
  11811. else
  11812. {
  11813. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11814. }
  11815. }
  11816. 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
  11817. {
  11818. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11819. }
  11820. }
  11821. else
  11822. {
  11823. //replace reservation
  11824. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11825. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11826. }
  11827. }
  11828. }// END FOR GB_QUANTITY
  11829. }
  11830. else
  11831. {
  11832. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11833. {
  11834. tempIndex = 2;
  11835. }
  11836. else
  11837. {
  11838. tempIndex = (connectorIdInt -1);
  11839. }
  11840. for (int index = 0; index < AC_QUANTITY; index++)
  11841. {
  11842. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11843. {
  11844. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11845. {
  11846. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11847. {
  11848. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11849. {
  11850. 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))
  11851. {
  11852. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11853. }
  11854. else
  11855. {
  11856. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11857. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11858. }
  11859. }
  11860. 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'))
  11861. {
  11862. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11863. }
  11864. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11865. {
  11866. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11867. }
  11868. else
  11869. {
  11870. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11871. }
  11872. }
  11873. 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
  11874. {
  11875. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11876. }
  11877. }
  11878. else
  11879. {
  11880. //replace reservation
  11881. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11882. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11883. }
  11884. }
  11885. } // END FOR AC_QUANTITY
  11886. }
  11887. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11888. }
  11889. else if(connectorIdInt == 0)
  11890. {
  11891. //check Transaction active
  11892. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11893. {
  11894. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11895. {
  11896. 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'))
  11897. {
  11898. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11899. goto end;
  11900. }
  11901. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11902. {
  11903. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11904. goto end;
  11905. }
  11906. 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
  11907. {
  11908. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11909. goto end;
  11910. }
  11911. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11912. {
  11913. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11914. goto end;
  11915. }
  11916. }
  11917. }// END FOR CHAdeMO_QUANTITY
  11918. for (int index = 0; index < CCS_QUANTITY; index++)
  11919. {
  11920. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11921. {
  11922. 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'))
  11923. {
  11924. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11925. goto end;
  11926. }
  11927. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11928. {
  11929. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11930. goto end;
  11931. }
  11932. 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
  11933. {
  11934. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11935. goto end;
  11936. }
  11937. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11938. {
  11939. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11940. goto end;
  11941. }
  11942. }
  11943. } // END FOR CCS_QUANTITY
  11944. for (int index = 0; index < GB_QUANTITY; index++)
  11945. {
  11946. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11947. {
  11948. 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'))
  11949. {
  11950. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11951. goto end;
  11952. }
  11953. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11954. {
  11955. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11956. goto end;
  11957. }
  11958. 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
  11959. {
  11960. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11961. goto end;
  11962. }
  11963. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11964. {
  11965. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11966. goto end;
  11967. }
  11968. }
  11969. } // END FOR GB_QUANTITY
  11970. for (int index = 0; index < AC_QUANTITY; index++)
  11971. {
  11972. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11973. {
  11974. 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'))
  11975. {
  11976. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11977. goto end;
  11978. }
  11979. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11980. {
  11981. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11982. goto end;
  11983. }
  11984. 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
  11985. {
  11986. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11987. goto end;
  11988. }
  11989. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11990. {
  11991. 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))
  11992. {
  11993. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11994. goto end;
  11995. }
  11996. }
  11997. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11998. {
  11999. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12000. goto end;
  12001. }
  12002. }
  12003. }// END FOR AC_QUANTITY
  12004. //The connectorId is 0
  12005. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  12006. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12007. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  12008. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  12009. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  12010. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  12011. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  12012. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  12013. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  12014. result = TRUE;
  12015. return result;
  12016. }
  12017. else
  12018. {
  12019. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12020. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12021. }
  12022. if(strcmp(comfirmstr,"Accepted") == 0)
  12023. {
  12024. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  12025. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  12026. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  12027. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  12028. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  12029. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12030. result = TRUE;
  12031. return result;
  12032. }
  12033. end:
  12034. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  12035. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  12036. return result;
  12037. }
  12038. int handleResetRequest(char *uuid, char *payload)
  12039. {
  12040. mtrace();
  12041. int result = FAIL;
  12042. char sstr[10]={0},sstrtemp[30]={ 0 };
  12043. char typestr[10]={0};
  12044. char comfirmstr[20]={0};
  12045. int c = 0;
  12046. char *loc;
  12047. DEBUG_INFO("handleResetRequest...\n");
  12048. strcpy(sstrtemp, stringtrimspace(payload));
  12049. loc = strstr(sstrtemp, "type");
  12050. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12051. c = 0;
  12052. while (loc[3+strlen("type")+c] != '\"')
  12053. {
  12054. sstr[c] = loc[3+strlen("type")+c];
  12055. c++;
  12056. }
  12057. sstr[c] = '\0';
  12058. strcpy(typestr,sstr);
  12059. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  12060. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  12061. {
  12062. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  12063. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  12064. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  12065. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12066. }
  12067. else
  12068. {
  12069. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  12070. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12071. result = PASS;
  12072. }
  12073. sendResetConfirmation(uuid, comfirmstr);
  12074. return result;
  12075. }
  12076. int handleSendLocalListRequest(char *uuid, char *payload)
  12077. {
  12078. mtrace();
  12079. int result = FAIL;
  12080. char comfirmstr[20];
  12081. int checkState_Faulted = FALSE;
  12082. json_object *SendLocalList;
  12083. DEBUG_INFO("handleSendLocalListRequest...\n");
  12084. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  12085. {
  12086. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12087. goto end;
  12088. }
  12089. //check Charge Point state
  12090. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12091. {
  12092. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12093. {
  12094. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12095. }
  12096. }
  12097. for (int index = 0; index < CCS_QUANTITY; index++)
  12098. {
  12099. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12100. {
  12101. checkState_Faulted = TRUE; //OCPP Status
  12102. }
  12103. }
  12104. for (int index = 0; index < GB_QUANTITY; index++)
  12105. {
  12106. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12107. {
  12108. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12109. }
  12110. }
  12111. //check Charge Point state
  12112. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12113. {
  12114. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12115. {
  12116. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12117. }
  12118. }
  12119. //check Charge Point state
  12120. for (int index = 0; index < AC_QUANTITY; index++)
  12121. {
  12122. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12123. {
  12124. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12125. }
  12126. }
  12127. if(checkState_Faulted == TRUE)
  12128. {
  12129. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12130. goto end;
  12131. }
  12132. // Parsing payload
  12133. SendLocalList = json_tokener_parse(payload);
  12134. if(!is_error(SendLocalList))
  12135. {
  12136. // Required data
  12137. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12138. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12139. // Optional data
  12140. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12141. {
  12142. //Check UpdateType
  12143. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12144. {
  12145. //Local list full update
  12146. DEBUG_INFO("Local list full update.\n");
  12147. OCPP_getListVerion();
  12148. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12149. {
  12150. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12151. goto end;
  12152. }
  12153. OCPP_cleanLocalList();
  12154. }
  12155. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12156. {
  12157. //Local list different update
  12158. DEBUG_INFO("Local list different update.\n");
  12159. OCPP_getListVerion();
  12160. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12161. {
  12162. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12163. goto end;
  12164. }
  12165. }
  12166. else
  12167. {
  12168. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12169. goto end;
  12170. }
  12171. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12172. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12173. {
  12174. 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")));
  12175. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12176. {
  12177. 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")));
  12178. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12179. 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")));
  12180. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12181. 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")));
  12182. }
  12183. // Add to db
  12184. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12185. {
  12186. //Local list full update
  12187. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12188. idx,
  12189. ShmOCPP16Data->SendLocalList.ListVersion,
  12190. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12191. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12192. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12193. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12194. // update list
  12195. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12196. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12197. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12198. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12199. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12200. }
  12201. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12202. {
  12203. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12204. idx,
  12205. ShmOCPP16Data->SendLocalList.ListVersion,
  12206. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12207. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12208. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12209. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12210. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12211. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12212. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12213. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12214. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12215. }
  12216. }
  12217. }
  12218. else
  12219. {
  12220. //Check UpdateType
  12221. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12222. {
  12223. //Local list full update
  12224. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12225. OCPP_cleanLocalList();
  12226. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12227. goto end;
  12228. }
  12229. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12230. {
  12231. //Local list different update
  12232. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12233. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12234. goto end;
  12235. }
  12236. }
  12237. result = PASS;
  12238. }
  12239. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12240. end:
  12241. json_object_put(SendLocalList);
  12242. sendSendLocalListConfirmation(uuid, comfirmstr);
  12243. return result;
  12244. }
  12245. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12246. {
  12247. mtrace();
  12248. int result = FAIL;
  12249. struct StructSetChargingProfile SetProfileReq = {0};
  12250. int tempchargingProfileIdInt;
  12251. int tempstackLevelInt;
  12252. int chargingSchedulePeriodCount = 0;
  12253. char comfirmstr[20]={0};
  12254. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  12255. char rmFileCmd[128]={0};
  12256. int profileQuantity = 0;
  12257. int isReplaceable = FALSE;
  12258. json_object *SetChargingProfile;
  12259. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12260. SetChargingProfile = json_tokener_parse(payload);
  12261. if(!is_error(SetChargingProfile))
  12262. {
  12263. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12264. {
  12265. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12266. }
  12267. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12268. {
  12269. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12270. {
  12271. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12272. }
  12273. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12274. {
  12275. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12276. }
  12277. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12278. {
  12279. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12280. }
  12281. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12282. {
  12283. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12284. }
  12285. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12286. {
  12287. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12288. }
  12289. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12290. {
  12291. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12292. }
  12293. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12294. {
  12295. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12296. }
  12297. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12298. {
  12299. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12300. }
  12301. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12302. {
  12303. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12304. {
  12305. 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")));
  12306. }
  12307. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12308. {
  12309. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12310. }
  12311. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12312. {
  12313. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12314. }
  12315. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12316. {
  12317. 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")));
  12318. }
  12319. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12320. {
  12321. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12322. if(chargingSchedulePeriodCount <= 10)
  12323. {
  12324. 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++)
  12325. {
  12326. 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)
  12327. {
  12328. 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"));
  12329. }
  12330. 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)
  12331. {
  12332. 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"));
  12333. }
  12334. 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)
  12335. {
  12336. 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"));
  12337. }
  12338. }
  12339. }
  12340. }
  12341. }
  12342. }
  12343. }
  12344. // Profile periods quantity check
  12345. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12346. {
  12347. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12348. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12349. goto end;
  12350. }
  12351. // Check invalid limit
  12352. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12353. {
  12354. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12355. {
  12356. if(((0 < SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit) && (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit < (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='A'?6:6*220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)))) ||
  12357. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12358. {
  12359. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12360. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12361. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12362. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12363. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12364. goto end;
  12365. }
  12366. }
  12367. }
  12368. else
  12369. {
  12370. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12371. {
  12372. if((SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?1:220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)) > modelnameInfo.ratedPower))
  12373. {
  12374. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12375. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12376. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12377. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12378. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12379. goto end;
  12380. }
  12381. }
  12382. }
  12383. // Profile purpose info check
  12384. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12385. {
  12386. FILE *fp;
  12387. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12388. if(SetProfileReq.ConnectorId != 0)
  12389. {
  12390. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12391. DEBUG_WARN("Profile connector id is not 0.\n");
  12392. goto end;
  12393. }
  12394. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12395. if (!fp)
  12396. {
  12397. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12398. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12399. }
  12400. else
  12401. {
  12402. char *line = NULL;
  12403. size_t len = 0;
  12404. while(getline(&line, &len, fp) != -1)
  12405. {
  12406. json_object *obj = NULL;
  12407. obj = json_tokener_parse(line);
  12408. if(is_error(obj))
  12409. {
  12410. DEBUG_ERROR("Parse txProfile from file error.\n");
  12411. }
  12412. else
  12413. {
  12414. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12415. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12416. {
  12417. profileQuantity += 1;
  12418. }
  12419. else
  12420. isReplaceable = TRUE;
  12421. }
  12422. }
  12423. }
  12424. fclose(fp);
  12425. }
  12426. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12427. {
  12428. FILE *fp;
  12429. char filename[128]={0};
  12430. int tmpProfileQuantity;
  12431. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12432. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12433. {
  12434. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12435. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12436. goto end;
  12437. }
  12438. if(SetProfileReq.ConnectorId == 0)
  12439. {
  12440. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12441. {
  12442. tmpProfileQuantity = 0;
  12443. memset(filename, 0, ARRAY_SIZE(filename));
  12444. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12445. fp = fopen(filename, "r");
  12446. if (!fp)
  12447. {
  12448. DEBUG_INFO("%s does not create.\n", filename);
  12449. fp = fopen(filename, "w+");
  12450. }
  12451. else
  12452. {
  12453. char *line = NULL;
  12454. size_t len = 0;
  12455. while(getline(&line, &len, fp) != -1)
  12456. {
  12457. json_object *obj = NULL;
  12458. obj = json_tokener_parse(line);
  12459. if(is_error(obj))
  12460. {
  12461. DEBUG_ERROR("Parse txProfile from file error.\n");
  12462. }
  12463. else
  12464. {
  12465. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12466. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12467. {
  12468. tmpProfileQuantity += 1;
  12469. }
  12470. else
  12471. isReplaceable = TRUE;
  12472. }
  12473. }
  12474. }
  12475. fclose(fp);
  12476. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12477. }
  12478. }
  12479. else
  12480. {
  12481. memset(filename, 0, ARRAY_SIZE(filename));
  12482. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12483. fp = fopen(filename, "r");
  12484. if (!fp)
  12485. {
  12486. DEBUG_INFO("%s does not create.\n", filename);
  12487. fp = fopen(filename, "w+");
  12488. }
  12489. else
  12490. {
  12491. char *line = NULL;
  12492. size_t len = 0;
  12493. while(getline(&line, &len, fp) != -1)
  12494. {
  12495. json_object *obj = NULL;
  12496. obj = json_tokener_parse(line);
  12497. if(is_error(obj))
  12498. {
  12499. DEBUG_ERROR("Parse txProfile from file error.\n");
  12500. }
  12501. else
  12502. {
  12503. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12504. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12505. {
  12506. profileQuantity += 1;
  12507. }
  12508. else
  12509. isReplaceable = TRUE;
  12510. }
  12511. }
  12512. }
  12513. fclose(fp);
  12514. }
  12515. }
  12516. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12517. {
  12518. int isMatchTransactiodId= FALSE;
  12519. FILE *fp;
  12520. char filename[128]={0};
  12521. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12522. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12523. if(SetProfileReq.ConnectorId == 0)
  12524. {
  12525. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12526. DEBUG_WARN("Profile connector id is 0.\n");
  12527. goto end;
  12528. }
  12529. int tempIndex = 0;
  12530. //check Transaction active
  12531. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12532. {
  12533. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12534. {
  12535. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12536. }
  12537. else
  12538. {
  12539. tempIndex = SetProfileReq.ConnectorId -1;
  12540. }
  12541. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12542. {
  12543. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12544. {
  12545. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12546. {
  12547. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12548. {
  12549. isMatchTransactiodId = TRUE;
  12550. break;
  12551. }
  12552. }
  12553. }
  12554. }
  12555. }
  12556. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12557. {
  12558. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12559. {
  12560. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12561. }
  12562. else
  12563. {
  12564. tempIndex = SetProfileReq.ConnectorId -1;
  12565. }
  12566. for (int index = 0; index < CCS_QUANTITY; index++)
  12567. {
  12568. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12569. {
  12570. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12571. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12572. {
  12573. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12574. {
  12575. isMatchTransactiodId = TRUE;
  12576. break;
  12577. }
  12578. }
  12579. }
  12580. }
  12581. }
  12582. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12583. {
  12584. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12585. {
  12586. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12587. }
  12588. else
  12589. {
  12590. tempIndex = SetProfileReq.ConnectorId -1;
  12591. }
  12592. for (int index = 0; index < GB_QUANTITY; index++)
  12593. {
  12594. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12595. {
  12596. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12597. {
  12598. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12599. {
  12600. isMatchTransactiodId = TRUE;
  12601. break;
  12602. }
  12603. }
  12604. }
  12605. }
  12606. }
  12607. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12608. {
  12609. tempIndex = SetProfileReq.ConnectorId -1;
  12610. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12611. {
  12612. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12613. {
  12614. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12615. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12616. {
  12617. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12618. {
  12619. isMatchTransactiodId = TRUE;
  12620. break;
  12621. }
  12622. }
  12623. }
  12624. }
  12625. }
  12626. else
  12627. {
  12628. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12629. {
  12630. tempIndex = 2;
  12631. }
  12632. else
  12633. {
  12634. tempIndex = (SetProfileReq.ConnectorId -1);
  12635. }
  12636. for (int index = 0; index < AC_QUANTITY; index++)
  12637. {
  12638. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12639. {
  12640. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12641. {
  12642. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12643. {
  12644. isMatchTransactiodId = TRUE;
  12645. break;
  12646. }
  12647. }
  12648. }
  12649. }
  12650. }
  12651. //check Transaction active
  12652. if(isMatchTransactiodId == FALSE)
  12653. {
  12654. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12655. DEBUG_WARN("Tx profile transaction id is not match.\n");
  12656. goto end;
  12657. }
  12658. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12659. {
  12660. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12661. DEBUG_WARN("Connector id is over max gun number.\n");
  12662. goto end;
  12663. }
  12664. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12665. fp = fopen(filename, "r");
  12666. if (!fp)
  12667. {
  12668. DEBUG_INFO("%s does not create.\n", filename);
  12669. fp = fopen(filename, "w+");
  12670. }
  12671. else
  12672. {
  12673. char *line = NULL;
  12674. size_t len = 0;
  12675. while(getline(&line, &len, fp) != -1)
  12676. {
  12677. json_object *obj = NULL;
  12678. obj = json_tokener_parse(line);
  12679. if(is_error(obj))
  12680. {
  12681. DEBUG_ERROR("Parse txProfile from file error.\n");
  12682. }
  12683. else
  12684. {
  12685. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12686. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12687. {
  12688. profileQuantity += 1;
  12689. }
  12690. else
  12691. isReplaceable = TRUE;
  12692. }
  12693. }
  12694. }
  12695. fclose(fp);
  12696. }
  12697. // Check ChargeProfileMaxStackLevel
  12698. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12699. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12700. {
  12701. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12702. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12703. goto end;
  12704. }
  12705. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12706. {
  12707. FILE *fp;
  12708. char dataLine[4096]={0};
  12709. char fnametemp[128]={0};
  12710. int tmpProfileQuantity;
  12711. //Check ChargePointMaxProfile.json exit
  12712. profileQuantity = 0;
  12713. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12714. {
  12715. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  12716. //Check Charging Profile Count
  12717. tmpProfileQuantity = 0;
  12718. while(fscanf(fp, "%s", dataLine) != EOF)
  12719. {
  12720. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12721. {
  12722. profileQuantity += 1;
  12723. tmpProfileQuantity += 1;
  12724. }
  12725. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12726. }
  12727. fclose(fp);
  12728. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12729. }
  12730. //Check TxDefaultProfile_%d.json
  12731. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12732. {
  12733. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12734. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12735. if((access(fnametemp,F_OK))!=-1)
  12736. {
  12737. fp = fopen(fnametemp, "r");
  12738. //Check Charging Profile Count
  12739. tmpProfileQuantity = 0;
  12740. while(fscanf(fp, "%s", dataLine) != EOF)
  12741. {
  12742. //DEBUG_INFO("word=%s\n",word);
  12743. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12744. {
  12745. profileQuantity += 1;
  12746. tmpProfileQuantity += 1;
  12747. }
  12748. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12749. }
  12750. fclose(fp);
  12751. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12752. }
  12753. }
  12754. //Check TxProfile_%d.json
  12755. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12756. {
  12757. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12758. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  12759. if((access(fnametemp,F_OK))!=-1)
  12760. {
  12761. fp = fopen(fnametemp, "r");
  12762. //Check Charging Profile Count
  12763. tmpProfileQuantity = 0;
  12764. while(fscanf(fp, "%s", dataLine) != EOF)
  12765. {
  12766. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12767. {
  12768. profileQuantity += 1;
  12769. tmpProfileQuantity += 1;
  12770. }
  12771. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12772. }
  12773. fclose(fp);
  12774. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12775. }
  12776. }
  12777. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12778. if((profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData)) && (isReplaceable != TRUE))
  12779. {
  12780. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12781. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12782. goto end;
  12783. }
  12784. }
  12785. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12786. //**********************************Write to File********************************************************/
  12787. {
  12788. FILE *infile;
  12789. FILE *outfile;
  12790. char dataLine[4096]={0};
  12791. char filename[128]={0};
  12792. int chkChar=0;
  12793. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12794. {
  12795. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12796. {
  12797. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12798. }
  12799. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12800. {
  12801. if(SetProfileReq.ConnectorId==0)
  12802. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12803. else
  12804. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12805. }
  12806. else
  12807. {
  12808. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12809. }
  12810. infile = fopen (filename, "r");
  12811. outfile = fopen (tempfile, "w");
  12812. chkChar = fgetc(infile);
  12813. rewind(infile);
  12814. if(chkChar == EOF)
  12815. {
  12816. // Profile is empty
  12817. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12818. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12819. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12820. fclose(infile);
  12821. fclose(outfile);
  12822. sprintf(rmFileCmd,"rm -f %s",filename);
  12823. system(rmFileCmd);
  12824. rename(tempfile, filename);
  12825. }
  12826. else
  12827. {
  12828. // Profile is not empty
  12829. int ChargingProfileAdded = FALSE;
  12830. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12831. {
  12832. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12833. json_object *tmpChargingProfile;
  12834. tmpChargingProfile = json_tokener_parse(dataLine);
  12835. if(!is_error(SetChargingProfile))
  12836. {
  12837. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12838. {
  12839. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12840. {
  12841. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12842. }
  12843. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12844. {
  12845. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  12846. }
  12847. }
  12848. }
  12849. json_object_put(tmpChargingProfile);
  12850. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12851. {
  12852. if(ChargingProfileAdded == FALSE)
  12853. {
  12854. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12855. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12856. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12857. ChargingProfileAdded = TRUE;
  12858. }
  12859. }
  12860. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  12861. {
  12862. if(ChargingProfileAdded == FALSE)
  12863. {
  12864. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12865. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12866. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12867. ChargingProfileAdded = TRUE;
  12868. }
  12869. }
  12870. else
  12871. {
  12872. fprintf(outfile,"%s\n",dataLine);
  12873. if(ChargingProfileAdded == FALSE)
  12874. {
  12875. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12876. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12877. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12878. ChargingProfileAdded = TRUE;
  12879. }
  12880. }
  12881. } // end of while loop
  12882. fclose(infile);
  12883. fclose(outfile);
  12884. sprintf(rmFileCmd,"rm -f %s",filename);
  12885. system(rmFileCmd);
  12886. rename(tempfile, filename);
  12887. }
  12888. }
  12889. sleep(1);
  12890. result = TRUE;
  12891. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12892. }
  12893. end:
  12894. json_object_put(SetChargingProfile);
  12895. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12896. {
  12897. if(SetProfileReq.ConnectorId == 0)
  12898. {
  12899. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12900. {
  12901. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  12902. }
  12903. }
  12904. else
  12905. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12906. }
  12907. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12908. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12909. return result;
  12910. }
  12911. int handleTriggerMessageRequest(char *uuid, char *payload)
  12912. {
  12913. mtrace();
  12914. int result = FAIL;
  12915. int connectorIdIsNULL = FALSE;
  12916. int connectorIdInt =0;
  12917. char sstr[40]={0},sstrtemp[100]={ 0 };
  12918. char requestedMessagestr[40]={0};
  12919. char comfirmstr[20]={0};
  12920. int c = 0;
  12921. char *loc;
  12922. DEBUG_INFO("handleTriggerMessageRequest\n");
  12923. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12924. strcpy(sstrtemp, stringtrimspace(payload));
  12925. c = 0;
  12926. loc = strstr(sstrtemp, "requestedMessage");
  12927. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12928. {
  12929. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12930. c++;
  12931. }
  12932. sstr[c] = '\0';
  12933. strcpy(requestedMessagestr, sstr);
  12934. c = 0;
  12935. loc = strstr(sstrtemp, "connectorId");
  12936. if(loc == NULL)
  12937. {
  12938. connectorIdIsNULL = TRUE;
  12939. }
  12940. else
  12941. {
  12942. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12943. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12944. {
  12945. sstr[c] = loc[strlen("connectorId")+2+c];
  12946. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12947. c++;
  12948. }
  12949. sstr[c] = '\0';
  12950. connectorIdInt = atoi(sstr);
  12951. }
  12952. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12953. {
  12954. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12955. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12956. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12957. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12958. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12959. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12960. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12961. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12962. {
  12963. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12964. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12965. return TRUE;
  12966. }
  12967. else
  12968. {
  12969. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12970. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12971. }
  12972. }
  12973. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12974. {
  12975. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12976. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12977. return TRUE;
  12978. }
  12979. //==========================
  12980. // Trigger message
  12981. //==========================
  12982. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12983. {
  12984. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  12985. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12986. {
  12987. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12988. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12989. }
  12990. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12991. }
  12992. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12993. {
  12994. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  12995. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12996. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12997. }
  12998. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12999. {
  13000. //sendBootNotificationRequest();
  13001. server_sign = FALSE;
  13002. }
  13003. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  13004. {
  13005. refreshStartTimer(&clientTime.Heartbeat);
  13006. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13007. }
  13008. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  13009. {
  13010. if(connectorIdIsNULL == FALSE)
  13011. {
  13012. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13013. {
  13014. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  13015. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  13016. }
  13017. }
  13018. else
  13019. {
  13020. for(int idx=0;idx< gunTotalNumber;idx++)
  13021. {
  13022. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13023. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13024. }
  13025. }
  13026. }
  13027. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  13028. {
  13029. if(connectorIdIsNULL == FALSE)
  13030. {
  13031. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13032. {
  13033. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  13034. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  13035. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13036. }
  13037. }
  13038. else
  13039. {
  13040. for(int idx=0;idx< gunTotalNumber;idx++)
  13041. {
  13042. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  13043. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13044. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13045. }
  13046. }
  13047. }
  13048. return result;
  13049. }
  13050. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13051. {
  13052. mtrace();
  13053. int result = FAIL;
  13054. int connectorIdInt =0;
  13055. char comfirmstr[20]={0};
  13056. int tempIndex = 0;
  13057. json_object *UnlockConnector;
  13058. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13059. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13060. UnlockConnector = json_tokener_parse(payload);
  13061. if(!is_error(UnlockConnector))
  13062. {
  13063. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13064. {
  13065. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13066. }
  13067. }
  13068. json_object_put(UnlockConnector);
  13069. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13070. if(gunTotalNumber == 0)
  13071. {
  13072. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13073. goto end;
  13074. }
  13075. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13076. {
  13077. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13078. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13079. goto end;
  13080. }
  13081. else
  13082. {
  13083. //check Transaction active
  13084. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13085. {
  13086. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13087. {
  13088. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13089. }
  13090. else
  13091. {
  13092. tempIndex = connectorIdInt -1;
  13093. }
  13094. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13095. {
  13096. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13097. {
  13098. //stop Transaction
  13099. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13100. }
  13101. }
  13102. }
  13103. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13104. {
  13105. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13106. {
  13107. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13108. }
  13109. else
  13110. {
  13111. tempIndex = connectorIdInt -1;
  13112. }
  13113. for (int index = 0; index < CCS_QUANTITY; index++)
  13114. {
  13115. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13116. {
  13117. //stop Transaction
  13118. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13119. }
  13120. }
  13121. }
  13122. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13123. {
  13124. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13125. {
  13126. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13127. }
  13128. else
  13129. {
  13130. tempIndex = connectorIdInt -1;
  13131. }
  13132. for (int index = 0; index < GB_QUANTITY; index++)
  13133. {
  13134. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13135. {
  13136. //stop Transaction
  13137. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13138. }
  13139. }
  13140. }
  13141. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13142. {
  13143. tempIndex = connectorIdInt -1;
  13144. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13145. {
  13146. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13147. {
  13148. //stop Transaction
  13149. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13150. }
  13151. }
  13152. }
  13153. else
  13154. {
  13155. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13156. {
  13157. tempIndex = 2;
  13158. }
  13159. else
  13160. {
  13161. tempIndex = connectorIdInt-1;
  13162. }
  13163. for (int index = 0; index < AC_QUANTITY; index++)
  13164. {
  13165. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  13166. {
  13167. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13168. }
  13169. }
  13170. }
  13171. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  13172. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  13173. result = TRUE;
  13174. return result;
  13175. }
  13176. end:
  13177. //json_object_put(obj); --- remove temporally
  13178. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  13179. return result;
  13180. }
  13181. static char UpdateFirmwarepayloadData[300]={0};
  13182. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13183. {
  13184. mtrace();
  13185. int result = FAIL;
  13186. pthread_t t;
  13187. sendUpdateFirmwareConfirmation(uuid);
  13188. memset(UpdateFirmwarepayloadData, 0, 300);
  13189. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  13190. if(!interLock.isUpdateFirmwareGoing)
  13191. {
  13192. interLock.isUpdateFirmwareGoing = 1;
  13193. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  13194. sleep(1);
  13195. }
  13196. else
  13197. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13198. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  13199. return result;
  13200. }
  13201. void *UpdateFirmwareProcess(void *data)
  13202. {
  13203. pthread_detach(pthread_self());
  13204. mtrace();
  13205. int retriesInt =0, retryIntervalInt=0;
  13206. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  13207. int port=0;
  13208. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  13209. int isSuccess = 0;
  13210. char ftpbuf[1024];
  13211. char temp[1024];
  13212. char * pch;
  13213. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13214. json_object *UpdateFirmware;
  13215. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  13216. if(!is_error(UpdateFirmware))
  13217. {
  13218. // Required data
  13219. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13220. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13221. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13222. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13223. // Optional data
  13224. if(json_object_object_get(UpdateFirmware, "retries"))
  13225. {
  13226. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13227. }
  13228. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13229. {
  13230. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13231. }
  13232. }
  13233. json_object_put(UpdateFirmware);
  13234. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13235. memset(path, 0, ARRAY_SIZE(path));
  13236. // Wait retrieveData
  13237. if(strlen(retrieveDatestr) > 10)
  13238. {
  13239. do
  13240. {
  13241. sleep(1);
  13242. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13243. }
  13244. // Ready to download
  13245. system("rm -f /mnt/*");
  13246. if(strncmp(locationstr,"http", 4) == 0)
  13247. {
  13248. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13249. sprintf(ftppath,"/%s", path);
  13250. DEBUG_INFO("locationstr: %s\n", locationstr);
  13251. DEBUG_INFO("protocol: %s\n",protocol);
  13252. DEBUG_INFO("host: %s\n",host);
  13253. DEBUG_INFO("path: %s\n",path);
  13254. DEBUG_INFO("ftppath: %s\n",ftppath);
  13255. int ftppathlen=strlen(ftppath);
  13256. int i=1;
  13257. char filenametemp[50];
  13258. while(i < ftppathlen)
  13259. {
  13260. int len=ftppathlen-i;
  13261. if(ftppath[len]== 47) // '/' ascll code: 47
  13262. {
  13263. DEBUG_INFO("compare '/' all right\n");
  13264. break;
  13265. }
  13266. i=i+1;
  13267. }
  13268. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13269. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13270. filenametemp[i+1] = 0;
  13271. do
  13272. {
  13273. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13274. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13275. sleep(1);
  13276. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13277. if(!isSuccess)
  13278. {
  13279. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13280. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13281. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13282. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13283. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13284. }
  13285. else
  13286. {
  13287. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13288. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13289. }
  13290. retriesInt--;
  13291. }while((isSuccess == 0)&&(retriesInt >= 0));
  13292. }
  13293. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13294. {
  13295. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13296. memset(temp, 0, ARRAY_SIZE(temp));
  13297. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13298. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13299. int ftppathlen=strlen(ftpbuf);
  13300. int i=1;
  13301. char filenametemp[50];
  13302. while(i < ftppathlen)
  13303. {
  13304. int len=ftppathlen-i;
  13305. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13306. {
  13307. DEBUG_INFO(" compare '/' all right\n");
  13308. break;
  13309. }
  13310. i=i+1;
  13311. }
  13312. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13313. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13314. filenametemp[i+1] = 0;
  13315. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13316. pch=strchr(temp,'@');
  13317. if(pch==NULL)
  13318. {
  13319. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13320. protocol, host, &port, path);
  13321. strcpy(user,"anonymous");
  13322. strcpy(password,"");
  13323. }
  13324. else
  13325. {
  13326. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13327. protocol, user, password, host, &port, path);
  13328. }
  13329. sscanf(host,"%[^/]%s",host1, path1);
  13330. sprintf(ftppath,"%s", path1);
  13331. //DEBUG_INFO("protocol =%s\n",protocol);
  13332. //DEBUG_INFO("user =%s\n",user);
  13333. //DEBUG_INFO("password =%s\n",password);
  13334. //DEBUG_INFO("host1 =%s\n",host1);
  13335. //DEBUG_INFO("port =%d\n",port);
  13336. //DEBUG_INFO("path1 =%s\n",path1);
  13337. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13338. //ftpFile(host, user, password, port, ftppath, fname);
  13339. //download firmware pthred
  13340. if(port == 0)
  13341. {
  13342. port = 21;
  13343. }
  13344. do
  13345. {
  13346. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13347. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13348. sleep(1);
  13349. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13350. if(!isSuccess)
  13351. {
  13352. //BulldogUtil.sleepMs(interval*1000);
  13353. DEBUG_INFO("Update firmware request and download file fail.\n");
  13354. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13355. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13356. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13357. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13358. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13359. }
  13360. else
  13361. {
  13362. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13363. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13364. }
  13365. retriesInt--;
  13366. }while((!isSuccess)&&(retriesInt >= 0));
  13367. }
  13368. else
  13369. {
  13370. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13371. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13372. sleep(1);
  13373. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13374. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13375. }
  13376. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13377. interLock.isUpdateFirmwareGoing = 0;
  13378. pthread_exit(NULL);
  13379. }
  13380. int handleCertificateSignedRequest(char *uuid, char *payload)
  13381. {
  13382. mtrace();
  13383. int result = PASS;
  13384. json_object *CertificateSigned;
  13385. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13386. CertificateSigned = json_tokener_parse(payload);
  13387. if(!is_error(CertificateSigned))
  13388. {
  13389. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13390. }
  13391. json_object_put(CertificateSigned);
  13392. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  13393. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  13394. fclose(fp);
  13395. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13396. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  13397. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  13398. sendCertificateSignedConfirmation(uuid);
  13399. return result;
  13400. }
  13401. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13402. {
  13403. mtrace();
  13404. int result = PASS;
  13405. json_object *DeleteCertificate;
  13406. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13407. DeleteCertificate = json_tokener_parse(payload);
  13408. if(!is_error(DeleteCertificate))
  13409. {
  13410. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13411. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13412. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13413. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13414. }
  13415. json_object_put(DeleteCertificate);
  13416. /*
  13417. * TODO: Delete certificateSigned process
  13418. */
  13419. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  13420. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  13421. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  13422. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  13423. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  13424. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  13425. sendDeleteCertificateConfirmation(uuid);
  13426. return result;
  13427. }
  13428. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13429. {
  13430. mtrace();
  13431. int result = PASS;
  13432. json_object *ExtendedTriggerMessage;
  13433. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13434. ExtendedTriggerMessage = json_tokener_parse(payload);
  13435. if(!is_error(ExtendedTriggerMessage))
  13436. {
  13437. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13438. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13439. {
  13440. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13441. }
  13442. else
  13443. {
  13444. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  13445. }
  13446. }
  13447. json_object_put(ExtendedTriggerMessage);
  13448. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  13449. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  13450. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13451. {
  13452. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13453. }
  13454. else
  13455. {
  13456. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13457. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13458. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13459. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13460. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13461. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13462. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13463. {
  13464. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13465. }
  13466. else
  13467. {
  13468. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13469. }
  13470. }
  13471. sendExtendedTriggerMessageConfirmation(uuid);
  13472. //==========================
  13473. // Trigger message
  13474. //==========================
  13475. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13476. {
  13477. //sendBootNotificationRequest();
  13478. server_sign = FALSE;
  13479. }
  13480. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13481. {
  13482. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13483. }
  13484. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13485. {
  13486. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13487. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13488. {
  13489. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13490. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13491. }
  13492. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13493. }
  13494. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13495. {
  13496. refreshStartTimer(&clientTime.Heartbeat);
  13497. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13498. }
  13499. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13500. {
  13501. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13502. {
  13503. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13504. }
  13505. else
  13506. {
  13507. for(int idx=0;idx< gunTotalNumber;idx++)
  13508. {
  13509. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13510. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13511. }
  13512. }
  13513. }
  13514. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13515. {
  13516. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  13517. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  13518. {
  13519. 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\" &");
  13520. }
  13521. }
  13522. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13523. {
  13524. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13525. {
  13526. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13527. }
  13528. else
  13529. {
  13530. for(int idx=0;idx< gunTotalNumber;idx++)
  13531. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13532. }
  13533. }
  13534. return result;
  13535. }
  13536. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13537. {
  13538. mtrace();
  13539. int result = PASS;
  13540. json_object *GetInstalledCertificateIds;
  13541. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13542. GetInstalledCertificateIds = json_tokener_parse(payload);
  13543. if(!is_error(GetInstalledCertificateIds))
  13544. {
  13545. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13546. }
  13547. json_object_put(GetInstalledCertificateIds);
  13548. /*
  13549. * TODO: Return installed certificate process
  13550. */
  13551. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13552. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  13553. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13554. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13555. sendGetInstalledCertificateIdsConfirmation(uuid);
  13556. return result;
  13557. }
  13558. int handleGetLogRequest(char *uuid, char *payload)
  13559. {
  13560. mtrace();
  13561. int result = PASS;
  13562. json_object *GetLog;
  13563. DEBUG_INFO("handleGetLogRequest...\n");
  13564. GetLog = json_tokener_parse(payload);
  13565. if(!is_error(GetLog))
  13566. {
  13567. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13568. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13569. if(json_object_object_get(GetLog, "retries") != NULL)
  13570. {
  13571. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13572. }
  13573. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13574. {
  13575. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13576. }
  13577. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13578. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13579. {
  13580. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13581. }
  13582. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13583. {
  13584. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13585. }
  13586. }
  13587. json_object_put(GetLog);
  13588. /*
  13589. * TODO: Upload log process
  13590. */
  13591. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  13592. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  13593. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  13594. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  13595. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  13596. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  13597. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  13598. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  13599. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  13600. sendGetLogConfirmation(uuid);
  13601. return result;
  13602. }
  13603. int handleInstallCertificateRequest(char *uuid, char *payload)
  13604. {
  13605. mtrace();
  13606. int result = PASS;
  13607. json_object *InstallCertificate;
  13608. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13609. InstallCertificate = json_tokener_parse(payload);
  13610. if(!is_error(InstallCertificate))
  13611. {
  13612. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13613. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13614. /*
  13615. * TODO: Install certificate process
  13616. */
  13617. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  13618. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  13619. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  13620. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  13621. sendInstallCertificateConfirmation(uuid);
  13622. }
  13623. json_object_put(InstallCertificate);
  13624. return result;
  13625. }
  13626. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13627. {
  13628. mtrace();
  13629. int result = PASS;
  13630. json_object *SignedUpdateFirmware;
  13631. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13632. SignedUpdateFirmware = json_tokener_parse(payload);
  13633. if(!is_error(SignedUpdateFirmware))
  13634. {
  13635. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13636. {
  13637. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13638. }
  13639. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13640. {
  13641. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13642. }
  13643. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13644. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13645. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13646. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13647. {
  13648. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13649. }
  13650. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13651. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13652. }
  13653. json_object_put(SignedUpdateFirmware);
  13654. /*
  13655. * TODO: Upgrade firmware process
  13656. */
  13657. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13658. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  13659. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  13660. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  13661. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  13662. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  13663. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  13664. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  13665. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  13666. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  13667. sendInstallCertificateConfirmation(uuid);
  13668. return result;
  13669. }
  13670. int handleUnknownRequest(char *uuid, char *payload)
  13671. {
  13672. mtrace();
  13673. int result = PASS;
  13674. DEBUG_INFO("handleUnknownRequest...\n");
  13675. sendUnknownConfirmation(uuid);
  13676. result = PASS;
  13677. return result;
  13678. }
  13679. //==========================================
  13680. // Handle server response routine
  13681. //==========================================
  13682. void handleAuthorizeResponse(char *payload, int gun_index)
  13683. {
  13684. mtrace();
  13685. char expiryDatestr[30]={0};
  13686. char parentIdTagstr[20]={0};
  13687. char statusstr[20]={0};
  13688. int expiryDateISNULL=FALSE;
  13689. int parentIdTagISNULL=FALSE;
  13690. DEBUG_INFO("handleAuthorizeResponse...\n");
  13691. json_object *Authorize;
  13692. Authorize = json_tokener_parse(payload);
  13693. if(!is_error(Authorize))
  13694. {
  13695. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13696. {
  13697. // Required data
  13698. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13699. // Optional data
  13700. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13701. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13702. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13703. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13704. }
  13705. }
  13706. json_object_put(Authorize);
  13707. if(expiryDateISNULL == FALSE)
  13708. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13709. if(parentIdTagISNULL == FALSE)
  13710. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13711. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  13712. //Update idTag information to authorization cache if supproted
  13713. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13714. {
  13715. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13716. }
  13717. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  13718. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13719. authorizeRetryTimes = 0;
  13720. }
  13721. void handleBootNotificationResponse(char *payload, int gun_index)
  13722. {
  13723. mtrace();
  13724. char statusStr[12]={0};
  13725. char currentTimeStr[30]={0};
  13726. int intervalInt = 0;
  13727. DEBUG_INFO("handleBootNotificationResponse...\n");
  13728. json_object *BootNotification;
  13729. BootNotification = json_tokener_parse(payload);
  13730. if(!is_error(BootNotification))
  13731. {
  13732. // Required data
  13733. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13734. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13735. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13736. }
  13737. json_object_put(BootNotification);
  13738. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13739. BootNotificationInterval = intervalInt;
  13740. //write back to ShmOCPP16Data->BootNotification
  13741. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  13742. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13743. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  13744. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13745. {
  13746. BootNotificationInterval = 0;
  13747. if((intervalInt == 0) || (intervalInt >= 10))
  13748. {
  13749. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13750. HeartBeatWaitTime = intervalInt;
  13751. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13752. }
  13753. server_sign = TRUE;
  13754. server_pending =FALSE;
  13755. }
  13756. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13757. {
  13758. server_pending = TRUE;
  13759. }
  13760. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  13761. srand(time(NULL));
  13762. refreshStartTimer(&clientTime.Heartbeat);
  13763. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13764. SetOcppConnStatus(TRUE);
  13765. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  13766. }
  13767. void handleDataTransferResponse(char *payload, int gun_index)
  13768. {
  13769. json_object *DataTransfer = json_tokener_parse(payload);
  13770. if(!is_error(DataTransfer))
  13771. {
  13772. // Required data
  13773. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13774. // Optional data
  13775. if(json_object_object_get(DataTransfer, "data") != NULL)
  13776. {
  13777. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13778. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13779. if(!is_error(Data))
  13780. {
  13781. if(json_object_object_get(Data, "msgId") != NULL)
  13782. {
  13783. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13784. {
  13785. OCPP_update_deduct_info(json_object_get_int(json_object_object_get(Data, "txId")), (char*)json_object_get_string(json_object_object_get(Data, "creditNo")));
  13786. }
  13787. }
  13788. }
  13789. json_object_put(Data);
  13790. }
  13791. }
  13792. json_object_put(DataTransfer);
  13793. }
  13794. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13795. {
  13796. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13797. //struct json_object *obj;
  13798. // obj = json_tokener_parse(payload);
  13799. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13800. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13801. //No fields are defined.
  13802. }
  13803. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13804. {
  13805. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13806. //struct json_object *obj;
  13807. // obj = json_tokener_parse(payload);
  13808. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13809. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13810. //No fields are defined.
  13811. }
  13812. void handleHeartbeatResponse(char *payload, int gun_index)
  13813. {
  13814. mtrace();
  13815. DEBUG_INFO("handleHeartbeatResponse...\n");
  13816. json_object *Heartbeat;
  13817. Heartbeat = json_tokener_parse(payload);
  13818. if(!is_error(Heartbeat))
  13819. {
  13820. // Required data
  13821. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13822. }
  13823. json_object_put(Heartbeat);
  13824. if(FirstHeartBeat == 0)
  13825. {
  13826. FirstHeartBeat = 1;
  13827. DEBUG_INFO("FirstHeartBeat \n");
  13828. }
  13829. HeartBeatWithNOResponse = 0;
  13830. refreshStartTimer(&clientTime.Heartbeat);
  13831. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  13832. }
  13833. void handleMeterValuesResponse(char *payload, int gun_index)
  13834. {
  13835. mtrace();
  13836. DEBUG_INFO("handleMeterValuesResponse...\n");
  13837. isQueueSendable = 1;
  13838. }
  13839. void handleStartTransactionResponse(char *payload, int gun_index)
  13840. {
  13841. mtrace();
  13842. //int transactionIdInt = 0;
  13843. FILE *outfile;
  13844. char data[100]={0};
  13845. DEBUG_INFO("handleStartTransactionResponse...\n");
  13846. json_object *StartTransaction;
  13847. StartTransaction = json_tokener_parse(payload);
  13848. if(!is_error(StartTransaction))
  13849. {
  13850. // Required data
  13851. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13852. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13853. // Optional data
  13854. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13855. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13856. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13857. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13858. }
  13859. json_object_put(StartTransaction);
  13860. isQueueSendable = 1;
  13861. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13862. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13863. //-----------Start : write to the Queue TransactionId file -----------------//
  13864. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  13865. {}
  13866. else
  13867. {
  13868. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  13869. if(log == NULL)
  13870. {
  13871. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13872. return ;
  13873. }
  13874. else
  13875. {
  13876. fclose(log);
  13877. }
  13878. }
  13879. // open file for writing
  13880. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13881. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  13882. {
  13883. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  13884. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13885. fputs(data, outfile);
  13886. fclose (outfile);
  13887. }
  13888. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13889. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13890. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13891. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  13892. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13893. }
  13894. void handleStatusNotificationResponse(char *payload, int gun_index)
  13895. {
  13896. mtrace();
  13897. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13898. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13899. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13900. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13901. }
  13902. void handleStopTransactionnResponse(char *payload, int gun_index)
  13903. {
  13904. mtrace();
  13905. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13906. json_object *StopTransaction;
  13907. StopTransaction = json_tokener_parse(payload);
  13908. if(!is_error(StopTransaction))
  13909. {
  13910. // Optional data
  13911. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13912. {
  13913. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13914. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13915. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13916. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13917. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13918. }
  13919. }
  13920. json_object_put(StopTransaction);
  13921. isQueueSendable = 1;
  13922. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13923. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13924. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13925. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13926. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13927. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13928. }
  13929. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13930. {
  13931. mtrace();
  13932. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13933. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  13934. }
  13935. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13936. {
  13937. mtrace();
  13938. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13939. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  13940. }
  13941. void handleSignCertificateResponse(char *payload, int gun_index)
  13942. {
  13943. mtrace();
  13944. DEBUG_INFO("handleSignCertificateResponse...\n");
  13945. json_object *SignCertificate;
  13946. SignCertificate = json_tokener_parse(payload);
  13947. if(!is_error(SignCertificate))
  13948. {
  13949. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13950. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  13951. }
  13952. json_object_put(SignCertificate);
  13953. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  13954. }
  13955. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13956. {
  13957. mtrace();
  13958. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13959. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13960. }
  13961. //==========================================
  13962. // Handle Error routine
  13963. //==========================================
  13964. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13965. {
  13966. mtrace();
  13967. #ifdef SystemLogMessage
  13968. DEBUG_INFO("errorCode: %s\n", errorCode);
  13969. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13970. DEBUG_INFO("errorDetails: %s\n", payload);
  13971. #endif
  13972. }
  13973. //===============================================
  13974. // Common routine
  13975. //===============================================
  13976. int initialConfigurationTable(void)
  13977. {
  13978. //clock_t start_t, end_t, total_t;
  13979. FILE *fp;
  13980. FILE *outfile;
  13981. char str[512]={0};
  13982. char sstr[256]={0};
  13983. int c = 0;
  13984. char *loc;
  13985. int confVersion = 14;
  13986. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13987. //start_t = clock();
  13988. //printf("Starting of the program, start_t = %ld\n", start_t);
  13989. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13990. // Check configuration file size is correct
  13991. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  13992. {
  13993. struct stat st;
  13994. stat("/Storage/OCPP/OCPPConfiguration", &st);
  13995. if(st.st_size < 3100)
  13996. {
  13997. system("rm -f /Storage/OCPP/OCPPConfiguration");
  13998. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13999. }
  14000. }
  14001. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  14002. {
  14003. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14004. if(outfile == NULL)
  14005. {
  14006. DEBUG_INFO("Error opening file\n");
  14007. return FALSE;
  14008. }
  14009. /*Core Profile*/
  14010. //AllowOfflineTxForUnknownId
  14011. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14012. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  14014. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14015. //AuthorizationCacheEnabled
  14016. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14017. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14018. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14019. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14020. //AuthorizeRemoteTxRequests
  14021. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14022. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14023. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  14024. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14025. //BlinkRepeat
  14026. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14029. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14030. //ClockAlignedDataInterval
  14031. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14032. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14033. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14034. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14035. //ConnectionTimeOut
  14036. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14037. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14038. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14039. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14040. //GetConfigurationMaxKeys
  14041. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14043. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  14044. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14045. // HeartbeatInterval
  14046. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  14049. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14050. // LightIntensity
  14051. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14054. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14055. // LocalAuthorizeOffline
  14056. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  14057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14059. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14060. // LocalPreAuthorize
  14061. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  14062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14064. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14065. // MaxEnergyOnInvalidId
  14066. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14067. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14069. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14070. // MeterValuesAlignedData
  14071. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14073. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14074. 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" );
  14075. else
  14076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14077. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14078. // MeterValuesAlignedDataMaxLength
  14079. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14080. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14081. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  14083. else
  14084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  14085. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14086. // MeterValuesSampledData
  14087. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14089. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14090. 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" );
  14091. else
  14092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14093. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14094. // MeterValuesSampledDataMaxLength
  14095. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14097. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  14099. else
  14100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  14101. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14102. // MeterValueSampleInterval
  14103. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  14106. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14107. // MinimumStatusDuration
  14108. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  14111. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  14112. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14113. // NumberOfConnectors
  14114. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14116. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14117. {
  14118. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14119. }
  14120. else
  14121. {
  14122. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14123. }
  14124. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14125. // ResetRetries
  14126. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14128. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14129. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14130. // ConnectorPhaseRotation
  14131. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14134. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14135. // ConnectorPhaseRotationMaxLength
  14136. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14138. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14139. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14140. // StopTransactionOnEVSideDisconnect
  14141. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14143. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14144. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14145. // StopTransactionOnInvalidId
  14146. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  14147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14149. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14150. // StopTxnAlignedData
  14151. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  14152. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  14154. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14155. // StopTxnAlignedDataMaxLength
  14156. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14158. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14159. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14160. // StopTxnSampledData
  14161. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14163. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14164. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  14165. else
  14166. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  14167. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14168. // StopTxnSampledDataMaxLength
  14169. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14170. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14171. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14172. {
  14173. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  14174. }
  14175. else
  14176. {
  14177. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  14178. }
  14179. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14180. // SupportedFeatureProfiles
  14181. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14182. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14183. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14184. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14185. // SupportedFeatureProfilesMaxLength
  14186. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14187. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14188. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14189. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14190. // TransactionMessageAttempts
  14191. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14192. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14193. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14194. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14195. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14196. // TransactionMessageRetryInterval
  14197. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14198. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14200. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14202. // UnlockConnectorOnEVSideDisconnect
  14203. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14205. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14206. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14207. // WebSocketPingInterval
  14208. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14211. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14212. // QueueOffLineMeterValues
  14213. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  14214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14215. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  14216. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14217. // AuthorizationKey
  14218. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14219. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14221. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14222. // SecurityProfile
  14223. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14225. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14226. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14227. // DefaultPrice
  14228. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14229. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14230. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14231. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14232. // CustomDisplayCostAndPrice
  14233. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14234. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14236. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14237. // CustomIdleFeeAfterStop
  14238. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14239. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14241. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14242. // TimeOffset
  14243. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14244. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  14246. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14247. // NextTimeOffsetTransitionDateTime
  14248. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14249. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14250. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  14251. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14252. // TimeOffsetNextTransition
  14253. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  14256. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14257. // SystemUptimeSec
  14258. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14260. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14261. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14262. // FreeVend
  14263. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14264. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14266. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14267. // FreeVendIdtag
  14268. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14271. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14272. // OcppServer
  14273. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14274. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14275. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14276. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14277. // MaintainServer
  14278. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14279. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14280. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  14281. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14282. // StatusNotificationPeriodically
  14283. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  14284. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14286. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14287. // StatusNotificationInterval
  14288. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14291. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14292. // PreAuthAmount
  14293. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  14294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  14295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "888" );
  14296. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  14297. // Configuration Version
  14298. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  14299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14300. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  14301. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14302. //* Local Auth List Management Profile*/
  14303. #if 0
  14304. //For OCTT Test Case
  14305. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  14307. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14308. #endif
  14309. #if 1
  14310. //LocalAuthListEnabled
  14311. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14312. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14313. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14314. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14315. #endif
  14316. //LocalAuthListMaxLength
  14317. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14318. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14319. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  14320. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14321. //SendLocalListMaxLength
  14322. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14323. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14325. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14326. //ReserveConnectorZeroSupported
  14327. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14330. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14331. //* Smart Charging Profile */
  14332. //ChargeProfileMaxStackLevel
  14333. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14336. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14337. // ChargingScheduleAllowedChargingRateUnit
  14338. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14340. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  14341. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14342. // ChargingScheduleMaxPeriods
  14343. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14345. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14346. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14347. // ConnectorSwitch3to1PhaseSupported
  14348. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  14351. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14352. // MaxChargingProfilesInstalled
  14353. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14354. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14356. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14357. fclose(outfile);
  14358. }
  14359. else
  14360. {
  14361. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  14362. char keystr[60]={0};
  14363. char readonlystr[10]={0};
  14364. char valuestr[256]={0};
  14365. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  14366. if(fp == NULL) {
  14367. DEBUG_INFO("Error opening file");
  14368. return FALSE;
  14369. }
  14370. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  14371. {
  14372. //DEBUG_INFO("Get Configuration \n");
  14373. if(strlen(str) > 0)
  14374. {
  14375. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14376. //*************************key*********************************/
  14377. if(strstr(str, "key") != NULL)
  14378. {
  14379. loc = strstr(str, "key");
  14380. c = 0;
  14381. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14382. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14383. {
  14384. sstr[c] = loc[strlen("key")+3+c];
  14385. c++;
  14386. }
  14387. sstr[c] = '\0';
  14388. strcpy(keystr,sstr);
  14389. }
  14390. //*************************readonly*********************************/
  14391. if(strstr(str, "readonly") != NULL)
  14392. {
  14393. loc = strstr(str, "readonly");
  14394. c = 0;
  14395. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14396. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  14397. {
  14398. sstr[c] = loc[strlen("readonly")+2+c];
  14399. c++;
  14400. }
  14401. sstr[c] = '\0';
  14402. strcpy(readonlystr,sstr);
  14403. }
  14404. //*************************value*********************************/
  14405. if(strstr(str, "value") != NULL)
  14406. {
  14407. loc = strstr(str, "value");
  14408. c = 0;
  14409. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14410. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14411. {
  14412. sstr[c] = loc[strlen("value")+3+c];
  14413. c++;
  14414. }
  14415. sstr[c] = '\0';
  14416. strcpy(valuestr,sstr);
  14417. }
  14418. // DEBUG_INFO("keystr=%s\n",keystr);
  14419. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  14420. // DEBUG_INFO("valuestr=%s\n",valuestr);
  14421. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  14422. {
  14423. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14424. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14425. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14426. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14427. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14428. }
  14429. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14430. {
  14431. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14432. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14433. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14434. }
  14435. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14436. {
  14437. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14438. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14439. }
  14440. if(strcmp(keystr, "BlinkRepeat") == 0)
  14441. {
  14442. //Charger.BlinkRepeat = Integer.parseInt(value);
  14443. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14444. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14445. }
  14446. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14447. {
  14448. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14449. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14450. }
  14451. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14452. {
  14453. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14454. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14455. }
  14456. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14457. {
  14458. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14459. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14460. }
  14461. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14462. {
  14463. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14464. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14465. HeartBeatWaitTime = atoi(valuestr);
  14466. }
  14467. if(strcmp(keystr, "LightIntensity") == 0)
  14468. {
  14469. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14470. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14471. }
  14472. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14473. {
  14474. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14475. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14476. }
  14477. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14478. {
  14479. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14480. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14481. }
  14482. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14483. {
  14484. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14485. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14486. }
  14487. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14488. {
  14489. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14490. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14491. }
  14492. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14493. {
  14494. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14495. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14496. }
  14497. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14498. {
  14499. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14500. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14501. }
  14502. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14503. {
  14504. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14505. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14506. }
  14507. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14508. {
  14509. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14510. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14511. }
  14512. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14513. {
  14514. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14515. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14516. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14517. }
  14518. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14519. {
  14520. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14521. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14522. }
  14523. if(strcmp(keystr, "ResetRetries") == 0)
  14524. {
  14525. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14526. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14527. }
  14528. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14529. {
  14530. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14531. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14532. }
  14533. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14534. {
  14535. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14536. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14537. }
  14538. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14539. {
  14540. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14541. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14542. }
  14543. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14544. {
  14545. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14546. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14547. }
  14548. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14549. {
  14550. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14551. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14552. }
  14553. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14554. {
  14555. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14556. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14557. }
  14558. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14559. {
  14560. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14561. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14562. }
  14563. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14564. {
  14565. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14566. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14567. }
  14568. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14569. {
  14570. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14571. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14572. }
  14573. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14574. {
  14575. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14576. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14577. }
  14578. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14579. {
  14580. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14581. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14582. TransactionMessageAttemptsValue = atoi(valuestr);
  14583. }
  14584. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14585. {
  14586. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14587. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14588. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14589. }
  14590. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14591. {
  14592. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14593. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14594. }
  14595. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14596. {
  14597. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14598. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14599. }
  14600. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14601. {
  14602. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14603. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14604. }
  14605. if(strcmp(keystr, "AuthorizationKey") == 0)
  14606. {
  14607. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14608. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14609. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14610. }
  14611. if(strcmp(keystr, "SecurityProfile") == 0)
  14612. {
  14613. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14614. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14615. }
  14616. if(strcmp(keystr, "DefaultPrice") == 0)
  14617. {
  14618. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14619. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14620. }
  14621. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14622. {
  14623. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14624. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14625. }
  14626. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14627. {
  14628. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14629. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14630. }
  14631. if(strcmp(keystr, "TimeOffset") == 0)
  14632. {
  14633. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14634. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  14635. }
  14636. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  14637. {
  14638. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14639. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  14640. }
  14641. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  14642. {
  14643. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14644. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  14645. }
  14646. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14647. {
  14648. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14649. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  14650. }
  14651. if(strcmp(keystr, "FreeVend") == 0)
  14652. {
  14653. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14654. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14655. }
  14656. if(strcmp(keystr, "FreeVendIdtag") == 0)
  14657. {
  14658. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14659. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  14660. }
  14661. if(strcmp(keystr, "OcppServer") == 0)
  14662. {
  14663. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14664. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14665. }
  14666. if(strcmp(keystr, "MaintainServer") == 0)
  14667. {
  14668. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14669. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14670. }
  14671. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14672. {
  14673. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14674. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14675. }
  14676. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14677. {
  14678. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14679. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14680. }
  14681. if(strcmp(keystr, "PreAuthAmount") == 0)
  14682. {
  14683. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14684. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(valuestr));
  14685. }
  14686. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14687. {
  14688. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14689. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14690. }
  14691. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14692. {
  14693. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14694. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14695. }
  14696. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14697. {
  14698. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14699. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14700. }
  14701. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14702. {
  14703. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14704. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14705. }
  14706. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14707. {
  14708. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14709. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14710. }
  14711. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14712. {
  14713. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14714. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14715. }
  14716. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14717. {
  14718. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14719. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14720. }
  14721. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14722. {
  14723. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14724. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14725. }
  14726. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14727. {
  14728. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14729. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14730. }
  14731. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14732. {
  14733. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14734. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14735. }
  14736. }
  14737. }
  14738. fclose(fp);
  14739. }
  14740. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14741. {
  14742. return PASS;
  14743. }
  14744. else
  14745. {
  14746. return FAIL;
  14747. }
  14748. }
  14749. void StoreConfigurationTable(void)
  14750. {
  14751. FILE *outfile;
  14752. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14753. if(outfile == NULL)
  14754. {
  14755. DEBUG_INFO("Error opening file");
  14756. return ;
  14757. }
  14758. /*Core Profile*/
  14759. //AllowOfflineTxForUnknownId
  14760. /*
  14761. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14762. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14765. */
  14766. //DEBUG_INFO("data=%s\n",data);
  14767. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14768. //AuthorizationCacheEnabled
  14769. /*
  14770. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14771. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14773. */
  14774. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14775. //AuthorizeRemoteTxRequests
  14776. /*
  14777. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14780. */
  14781. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14782. //BlinkRepeat
  14783. /*
  14784. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14787. */
  14788. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14789. //ClockAlignedDataInterval
  14790. /*
  14791. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14794. */
  14795. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14796. //ConnectionTimeOut
  14797. /*
  14798. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14801. */
  14802. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14803. //GetConfigurationMaxKeys
  14804. /*
  14805. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14806. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14808. */
  14809. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14810. // HeartbeatInterval
  14811. /*
  14812. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14815. */
  14816. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14817. // LightIntensity
  14818. /*
  14819. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14820. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14821. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14822. */
  14823. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14824. // LocalAuthorizeOffline
  14825. /*
  14826. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14827. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14829. */
  14830. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14831. // LocalPreAuthorize
  14832. /*
  14833. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14834. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14835. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14836. */
  14837. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14838. // MaxEnergyOnInvalidId
  14839. /*
  14840. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14842. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14843. */
  14844. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14845. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14846. // MeterValuesAlignedData
  14847. /*
  14848. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14851. */
  14852. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14853. // MeterValuesAlignedDataMaxLength
  14854. /*
  14855. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14858. */
  14859. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14860. // MeterValuesSampledData
  14861. /*
  14862. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14865. */
  14866. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14867. // MeterValuesSampledDataMaxLength
  14868. /*
  14869. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14870. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14871. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14872. */
  14873. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14874. // MeterValueSampleInterval
  14875. /*
  14876. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14879. */
  14880. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14881. // MinimumStatusDuration
  14882. /*
  14883. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14884. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14885. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14886. */
  14887. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14888. // NumberOfConnectors
  14889. /*
  14890. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14891. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14892. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14893. {
  14894. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14895. }
  14896. else
  14897. {
  14898. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14899. }
  14900. */
  14901. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14902. // ResetRetries
  14903. /*
  14904. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14905. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14906. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14907. */
  14908. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14909. // ConnectorPhaseRotation
  14910. /*
  14911. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14912. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14913. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14914. */
  14915. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14916. // ConnectorPhaseRotationMaxLength
  14917. /*
  14918. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14919. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14920. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14921. */
  14922. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14923. // StopTransactionOnEVSideDisconnect
  14924. /*
  14925. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14926. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14927. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14928. */
  14929. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14930. // StopTransactionOnInvalidId
  14931. /*
  14932. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14933. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14934. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14935. */
  14936. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14937. // StopTxnAlignedData
  14938. /*
  14939. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14940. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14941. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14942. */
  14943. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14944. // StopTxnAlignedDataMaxLength
  14945. /*
  14946. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14947. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14948. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14949. */
  14950. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14951. // StopTxnSampledData
  14952. /*
  14953. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14954. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14955. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14956. */
  14957. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14958. // StopTxnSampledDataMaxLength
  14959. /*
  14960. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14961. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14962. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14963. */
  14964. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14965. // SupportedFeatureProfiles
  14966. /*
  14967. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14968. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14969. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14970. */
  14971. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14972. // SupportedFeatureProfilesMaxLength
  14973. /*
  14974. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14975. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14976. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14977. */
  14978. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14979. // TransactionMessageAttempts
  14980. /*
  14981. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14982. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14983. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14984. */
  14985. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14986. // TransactionMessageRetryInterval
  14987. /*
  14988. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14989. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14990. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14991. */
  14992. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14993. // UnlockConnectorOnEVSideDisconnect
  14994. /*
  14995. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14996. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14997. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14998. */
  14999. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15000. // WebSocketPingInterval
  15001. /*
  15002. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15003. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15004. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15005. */
  15006. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15007. // QueueOffLineMeterValues
  15008. /*
  15009. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  15010. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15011. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  15012. */
  15013. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15014. // AuthorizationKey
  15015. /*
  15016. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15017. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15018. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  15019. */
  15020. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15021. // SecurityProfile
  15022. /*
  15023. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15024. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15025. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  15026. */
  15027. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15028. // DefaultPrice
  15029. /*
  15030. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15031. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15032. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15033. */
  15034. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15035. // CustomDisplayCostAndPrice
  15036. /*
  15037. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15038. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15039. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15040. */
  15041. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15042. // CustomIdleFeeAfterStop
  15043. /*
  15044. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15045. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15046. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15047. */
  15048. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15049. // TimeOffset
  15050. /*
  15051. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  15052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  15053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  15054. */
  15055. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  15056. // NextTimeOffsetTransitionDateTime
  15057. /*
  15058. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  15059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  15060. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  15061. */
  15062. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  15063. // TimeOffsetNextTransition
  15064. /*
  15065. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  15066. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  15067. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  15068. */
  15069. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  15070. // SystemUptimeSec
  15071. /*
  15072. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15075. */
  15076. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15077. // FreeVend
  15078. /*
  15079. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15080. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15081. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  15082. */
  15083. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15084. // FreeVendIdtag
  15085. /*
  15086. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15089. */
  15090. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15091. // OcppServer
  15092. /*
  15093. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15095. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  15096. */
  15097. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15098. // MaintainServer
  15099. /*
  15100. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  15103. */
  15104. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15105. // StatusNotificationPeriodically
  15106. /*
  15107. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  15108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15110. */
  15111. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15112. // StatusNotificationInterval
  15113. /*
  15114. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15116. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15117. */
  15118. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15119. // PreAuthAmount
  15120. /*
  15121. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  15122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  15123. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "120" );
  15124. */
  15125. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  15126. // ConfigurationVersion
  15127. /*
  15128. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  15129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15130. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  15131. */
  15132. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15133. //* Local Auth List Management Profile*/
  15134. //LocalAuthListEnabled
  15135. /*
  15136. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15138. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15139. */
  15140. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15141. //LocalAuthListMaxLength
  15142. /*
  15143. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15144. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15145. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  15146. */
  15147. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15148. //SendLocalListMaxLength
  15149. /*
  15150. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15151. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15152. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  15153. */
  15154. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15155. //ReserveConnectorZeroSupported
  15156. /*
  15157. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15158. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15159. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15160. */
  15161. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15162. //* Smart Charging Profile */
  15163. //ChargeProfileMaxStackLevel
  15164. /*
  15165. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  15166. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  15167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  15168. */
  15169. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15170. // ChargingScheduleAllowedChargingRateUnit
  15171. /*
  15172. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  15173. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  15174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  15175. */
  15176. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15177. // ChargingScheduleMaxPeriods
  15178. /*
  15179. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  15180. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  15181. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  15182. */
  15183. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15184. // ConnectorSwitch3to1PhaseSupported
  15185. /*
  15186. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  15187. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  15188. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  15189. */
  15190. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15191. // MaxChargingProfilesInstalled
  15192. /*
  15193. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  15194. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  15195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  15196. */
  15197. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15198. fclose(outfile);
  15199. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15200. }
  15201. void getKeyValue(char *keyReq)
  15202. {
  15203. int isEmpty = FALSE;
  15204. int isKnowKey = FALSE;
  15205. DEBUG_INFO("keyReq = %s\n", keyReq);
  15206. if((keyReq == NULL) || (strlen(keyReq) == 0))
  15207. isEmpty = TRUE;
  15208. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  15209. {
  15210. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  15211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  15212. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15213. {
  15214. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  15215. }
  15216. else
  15217. {
  15218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  15219. }
  15220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  15221. isKnowKey = TRUE;
  15222. }
  15223. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  15224. {
  15225. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  15226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  15227. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15228. {
  15229. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  15230. }
  15231. else
  15232. {
  15233. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  15234. }
  15235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  15236. isKnowKey = TRUE;
  15237. }
  15238. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  15239. {
  15240. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  15241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  15242. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15243. {
  15244. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  15245. }
  15246. else
  15247. {
  15248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  15249. }
  15250. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  15251. isKnowKey = TRUE;
  15252. }
  15253. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  15254. {
  15255. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  15256. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  15257. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15258. {
  15259. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  15260. }
  15261. else
  15262. {
  15263. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  15264. }
  15265. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  15266. isKnowKey = TRUE;
  15267. }
  15268. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  15269. {
  15270. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  15271. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  15272. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15273. {
  15274. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  15275. }
  15276. else
  15277. {
  15278. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  15279. }
  15280. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  15281. isKnowKey = TRUE;
  15282. }
  15283. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  15284. {
  15285. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  15286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  15287. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15288. {
  15289. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  15290. }
  15291. else
  15292. {
  15293. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  15294. }
  15295. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  15296. isKnowKey = TRUE;
  15297. }
  15298. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  15299. {
  15300. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  15301. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  15302. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15303. {
  15304. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  15305. }
  15306. else
  15307. {
  15308. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  15309. }
  15310. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  15311. isKnowKey = TRUE;
  15312. }
  15313. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  15314. {
  15315. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  15316. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  15317. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15318. {
  15319. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  15320. }
  15321. else
  15322. {
  15323. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  15324. }
  15325. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  15326. isKnowKey = TRUE;
  15327. }
  15328. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  15329. {
  15330. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  15331. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  15332. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15333. {
  15334. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  15335. }
  15336. else
  15337. {
  15338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  15339. }
  15340. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  15341. isKnowKey = TRUE;
  15342. }
  15343. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  15344. {
  15345. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  15346. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  15347. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15348. {
  15349. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  15350. }
  15351. else
  15352. {
  15353. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  15354. }
  15355. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  15356. isKnowKey = TRUE;
  15357. }
  15358. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  15359. {
  15360. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  15361. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  15362. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15363. {
  15364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  15365. }
  15366. else
  15367. {
  15368. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  15369. }
  15370. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  15371. isKnowKey = TRUE;
  15372. }
  15373. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  15374. {
  15375. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  15376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  15377. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15378. {
  15379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15380. }
  15381. else
  15382. {
  15383. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15384. }
  15385. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  15386. isKnowKey = TRUE;
  15387. }
  15388. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  15389. {
  15390. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  15391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  15392. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15393. {
  15394. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15395. }
  15396. else
  15397. {
  15398. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15399. }
  15400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  15401. isKnowKey = TRUE;
  15402. }
  15403. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  15404. {
  15405. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  15406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  15407. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15408. {
  15409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15410. }
  15411. else
  15412. {
  15413. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15414. }
  15415. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  15416. isKnowKey = TRUE;
  15417. }
  15418. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  15419. {
  15420. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  15421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  15422. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15423. {
  15424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  15425. }
  15426. else
  15427. {
  15428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  15429. }
  15430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  15431. isKnowKey = TRUE;
  15432. }
  15433. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  15434. {
  15435. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  15436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  15437. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15438. {
  15439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15440. }
  15441. else
  15442. {
  15443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15444. }
  15445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  15446. isKnowKey = TRUE;
  15447. }
  15448. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  15449. {
  15450. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  15451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  15452. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15453. {
  15454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  15455. }
  15456. else
  15457. {
  15458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  15459. }
  15460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  15461. isKnowKey = TRUE;
  15462. }
  15463. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  15464. {
  15465. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  15466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  15467. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15468. {
  15469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  15470. }
  15471. else
  15472. {
  15473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  15474. }
  15475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  15476. isKnowKey = TRUE;
  15477. }
  15478. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  15479. {
  15480. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  15481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  15482. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15483. {
  15484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  15485. }
  15486. else
  15487. {
  15488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15489. }
  15490. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15492. isKnowKey = TRUE;
  15493. }
  15494. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15495. {
  15496. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15498. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15499. {
  15500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15501. }
  15502. else
  15503. {
  15504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15505. }
  15506. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15507. isKnowKey = TRUE;
  15508. }
  15509. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15510. {
  15511. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15513. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15514. {
  15515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15516. }
  15517. else
  15518. {
  15519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15520. }
  15521. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15522. isKnowKey = TRUE;
  15523. }
  15524. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15525. {
  15526. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15528. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15529. {
  15530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15531. }
  15532. else
  15533. {
  15534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15535. }
  15536. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15537. isKnowKey = TRUE;
  15538. }
  15539. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15540. {
  15541. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15543. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15544. {
  15545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15546. }
  15547. else
  15548. {
  15549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15550. }
  15551. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15552. isKnowKey = TRUE;
  15553. }
  15554. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15555. {
  15556. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15558. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15559. {
  15560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15561. }
  15562. else
  15563. {
  15564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15565. }
  15566. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15567. isKnowKey = TRUE;
  15568. }
  15569. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15570. {
  15571. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15572. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15573. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15574. {
  15575. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15576. }
  15577. else
  15578. {
  15579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15580. }
  15581. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15582. isKnowKey = TRUE;
  15583. }
  15584. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15585. {
  15586. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15587. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15588. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15589. {
  15590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15591. }
  15592. else
  15593. {
  15594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15595. }
  15596. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15597. isKnowKey = TRUE;
  15598. }
  15599. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15600. {
  15601. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15602. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15603. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15604. {
  15605. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15606. }
  15607. else
  15608. {
  15609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15610. }
  15611. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15612. isKnowKey = TRUE;
  15613. }
  15614. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15615. {
  15616. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15617. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15618. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15619. {
  15620. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15621. }
  15622. else
  15623. {
  15624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15625. }
  15626. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15627. isKnowKey = TRUE;
  15628. }
  15629. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15630. {
  15631. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15632. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15633. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15634. {
  15635. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15636. }
  15637. else
  15638. {
  15639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15640. }
  15641. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15642. isKnowKey = TRUE;
  15643. }
  15644. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15645. {
  15646. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15647. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15648. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15649. {
  15650. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15651. }
  15652. else
  15653. {
  15654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15655. }
  15656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15657. isKnowKey = TRUE;
  15658. }
  15659. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15660. {
  15661. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15663. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15664. {
  15665. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15666. }
  15667. else
  15668. {
  15669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15670. }
  15671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15672. isKnowKey = TRUE;
  15673. }
  15674. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15675. {
  15676. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15678. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15679. {
  15680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15681. }
  15682. else
  15683. {
  15684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15685. }
  15686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15687. isKnowKey = TRUE;
  15688. }
  15689. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15690. {
  15691. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15693. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15694. {
  15695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15696. }
  15697. else
  15698. {
  15699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15700. }
  15701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15702. isKnowKey = TRUE;
  15703. }
  15704. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15705. {
  15706. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15708. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15709. {
  15710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15711. }
  15712. else
  15713. {
  15714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15715. }
  15716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15717. isKnowKey = TRUE;
  15718. }
  15719. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15720. {
  15721. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15723. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15724. {
  15725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15726. }
  15727. else
  15728. {
  15729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15730. }
  15731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15732. isKnowKey = TRUE;
  15733. }
  15734. /*
  15735. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15736. {
  15737. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15739. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15740. {
  15741. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15742. }
  15743. else
  15744. {
  15745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15746. }
  15747. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15748. isKnowKey = TRUE;
  15749. }*/
  15750. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15751. {
  15752. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15754. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15755. {
  15756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15757. }
  15758. else
  15759. {
  15760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15761. }
  15762. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15763. isKnowKey = TRUE;
  15764. }
  15765. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15766. {
  15767. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15769. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15770. {
  15771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15772. }
  15773. else
  15774. {
  15775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15776. }
  15777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15778. isKnowKey = TRUE;
  15779. }
  15780. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15781. {
  15782. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15784. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15785. {
  15786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15787. }
  15788. else
  15789. {
  15790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15791. }
  15792. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15793. isKnowKey = TRUE;
  15794. }
  15795. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15796. {
  15797. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15798. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15799. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15800. {
  15801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15802. }
  15803. else
  15804. {
  15805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15806. }
  15807. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15808. isKnowKey = TRUE;
  15809. }
  15810. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  15811. {
  15812. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  15813. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  15814. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15815. {
  15816. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  15817. }
  15818. else
  15819. {
  15820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  15821. }
  15822. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  15823. isKnowKey = TRUE;
  15824. }
  15825. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  15826. {
  15827. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  15828. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  15829. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15830. {
  15831. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  15832. }
  15833. else
  15834. {
  15835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  15836. }
  15837. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  15838. isKnowKey = TRUE;
  15839. }
  15840. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  15841. {
  15842. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  15843. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  15844. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15845. {
  15846. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  15847. }
  15848. else
  15849. {
  15850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  15851. }
  15852. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  15853. isKnowKey = TRUE;
  15854. }
  15855. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15856. {
  15857. struct sysinfo s_info;
  15858. int error = sysinfo(&s_info);
  15859. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15860. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15861. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15862. {
  15863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15864. }
  15865. else
  15866. {
  15867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15868. }
  15869. if(error != 0)
  15870. {
  15871. DEBUG_WARN("System uptime get error: %d\n", error);
  15872. }
  15873. else
  15874. {
  15875. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15876. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15877. }
  15878. isKnowKey = TRUE;
  15879. }
  15880. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15881. {
  15882. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15883. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15884. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15885. {
  15886. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15887. }
  15888. else
  15889. {
  15890. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15891. }
  15892. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  15893. isKnowKey = TRUE;
  15894. }
  15895. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  15896. {
  15897. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  15898. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  15899. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  15900. {
  15901. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  15902. }
  15903. else
  15904. {
  15905. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  15906. }
  15907. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15908. isKnowKey = TRUE;
  15909. }
  15910. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15911. {
  15912. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15913. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15914. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15915. {
  15916. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15917. }
  15918. else
  15919. {
  15920. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15921. }
  15922. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15923. isKnowKey = TRUE;
  15924. }
  15925. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15926. {
  15927. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15928. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15929. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15930. {
  15931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15932. }
  15933. else
  15934. {
  15935. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15936. }
  15937. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15938. isKnowKey = TRUE;
  15939. }
  15940. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15941. {
  15942. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15943. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15944. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15945. {
  15946. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15947. }
  15948. else
  15949. {
  15950. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15951. }
  15952. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15953. isKnowKey = TRUE;
  15954. }
  15955. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15956. {
  15957. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15958. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15959. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15960. {
  15961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15962. }
  15963. else
  15964. {
  15965. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15966. }
  15967. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15968. isKnowKey = TRUE;
  15969. }
  15970. if(isEmpty || strcmp(keyReq, "PreAuthAmount") == 0 )
  15971. {
  15972. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PreAuthAmount].Item, "PreAuthAmount");
  15973. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Key, "PreAuthAmount");
  15974. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  15975. {
  15976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "0"/*"FALSE"*/);
  15977. }
  15978. else
  15979. {
  15980. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "1"/*"TRUE"*/);
  15981. }
  15982. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData );
  15983. isKnowKey = TRUE;
  15984. }
  15985. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15986. {
  15987. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15988. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15989. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15990. {
  15991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15992. }
  15993. else
  15994. {
  15995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15996. }
  15997. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15998. isKnowKey = TRUE;
  15999. }
  16000. #if 1
  16001. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  16002. {
  16003. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  16004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  16005. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16006. {
  16007. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  16008. }
  16009. else
  16010. {
  16011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  16012. }
  16013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  16014. isKnowKey = TRUE;
  16015. }
  16016. #endif
  16017. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  16018. {
  16019. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  16020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  16021. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16022. {
  16023. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16024. }
  16025. else
  16026. {
  16027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16028. }
  16029. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  16030. isKnowKey = TRUE;
  16031. }
  16032. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  16033. {
  16034. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  16035. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  16036. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16037. {
  16038. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16039. }
  16040. else
  16041. {
  16042. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16043. }
  16044. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  16045. isKnowKey = TRUE;
  16046. }
  16047. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  16048. {
  16049. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  16050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  16051. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16052. {
  16053. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  16054. }
  16055. else
  16056. {
  16057. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  16058. }
  16059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16060. isKnowKey = TRUE;
  16061. }
  16062. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  16063. {
  16064. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  16065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  16066. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16067. {
  16068. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  16069. }
  16070. else
  16071. {
  16072. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  16073. }
  16074. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16075. isKnowKey = TRUE;
  16076. }
  16077. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  16078. {
  16079. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  16080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  16081. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16082. {
  16083. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  16084. }
  16085. else
  16086. {
  16087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  16088. }
  16089. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16090. isKnowKey = TRUE;
  16091. }
  16092. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  16093. {
  16094. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  16095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  16096. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16097. {
  16098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  16099. }
  16100. else
  16101. {
  16102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  16103. }
  16104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16105. isKnowKey = TRUE;
  16106. }
  16107. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  16108. {
  16109. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  16110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  16111. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16112. {
  16113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  16114. }
  16115. else
  16116. {
  16117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  16118. }
  16119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16120. isKnowKey = TRUE;
  16121. }
  16122. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  16123. {
  16124. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  16125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  16126. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16127. {
  16128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  16129. }
  16130. else
  16131. {
  16132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  16133. }
  16134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16135. isKnowKey = TRUE;
  16136. }
  16137. //=========================================================
  16138. if(!isEmpty && !isKnowKey)
  16139. {
  16140. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  16141. strcpy(unknownkey[UnknownKeynum], keyReq);
  16142. UnknownKeynum = UnknownKeynum + 1;
  16143. }
  16144. }
  16145. void processUnkownKey(void)
  16146. {
  16147. DEBUG_INFO("processUnkownKey...\n");
  16148. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  16149. for(int index=0; index < UnknownKeynum; index++)
  16150. {
  16151. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  16152. {
  16153. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  16154. }
  16155. }
  16156. }
  16157. int setKeyValue(char *key, char *value)
  16158. {
  16159. int isSuccess = NotSupported;
  16160. int check_ascii=0;
  16161. char str[501]={0};
  16162. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  16163. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  16164. {
  16165. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  16166. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16167. {
  16168. strcpy(str, (const char*)value);
  16169. for(int i = 0; str[i]; i++){
  16170. str[i] = tolower(str[i]);
  16171. }
  16172. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16173. isSuccess = ConfigurationStatus_Accepted;
  16174. }
  16175. else
  16176. {
  16177. isSuccess = ConfigurationStatus_Rejected;
  16178. }
  16179. }
  16180. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  16181. {
  16182. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  16183. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16184. {
  16185. strcpy(str, (const char*)value);
  16186. for(int i = 0; str[i]; i++){
  16187. str[i] = tolower(str[i]);
  16188. }
  16189. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16190. isSuccess = ConfigurationStatus_Accepted;
  16191. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  16192. }
  16193. else
  16194. {
  16195. isSuccess = ConfigurationStatus_Rejected;
  16196. }
  16197. }
  16198. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  16199. {
  16200. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16201. {
  16202. strcpy(str, (const char*)value);
  16203. for(int i = 0; str[i]; i++)
  16204. {
  16205. str[i] = tolower(str[i]);
  16206. }
  16207. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  16208. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16209. isSuccess = ConfigurationStatus_Accepted;
  16210. }
  16211. else
  16212. {
  16213. isSuccess = ConfigurationStatus_Rejected;
  16214. }
  16215. }
  16216. if(strcmp(key, "BlinkRepeat") == 0)
  16217. {
  16218. //Charger.BlinkRepeat = Integer.parseInt(value);
  16219. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16220. {
  16221. check_ascii = value[0];
  16222. if( (check_ascii < 48) || (check_ascii > 57) )
  16223. {
  16224. isSuccess = ConfigurationStatus_Rejected;
  16225. }
  16226. else
  16227. {
  16228. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  16229. isSuccess = ConfigurationStatus_Accepted;
  16230. }
  16231. }
  16232. else
  16233. {
  16234. isSuccess = ConfigurationStatus_Rejected;
  16235. }
  16236. }
  16237. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  16238. {
  16239. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16240. {
  16241. check_ascii = value[0];
  16242. if( (check_ascii < 48) || (check_ascii > 57) )
  16243. {
  16244. isSuccess = ConfigurationStatus_Rejected;
  16245. }
  16246. else
  16247. {
  16248. if((atoi(value) == 0) || (atoi(value) >= 5))
  16249. {
  16250. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  16251. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  16252. isSuccess = ConfigurationStatus_Accepted;
  16253. }
  16254. else
  16255. isSuccess = ConfigurationStatus_Rejected;
  16256. }
  16257. }
  16258. else
  16259. {
  16260. isSuccess = ConfigurationStatus_Rejected;
  16261. }
  16262. }
  16263. if(strcmp(key, "ConnectionTimeOut") == 0 )
  16264. {
  16265. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  16266. {
  16267. check_ascii = value[0];
  16268. if( (check_ascii < 48) || (check_ascii > 57) )
  16269. {
  16270. isSuccess = ConfigurationStatus_Rejected;
  16271. }
  16272. else
  16273. {
  16274. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  16275. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  16276. isSuccess = ConfigurationStatus_Accepted;
  16277. }
  16278. }
  16279. else
  16280. {
  16281. isSuccess = ConfigurationStatus_Rejected;
  16282. }
  16283. }
  16284. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  16285. {
  16286. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  16287. {
  16288. check_ascii = value[0];
  16289. if( (check_ascii < 48) || (check_ascii > 57) )
  16290. {
  16291. isSuccess = ConfigurationStatus_Rejected;
  16292. }
  16293. else
  16294. {
  16295. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16296. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  16297. isSuccess = ConfigurationStatus_Accepted;
  16298. }
  16299. }
  16300. else
  16301. {
  16302. isSuccess = ConfigurationStatus_Rejected;
  16303. }
  16304. }
  16305. if(strcmp(key, "HeartbeatInterval") == 0)
  16306. {
  16307. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  16308. {
  16309. check_ascii = value[0];
  16310. if( (check_ascii < 48) || (check_ascii > 57) )
  16311. {
  16312. isSuccess = ConfigurationStatus_Rejected;
  16313. }
  16314. else
  16315. {
  16316. if((atoi(value) == 0) || (atoi(value) >= 10))
  16317. {
  16318. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16319. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  16320. HeartBeatWaitTime = atoi(value);
  16321. isSuccess = ConfigurationStatus_Accepted;
  16322. }
  16323. else
  16324. {
  16325. isSuccess = ConfigurationStatus_Rejected;
  16326. }
  16327. }
  16328. }
  16329. else
  16330. {
  16331. isSuccess = ConfigurationStatus_Rejected;
  16332. }
  16333. }
  16334. if(strcmp(key, "LightIntensity") == 0)
  16335. {
  16336. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16337. {
  16338. check_ascii = value[0];
  16339. if( (check_ascii < 48) || (check_ascii > 57) )
  16340. {
  16341. isSuccess = ConfigurationStatus_Rejected;
  16342. }
  16343. else
  16344. {
  16345. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  16346. isSuccess = ConfigurationStatus_Accepted;
  16347. }
  16348. }
  16349. else
  16350. {
  16351. isSuccess = ConfigurationStatus_Rejected;
  16352. }
  16353. }
  16354. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  16355. {
  16356. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  16357. {
  16358. strcpy(str, (const char*)value);
  16359. for(int i = 0; str[i]; i++)
  16360. {
  16361. str[i] = tolower(str[i]);
  16362. }
  16363. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16364. isSuccess = ConfigurationStatus_Accepted;
  16365. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16366. }
  16367. else
  16368. {
  16369. isSuccess = ConfigurationStatus_Rejected;
  16370. }
  16371. }
  16372. if(strcmp(key, "LocalPreAuthorize") == 0)
  16373. {
  16374. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16375. {
  16376. strcpy(str, (const char*)value);
  16377. for(int i = 0; str[i]; i++)
  16378. {
  16379. str[i] = tolower(str[i]);
  16380. }
  16381. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16382. isSuccess = ConfigurationStatus_Accepted;
  16383. }
  16384. else
  16385. {
  16386. isSuccess = ConfigurationStatus_Rejected;
  16387. }
  16388. }
  16389. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  16390. {
  16391. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  16392. {
  16393. check_ascii = value[0];
  16394. if( (check_ascii < 48) || (check_ascii > 57) )
  16395. {
  16396. isSuccess = ConfigurationStatus_Rejected;
  16397. }
  16398. else
  16399. {
  16400. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  16401. isSuccess = ConfigurationStatus_Accepted;
  16402. }
  16403. }
  16404. else
  16405. {
  16406. isSuccess = ConfigurationStatus_Rejected;
  16407. }
  16408. }
  16409. if(strcmp(key, "MeterValuesAlignedData") == 0)
  16410. {
  16411. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  16412. {
  16413. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  16414. isSuccess = ConfigurationStatus_Accepted;
  16415. }
  16416. else
  16417. {
  16418. isSuccess = ConfigurationStatus_Rejected;
  16419. }
  16420. }
  16421. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  16422. {
  16423. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  16424. {
  16425. check_ascii = value[0];
  16426. if( (check_ascii < 48) || (check_ascii > 57) )
  16427. {
  16428. isSuccess = ConfigurationStatus_Rejected;
  16429. }
  16430. else
  16431. {
  16432. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16433. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  16434. isSuccess = ConfigurationStatus_Accepted;
  16435. }
  16436. }
  16437. else
  16438. {
  16439. isSuccess = ConfigurationStatus_Rejected;
  16440. }
  16441. }
  16442. if(strcmp(key, "MeterValuesSampledData") == 0 )
  16443. {
  16444. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  16445. {
  16446. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  16447. isSuccess = ConfigurationStatus_Accepted;
  16448. }
  16449. else
  16450. {
  16451. isSuccess = ConfigurationStatus_Rejected;
  16452. }
  16453. }
  16454. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  16455. {
  16456. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16457. {
  16458. check_ascii = value[0];
  16459. if( (check_ascii < 48) || (check_ascii > 57) )
  16460. {
  16461. isSuccess = ConfigurationStatus_Rejected;
  16462. }
  16463. else
  16464. {
  16465. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16466. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  16467. isSuccess = ConfigurationStatus_Accepted;
  16468. }
  16469. }
  16470. else
  16471. {
  16472. isSuccess = ConfigurationStatus_Rejected;
  16473. }
  16474. }
  16475. if(strcmp(key, "MeterValueSampleInterval") == 0)
  16476. {
  16477. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16478. {
  16479. check_ascii = value[0];
  16480. if( (check_ascii < 48) || (check_ascii > 57) )
  16481. {
  16482. isSuccess = ConfigurationStatus_Rejected;
  16483. }
  16484. else
  16485. {
  16486. if((atoi(value) == 0) || (atoi(value) >= 3))
  16487. {
  16488. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16489. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  16490. isSuccess = ConfigurationStatus_Accepted;
  16491. }
  16492. else
  16493. {
  16494. isSuccess = ConfigurationStatus_Rejected;
  16495. }
  16496. }
  16497. }
  16498. else
  16499. {
  16500. isSuccess = ConfigurationStatus_Rejected;
  16501. }
  16502. }
  16503. if(strcmp(key, "MinimumStatusDuration") == 0)
  16504. {
  16505. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16506. {
  16507. check_ascii = value[0];
  16508. if( (check_ascii < 48) || (check_ascii > 57) )
  16509. {
  16510. isSuccess = ConfigurationStatus_Rejected;
  16511. }
  16512. else
  16513. {
  16514. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  16515. {
  16516. isSuccess = ConfigurationStatus_Rejected;
  16517. }
  16518. else
  16519. {
  16520. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16521. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16522. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16523. isSuccess = ConfigurationStatus_Accepted;
  16524. }
  16525. }
  16526. }
  16527. else
  16528. {
  16529. isSuccess = ConfigurationStatus_Rejected;
  16530. }
  16531. }
  16532. if(strcmp(key, "NumberOfConnectors") == 0)
  16533. {
  16534. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16535. {
  16536. check_ascii = value[0];
  16537. if( (check_ascii < 48) || (check_ascii > 57) )
  16538. {
  16539. isSuccess = ConfigurationStatus_Rejected;
  16540. }
  16541. else
  16542. {
  16543. //Charger.ResetRetries = Integer.parseInt(value);
  16544. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16545. isSuccess = ConfigurationStatus_Accepted;
  16546. }
  16547. }
  16548. else
  16549. {
  16550. isSuccess = ConfigurationStatus_Rejected;
  16551. }
  16552. }
  16553. if(strcmp(key, "ResetRetries") == 0)
  16554. {
  16555. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16556. {
  16557. check_ascii = value[0];
  16558. if( (check_ascii < 48) || (check_ascii > 57) )
  16559. {
  16560. isSuccess = ConfigurationStatus_Rejected;
  16561. }
  16562. else
  16563. {
  16564. //Charger.ResetRetries = Integer.parseInt(value);
  16565. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16566. isSuccess = ConfigurationStatus_Accepted;
  16567. }
  16568. }
  16569. else
  16570. {
  16571. isSuccess = ConfigurationStatus_Rejected;
  16572. }
  16573. }
  16574. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16575. {
  16576. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16577. {
  16578. strcpy(str, (const char*)value);
  16579. for(int i = 0; str[i]; i++)
  16580. {
  16581. str[i] = tolower(str[i]);
  16582. }
  16583. if(strcmp(str, "notapplicable")== 0)
  16584. {
  16585. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16586. isSuccess = ConfigurationStatus_Accepted;
  16587. }
  16588. else if(strcmp(str, "unknown")== 0)
  16589. {
  16590. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16591. isSuccess = ConfigurationStatus_Accepted;
  16592. }
  16593. else if(strcmp(str, "rst")== 0)
  16594. {
  16595. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16596. isSuccess = ConfigurationStatus_Accepted;
  16597. }
  16598. else if(strcmp(str, "rts")== 0)
  16599. {
  16600. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16601. isSuccess = ConfigurationStatus_Accepted;
  16602. }
  16603. else if(strcmp(str, "srt")== 0)
  16604. {
  16605. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16606. isSuccess = ConfigurationStatus_Accepted;
  16607. }
  16608. else if(strcmp(str, "str")== 0)
  16609. {
  16610. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16611. isSuccess = ConfigurationStatus_Accepted;
  16612. }
  16613. else if(strcmp(str, "trs")== 0)
  16614. {
  16615. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16616. isSuccess = ConfigurationStatus_Accepted;
  16617. }
  16618. else if(strcmp(str, "tsr")== 0)
  16619. {
  16620. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16621. isSuccess = ConfigurationStatus_Accepted;
  16622. }
  16623. else
  16624. {
  16625. isSuccess = ConfigurationStatus_Rejected;
  16626. }
  16627. }
  16628. else
  16629. {
  16630. isSuccess = ConfigurationStatus_Rejected;
  16631. }
  16632. }
  16633. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16634. {
  16635. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16636. {
  16637. check_ascii = value[0];
  16638. if( (check_ascii < 48) || (check_ascii > 57) )
  16639. {
  16640. isSuccess = ConfigurationStatus_Rejected;
  16641. }
  16642. else
  16643. {
  16644. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16645. isSuccess = ConfigurationStatus_Accepted;
  16646. }
  16647. }
  16648. else
  16649. {
  16650. isSuccess = ConfigurationStatus_Rejected;
  16651. }
  16652. }
  16653. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16654. {
  16655. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16656. {
  16657. strcpy(str, (const char*)value);
  16658. for(int i = 0; str[i]; i++)
  16659. {
  16660. str[i] = tolower(str[i]);
  16661. }
  16662. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16663. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16664. isSuccess = ConfigurationStatus_Accepted;
  16665. }
  16666. else
  16667. {
  16668. isSuccess = ConfigurationStatus_Rejected;
  16669. }
  16670. }
  16671. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16672. {
  16673. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16674. {
  16675. strcpy(str, (const char*)value);
  16676. for(int i = 0; str[i]; i++)
  16677. {
  16678. str[i] = tolower(str[i]);
  16679. }
  16680. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16681. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16682. isSuccess = ConfigurationStatus_Accepted;
  16683. }
  16684. else
  16685. {
  16686. isSuccess = ConfigurationStatus_Rejected;
  16687. }
  16688. }
  16689. if(strcmp(key, "StopTxnAlignedData") == 0)
  16690. {
  16691. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16692. {
  16693. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16694. isSuccess = ConfigurationStatus_Accepted;
  16695. }
  16696. else
  16697. {
  16698. isSuccess = ConfigurationStatus_Rejected;
  16699. }
  16700. }
  16701. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16702. {
  16703. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16704. {
  16705. check_ascii = value[0];
  16706. if( (check_ascii < 48) || (check_ascii > 57) )
  16707. {
  16708. isSuccess = ConfigurationStatus_Rejected;
  16709. }
  16710. else
  16711. {
  16712. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16713. isSuccess = ConfigurationStatus_Accepted;
  16714. }
  16715. }
  16716. else
  16717. {
  16718. isSuccess = ConfigurationStatus_Rejected;
  16719. }
  16720. }
  16721. if(strcmp(key, "StopTxnSampledData") == 0)
  16722. {
  16723. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16724. {
  16725. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16726. isSuccess = ConfigurationStatus_Accepted;
  16727. }
  16728. else
  16729. {
  16730. isSuccess = ConfigurationStatus_Rejected;
  16731. }
  16732. }
  16733. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16734. {
  16735. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16736. {
  16737. check_ascii = value[0];
  16738. if( (check_ascii < 48) || (check_ascii > 57) )
  16739. {
  16740. isSuccess = ConfigurationStatus_Rejected;
  16741. }
  16742. else
  16743. {
  16744. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16745. isSuccess = ConfigurationStatus_Accepted;
  16746. }
  16747. }
  16748. else
  16749. {
  16750. isSuccess = ConfigurationStatus_Rejected;
  16751. }
  16752. }
  16753. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16754. {
  16755. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16756. {
  16757. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16758. isSuccess = ConfigurationStatus_Accepted;
  16759. }
  16760. else
  16761. {
  16762. isSuccess = ConfigurationStatus_Rejected;
  16763. }
  16764. }
  16765. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16766. {
  16767. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16768. {
  16769. check_ascii = value[0];
  16770. if( (check_ascii < 48) || (check_ascii > 57) )
  16771. {
  16772. isSuccess = ConfigurationStatus_Rejected;
  16773. }
  16774. else
  16775. {
  16776. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16777. isSuccess = ConfigurationStatus_Accepted;
  16778. }
  16779. }
  16780. else
  16781. {
  16782. isSuccess = ConfigurationStatus_Rejected;
  16783. }
  16784. }
  16785. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16786. {
  16787. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16788. {
  16789. check_ascii = value[0];
  16790. if( (check_ascii < 48) || (check_ascii > 57) )
  16791. {
  16792. isSuccess = ConfigurationStatus_Rejected;
  16793. }
  16794. else
  16795. {
  16796. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16797. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16798. TransactionMessageAttemptsValue = atoi(value);
  16799. isSuccess = ConfigurationStatus_Accepted;
  16800. }
  16801. }
  16802. else
  16803. {
  16804. isSuccess = ConfigurationStatus_Rejected;
  16805. }
  16806. }
  16807. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16808. {
  16809. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16810. {
  16811. check_ascii = value[0];
  16812. if( (check_ascii < 48) || (check_ascii > 57) )
  16813. {
  16814. isSuccess = ConfigurationStatus_Rejected;
  16815. }
  16816. else
  16817. {
  16818. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16819. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16820. TransactionMessageRetryIntervalValue = atoi(value);
  16821. isSuccess = ConfigurationStatus_Accepted;
  16822. }
  16823. }
  16824. else
  16825. {
  16826. isSuccess = ConfigurationStatus_Rejected;
  16827. }
  16828. }
  16829. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16830. {
  16831. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16832. {
  16833. strcpy(str, (const char*)value);
  16834. for(int i = 0; str[i]; i++)
  16835. {
  16836. str[i] = tolower(str[i]);
  16837. }
  16838. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16839. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16840. isSuccess = ConfigurationStatus_Accepted;
  16841. }
  16842. else
  16843. {
  16844. isSuccess = ConfigurationStatus_Rejected;
  16845. }
  16846. }
  16847. if(strcmp(key, "WebSocketPingInterval") == 0)
  16848. {
  16849. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16850. {
  16851. check_ascii = value[0];
  16852. if( (check_ascii < 48) || (check_ascii > 57) )
  16853. {
  16854. isSuccess = ConfigurationStatus_Rejected;
  16855. }
  16856. else
  16857. {
  16858. if((atoi(value) == 0) || (atoi(value) >= 10))
  16859. {
  16860. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16861. isSuccess = ConfigurationStatus_Accepted;
  16862. }
  16863. else
  16864. isSuccess = ConfigurationStatus_Rejected;
  16865. }
  16866. }
  16867. else
  16868. {
  16869. isSuccess = ConfigurationStatus_Rejected;
  16870. }
  16871. }
  16872. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16873. {
  16874. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16875. {
  16876. strcpy(str, (const char*)value);
  16877. for(int i = 0; str[i]; i++)
  16878. {
  16879. str[i] = tolower(str[i]);
  16880. }
  16881. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16882. isSuccess = ConfigurationStatus_Accepted;
  16883. }
  16884. else
  16885. {
  16886. isSuccess = ConfigurationStatus_Rejected;
  16887. }
  16888. }
  16889. if(strcmp(key, "AuthorizationKey") == 0)
  16890. {
  16891. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16892. {
  16893. strcpy(str, (const char*)value);
  16894. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16895. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16896. isSuccess = ConfigurationStatus_Accepted;
  16897. }
  16898. else
  16899. {
  16900. isSuccess = ConfigurationStatus_Rejected;
  16901. }
  16902. }
  16903. if(strcmp(key, "SecurityProfile") == 0)
  16904. {
  16905. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16906. {
  16907. check_ascii = value[0];
  16908. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16909. {
  16910. isSuccess = ConfigurationStatus_Rejected;
  16911. }
  16912. else if(check_ascii == 0x33)
  16913. {
  16914. isSuccess = NotSupported;
  16915. }
  16916. else
  16917. {
  16918. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16919. {
  16920. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16921. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  16922. isSuccess = ConfigurationStatus_Accepted;
  16923. }
  16924. else
  16925. isSuccess = ConfigurationStatus_Rejected;
  16926. }
  16927. }
  16928. else
  16929. {
  16930. isSuccess = ConfigurationStatus_Rejected;
  16931. }
  16932. }
  16933. if(strcmp(key, "DefaultPrice") == 0)
  16934. {
  16935. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16936. {
  16937. strcpy(str, (const char*)value);
  16938. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16939. isSuccess = ConfigurationStatus_Accepted;
  16940. }
  16941. else
  16942. {
  16943. isSuccess = ConfigurationStatus_Rejected;
  16944. }
  16945. }
  16946. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16947. {
  16948. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16949. {
  16950. strcpy(str, (const char*)value);
  16951. for(int i = 0; str[i]; i++)
  16952. {
  16953. str[i] = tolower(str[i]);
  16954. }
  16955. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16956. isSuccess = ConfigurationStatus_Accepted;
  16957. }
  16958. else
  16959. {
  16960. isSuccess = ConfigurationStatus_Rejected;
  16961. }
  16962. }
  16963. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16964. {
  16965. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16966. {
  16967. strcpy(str, (const char*)value);
  16968. for(int i = 0; str[i]; i++)
  16969. {
  16970. str[i] = tolower(str[i]);
  16971. }
  16972. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16973. isSuccess = ConfigurationStatus_Accepted;
  16974. }
  16975. else
  16976. {
  16977. isSuccess = ConfigurationStatus_Rejected;
  16978. }
  16979. }
  16980. if(strcmp(key, "TimeOffset") == 0)
  16981. {
  16982. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  16983. {
  16984. strcpy(str, (const char*)value);
  16985. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  16986. isSuccess = ConfigurationStatus_Accepted;
  16987. }
  16988. else
  16989. {
  16990. isSuccess = ConfigurationStatus_Rejected;
  16991. }
  16992. }
  16993. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  16994. {
  16995. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  16996. {
  16997. strcpy(str, (const char*)value);
  16998. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  16999. isSuccess = ConfigurationStatus_Accepted;
  17000. }
  17001. else
  17002. {
  17003. isSuccess = ConfigurationStatus_Rejected;
  17004. }
  17005. }
  17006. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  17007. {
  17008. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  17009. {
  17010. strcpy(str, (const char*)value);
  17011. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  17012. isSuccess = ConfigurationStatus_Accepted;
  17013. }
  17014. else
  17015. {
  17016. isSuccess = ConfigurationStatus_Rejected;
  17017. }
  17018. }
  17019. if(strcmp(key, "SystemUptimeSec") == 0)
  17020. {
  17021. isSuccess = NotSupported;
  17022. }
  17023. if(strcmp(key, "FreeVend") == 0)
  17024. {
  17025. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17026. {
  17027. strcpy(str, (const char*)value);
  17028. for(int i = 0; str[i]; i++)
  17029. {
  17030. str[i] = tolower(str[i]);
  17031. }
  17032. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  17033. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17034. isSuccess = ConfigurationStatus_Accepted;
  17035. }
  17036. else
  17037. {
  17038. isSuccess = ConfigurationStatus_Rejected;
  17039. }
  17040. }
  17041. if(strcmp(key, "FreeVendIdtag") == 0)
  17042. {
  17043. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17044. {
  17045. strcpy(str, (const char*)value);
  17046. if(strlen(str) <= 20)
  17047. {
  17048. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  17049. isSuccess = ConfigurationStatus_Accepted;
  17050. }
  17051. else
  17052. {
  17053. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  17054. isSuccess = ConfigurationStatus_Rejected;
  17055. }
  17056. }
  17057. else
  17058. {
  17059. isSuccess = ConfigurationStatus_Rejected;
  17060. }
  17061. }
  17062. if(strcmp(key, "OcppServer") == 0)
  17063. {
  17064. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17065. {
  17066. strcpy(str, (const char*)value);
  17067. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  17068. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  17069. isSuccess = ConfigurationStatus_Accepted;
  17070. }
  17071. else
  17072. {
  17073. isSuccess = ConfigurationStatus_Rejected;
  17074. }
  17075. }
  17076. if(strcmp(key, "MaintainServer") == 0)
  17077. {
  17078. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17079. {
  17080. strcpy(str, (const char*)value);
  17081. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  17082. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  17083. isSuccess = ConfigurationStatus_Accepted;
  17084. }
  17085. else
  17086. {
  17087. isSuccess = ConfigurationStatus_Rejected;
  17088. }
  17089. }
  17090. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  17091. {
  17092. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17093. {
  17094. strcpy(str, (const char*)value);
  17095. for(int i = 0; str[i]; i++)
  17096. {
  17097. str[i] = tolower(str[i]);
  17098. }
  17099. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  17100. isSuccess = ConfigurationStatus_Accepted;
  17101. }
  17102. else
  17103. {
  17104. isSuccess = ConfigurationStatus_Rejected;
  17105. }
  17106. }
  17107. if(strcmp(key, "StatusNotificationInterval") == 0)
  17108. {
  17109. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17110. {
  17111. check_ascii = value[0];
  17112. if( (check_ascii < 48) || (check_ascii > 57) )
  17113. {
  17114. isSuccess = ConfigurationStatus_Rejected;
  17115. }
  17116. else
  17117. {
  17118. if((atoi(value) == 0) || (atoi(value) >= 10))
  17119. {
  17120. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  17121. isSuccess = ConfigurationStatus_Accepted;
  17122. }
  17123. else
  17124. isSuccess = ConfigurationStatus_Rejected;
  17125. }
  17126. }
  17127. else
  17128. {
  17129. isSuccess = ConfigurationStatus_Rejected;
  17130. }
  17131. }
  17132. if(strcmp(key, "PreAuthAmount") == 0)
  17133. {
  17134. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  17135. {
  17136. check_ascii = value[0];
  17137. if( (check_ascii < 48) || (check_ascii > 57) )
  17138. {
  17139. isSuccess = ConfigurationStatus_Rejected;
  17140. }
  17141. else
  17142. {
  17143. if(atof(value) >= 0)
  17144. {
  17145. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(value) );
  17146. isSuccess = ConfigurationStatus_Accepted;
  17147. }
  17148. else
  17149. isSuccess = ConfigurationStatus_Rejected;
  17150. }
  17151. }
  17152. else
  17153. {
  17154. isSuccess = ConfigurationStatus_Rejected;
  17155. }
  17156. }
  17157. #if 0
  17158. //For OCPP Test Case
  17159. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  17160. {
  17161. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17162. {
  17163. strcpy(str, (const char*)value);
  17164. for(int i = 0; str[i]; i++)
  17165. {
  17166. str[i] = tolower(str[i]);
  17167. }
  17168. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17169. isSuccess = ConfigurationStatus_Accepted;
  17170. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17171. }
  17172. else
  17173. {
  17174. isSuccess = ConfigurationStatus_Rejected;
  17175. }
  17176. }
  17177. #endif
  17178. #if 1
  17179. if(strcmp(key, "LocalAuthListEnabled") == 0)
  17180. {
  17181. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17182. {
  17183. strcpy(str, (const char*)value);
  17184. for(int i = 0; str[i]; i++)
  17185. {
  17186. str[i] = tolower(str[i]);
  17187. }
  17188. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17189. isSuccess = ConfigurationStatus_Accepted;
  17190. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17191. }
  17192. else
  17193. {
  17194. isSuccess = ConfigurationStatus_Rejected;
  17195. }
  17196. }
  17197. #endif
  17198. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  17199. {
  17200. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  17201. {
  17202. check_ascii = value[0];
  17203. if( (check_ascii < 48) || (check_ascii > 57) )
  17204. {
  17205. isSuccess = ConfigurationStatus_Rejected;
  17206. }
  17207. else
  17208. {
  17209. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  17210. isSuccess = ConfigurationStatus_Accepted;
  17211. }
  17212. }
  17213. else
  17214. {
  17215. isSuccess = ConfigurationStatus_Rejected;
  17216. }
  17217. }
  17218. if(strcmp(key, "SendLocalListMaxLength") == 0)
  17219. {
  17220. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17221. {
  17222. check_ascii = value[0];
  17223. if( (check_ascii < 48) || (check_ascii > 57) )
  17224. {
  17225. isSuccess = ConfigurationStatus_Rejected;
  17226. }
  17227. else
  17228. {
  17229. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  17230. isSuccess = ConfigurationStatus_Accepted;
  17231. }
  17232. }
  17233. else
  17234. {
  17235. isSuccess = ConfigurationStatus_Rejected;
  17236. }
  17237. }
  17238. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  17239. {
  17240. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17241. {
  17242. strcpy(str, (const char*)value);
  17243. for(int i = 0; str[i]; i++)
  17244. {
  17245. str[i] = tolower(str[i]);
  17246. }
  17247. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17248. isSuccess = ConfigurationStatus_Accepted;
  17249. }
  17250. else
  17251. {
  17252. isSuccess = ConfigurationStatus_Rejected;
  17253. }
  17254. }
  17255. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  17256. {
  17257. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17258. {
  17259. check_ascii = value[0];
  17260. if( (check_ascii < 48) || (check_ascii > 57) )
  17261. {
  17262. isSuccess = ConfigurationStatus_Rejected;
  17263. }
  17264. else
  17265. {
  17266. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  17267. isSuccess = ConfigurationStatus_Accepted;
  17268. }
  17269. }
  17270. else
  17271. {
  17272. isSuccess = ConfigurationStatus_Rejected;
  17273. }
  17274. }
  17275. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  17276. {
  17277. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17278. {
  17279. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  17280. isSuccess = ConfigurationStatus_Accepted;
  17281. }
  17282. else
  17283. {
  17284. isSuccess = ConfigurationStatus_Rejected;
  17285. }
  17286. }
  17287. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  17288. {
  17289. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17290. {
  17291. check_ascii = value[0];
  17292. if( (check_ascii < 48) || (check_ascii > 57) )
  17293. {
  17294. isSuccess = ConfigurationStatus_Rejected;
  17295. }
  17296. else
  17297. {
  17298. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  17299. isSuccess = ConfigurationStatus_Accepted;
  17300. }
  17301. }
  17302. else
  17303. {
  17304. isSuccess = ConfigurationStatus_Rejected;
  17305. }
  17306. }
  17307. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  17308. {
  17309. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17310. {
  17311. strcpy(str, (const char*)value);
  17312. for(int i = 0; str[i]; i++)
  17313. {
  17314. str[i] = tolower(str[i]);
  17315. }
  17316. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17317. isSuccess = ConfigurationStatus_Accepted;
  17318. }
  17319. else
  17320. {
  17321. isSuccess = ConfigurationStatus_Rejected;
  17322. }
  17323. }
  17324. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  17325. {
  17326. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  17327. {
  17328. check_ascii = value[0];
  17329. if( (check_ascii < 48) || (check_ascii > 57) )
  17330. {
  17331. isSuccess = ConfigurationStatus_Rejected;
  17332. }
  17333. else
  17334. {
  17335. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  17336. isSuccess = ConfigurationStatus_Accepted;
  17337. }
  17338. }
  17339. else
  17340. {
  17341. isSuccess = ConfigurationStatus_Rejected;
  17342. }
  17343. }
  17344. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17345. return isSuccess;
  17346. }
  17347. int TransactionMessageAttemptsGet(void)
  17348. {
  17349. return TransactionMessageAttemptsValue;
  17350. }
  17351. int FirstHeartBeatResponse(void)
  17352. {
  17353. return FirstHeartBeat;
  17354. }
  17355. int TransactionMessageRetryIntervalGet(void)
  17356. {
  17357. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17358. }
  17359. int ReadHttpStatus(int sock)
  17360. {
  17361. //char c;
  17362. char buff[1024]="",*ptr=buff+1;
  17363. int bytes_received, status;
  17364. DEBUG_INFO("Begin Response ..\n");
  17365. while((bytes_received = recv(sock, ptr, 1, 0))){
  17366. if(bytes_received==-1){
  17367. perror("ReadHttpStatus");
  17368. exit(1);
  17369. }
  17370. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  17371. ptr++;
  17372. }
  17373. *ptr=0;
  17374. ptr=buff+1;
  17375. sscanf(ptr,"%*s %d ", &status);
  17376. DEBUG_INFO("%s\n",ptr);
  17377. DEBUG_INFO("status=%d\n",status);
  17378. DEBUG_INFO("End Response ..\n");
  17379. return (bytes_received>0)?status:0;
  17380. }
  17381. //the only filed that it parsed is 'Content-Length'
  17382. int ParseHeader(int sock)
  17383. {
  17384. //char c;
  17385. char buff[1024]="",*ptr=buff+4;
  17386. int bytes_received;
  17387. DEBUG_INFO("Begin HEADER ..\n");
  17388. while((bytes_received = recv(sock, ptr, 1, 0))){
  17389. if(bytes_received==-1){
  17390. perror("Parse Header");
  17391. exit(1);
  17392. }
  17393. if(
  17394. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  17395. (ptr[-1]=='\r') && (*ptr=='\n' )
  17396. ) break;
  17397. ptr++;
  17398. }
  17399. *ptr=0;
  17400. ptr=buff+4;
  17401. //printf("%s",ptr);
  17402. if(bytes_received){
  17403. ptr=strstr(ptr,"Content-Length:");
  17404. if(ptr){
  17405. sscanf(ptr,"%*s %d",&bytes_received);
  17406. }else
  17407. bytes_received=-1; //unknown size
  17408. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  17409. }
  17410. DEBUG_INFO("End HEADER ..\n");
  17411. return bytes_received ;
  17412. }
  17413. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  17414. {
  17415. int result = TRUE;
  17416. char rmFileCmd[100]={0};
  17417. char FilePath[100]={0};
  17418. char ftpbuf[200];
  17419. int systemresult;
  17420. sprintf(FilePath,"/mnt/%s",filename);
  17421. system("ping 8.8.8.8 &");
  17422. if((access(FilePath,F_OK))!=-1)
  17423. {
  17424. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17425. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17426. system(rmFileCmd);
  17427. }
  17428. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17429. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  17430. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17431. systemresult = system(ftpbuf);
  17432. if(systemresult != 0)
  17433. {
  17434. DEBUG_INFO("http DownLoad error!\n");
  17435. result = FALSE;
  17436. }
  17437. system("pkill ping");
  17438. return result;
  17439. }
  17440. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  17441. {
  17442. int result = TRUE;
  17443. char rmFileCmd[100]={0};
  17444. char FilePath[100]={0};
  17445. char ftpbuf[200];
  17446. int systemresult;
  17447. sprintf(FilePath,"/mnt/%s",filename);
  17448. system("ping 8.8.8.8 &");
  17449. if((access(FilePath,F_OK))!=-1)
  17450. {
  17451. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17452. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17453. system(rmFileCmd);
  17454. }
  17455. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17456. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  17457. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17458. systemresult = system(ftpbuf);
  17459. if(systemresult != 0)
  17460. {
  17461. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  17462. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17463. systemresult = system(ftpbuf);
  17464. if(systemresult != 0)
  17465. {
  17466. DEBUG_WARN("wget error!\n");
  17467. result = FALSE;
  17468. }
  17469. }
  17470. system("pkill ping");
  17471. return result;
  17472. }
  17473. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17474. {
  17475. char rmFileCmd[100]={0};
  17476. char FilePath[100]={0};
  17477. char buf[512];
  17478. int systemresult = 0;
  17479. //DEBUG_INFO("filename=%s\n",filename);
  17480. //DEBUG_INFO("url=%s\n",url);
  17481. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17482. if((access(FilePath,F_OK))!=-1)
  17483. {
  17484. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17485. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17486. system(rmFileCmd);
  17487. }
  17488. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17489. if(fp == NULL)
  17490. {
  17491. DEBUG_INFO("log is NULL\n");
  17492. return FALSE;
  17493. }
  17494. else
  17495. {
  17496. fprintf(fp, "%s\n", url);
  17497. fprintf(fp, "%s\n", filename);
  17498. fclose(fp);
  17499. }
  17500. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  17501. if(phpFP == NULL)
  17502. {
  17503. DEBUG_INFO("PHP upload fail.\n");
  17504. return FALSE;
  17505. }
  17506. else
  17507. {
  17508. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17509. {
  17510. if(strstr(buf, "result") != NULL)
  17511. {
  17512. sscanf(buf, "result: %d", &systemresult);
  17513. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17514. }
  17515. }
  17516. pclose(phpFP);
  17517. }
  17518. if(systemresult != 1)
  17519. {
  17520. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  17521. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  17522. if(phpFP == NULL)
  17523. {
  17524. DEBUG_WARN("PHP PUT upload fail.\n");
  17525. return FALSE;
  17526. }
  17527. else
  17528. {
  17529. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17530. {
  17531. if(strstr(buf, "result") != NULL)
  17532. {
  17533. sscanf(buf, "result: %d", &systemresult);
  17534. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  17535. }
  17536. }
  17537. pclose(phpFP);
  17538. }
  17539. }
  17540. return TRUE;
  17541. }
  17542. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17543. {
  17544. int result = FALSE;
  17545. char ftpbuf[200];
  17546. int systemresult;
  17547. /*
  17548. // Domaind name transfer to IP address
  17549. struct hostent* server;
  17550. char *IPbuffer;
  17551. server = gethostbyname(location);
  17552. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17553. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17554. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17555. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  17556. systemresult = system(ftpbuf);
  17557. if(systemresult != 0)
  17558. {
  17559. DEBUG_INFO("ftpput error!\n");
  17560. }
  17561. else
  17562. {
  17563. result = TRUE;
  17564. DEBUG_INFO("ftpput OK!\n");
  17565. }
  17566. return result;
  17567. }
  17568. int GetOcppServerURL()
  17569. {
  17570. int result = FALSE;
  17571. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  17572. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  17573. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  17574. struct yuarel url;
  17575. char urlStr[512];
  17576. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  17577. {
  17578. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  17579. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17580. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17581. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  17582. if(yuarel_parse(&url, urlStr) != -1)
  17583. {
  17584. sprintf(OcppProtocol, "%s", url.scheme);
  17585. sprintf(OcppHost, "%s", url.host);
  17586. if(url.path == NULL)
  17587. OcppTempPath[0] = '\0';
  17588. else
  17589. {
  17590. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  17591. {
  17592. sprintf(OcppTempPath, "%s/", url.path);
  17593. }
  17594. else
  17595. {
  17596. sprintf(OcppTempPath, "%s", url.path);
  17597. }
  17598. }
  17599. if(url.port == 0)
  17600. {
  17601. if(strcmp(OcppProtocol, "wss") == 0)
  17602. OcppPort = 443;
  17603. else
  17604. OcppPort = 80;
  17605. }
  17606. else
  17607. OcppPort = url.port;
  17608. result = TRUE;
  17609. }
  17610. }
  17611. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  17612. {
  17613. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  17614. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17615. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17616. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  17617. if(yuarel_parse(&url, urlStr) != -1)
  17618. {
  17619. sprintf(OcppProtocol, "%s", url.scheme);
  17620. sprintf(OcppHost, "%s", url.host);
  17621. if(url.path == NULL)
  17622. OcppTempPath[0] = '\0';
  17623. else
  17624. sprintf(OcppTempPath, "%s", url.path);
  17625. if(url.port == 0)
  17626. {
  17627. if(strcmp(OcppProtocol, "wss") == 0)
  17628. OcppPort = 443;
  17629. else
  17630. OcppPort = 80;
  17631. }
  17632. else
  17633. OcppPort = url.port;
  17634. result = TRUE;
  17635. }
  17636. }
  17637. else
  17638. {
  17639. strcpy(OcppHost,"");
  17640. }
  17641. return result;
  17642. }
  17643. int GetOcppPath()
  17644. {
  17645. int result = FALSE;
  17646. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  17647. {
  17648. if(OcppTempPath == NULL)
  17649. {
  17650. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17651. }
  17652. else
  17653. {
  17654. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17655. }
  17656. result = TRUE;
  17657. goto End;
  17658. }
  17659. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  17660. {
  17661. if(OcppTempPath == NULL)
  17662. {
  17663. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  17664. }
  17665. else
  17666. {
  17667. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  17668. }
  17669. result = TRUE;
  17670. goto End;
  17671. }
  17672. else
  17673. {
  17674. strcpy(OcppPath,"");
  17675. }
  17676. End:
  17677. return result;
  17678. }
  17679. int GetOcppPort()
  17680. {
  17681. return OcppPort;
  17682. }
  17683. int GetOcppConnStatus(void)
  17684. {
  17685. return ShmOCPP16Data->OcppConnStatus;
  17686. }
  17687. void SetOcppConnStatus(uint8_t status)
  17688. {
  17689. ShmOCPP16Data->OcppConnStatus = status;
  17690. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  17691. }
  17692. int GetHeartBeatWithNOResponse(void)
  17693. {
  17694. return HeartBeatWithNOResponse;
  17695. }
  17696. void SetHeartBeatWithNOResponse(void)
  17697. {
  17698. HeartBeatWithNOResponse = 0;
  17699. }
  17700. void GetStartTransactionIdTag(int gun_index)
  17701. {
  17702. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17703. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17704. }
  17705. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17706. {
  17707. char ch;
  17708. FILE *fptr1;
  17709. int temptransactionId;
  17710. char str[100]={0};
  17711. temptransactionId = 0;
  17712. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17713. {
  17714. DEBUG_INFO("IdTag is empty.\n");
  17715. return temptransactionId;
  17716. }
  17717. /*------ Read the file ----------------*/
  17718. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  17719. if (!fptr1)
  17720. {
  17721. DEBUG_INFO("QueueTransactionId file open error.\n");
  17722. //printf(" File not found or unable to open the input file!!\n");
  17723. return temptransactionId;
  17724. }
  17725. ch=fgetc(fptr1);
  17726. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  17727. rewind(fptr1);
  17728. if(ch!=EOF)
  17729. {
  17730. // printf("%c",ch);
  17731. while (fgets(str, 100, fptr1) != NULL)
  17732. {
  17733. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17734. if(str[0]=='\0')
  17735. {
  17736. break;
  17737. }
  17738. char *revbuf[8] = {0}; // Variable store string split
  17739. int num = 0;// Quantity after string split
  17740. DEBUG_INFO("Transaction queue data= %s\n", str);
  17741. splitstring(str,",",revbuf,&num); // String split
  17742. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17743. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17744. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17745. DEBUG_INFO("------------------------------\n");
  17746. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17747. {
  17748. if(isStopTransaction)
  17749. {
  17750. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17751. {
  17752. temptransactionId = atoi(revbuf[2]);
  17753. //break;
  17754. }
  17755. }
  17756. else
  17757. {
  17758. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17759. {
  17760. temptransactionId = atoi(revbuf[2]);
  17761. //break;
  17762. }
  17763. }
  17764. }
  17765. }
  17766. }
  17767. else
  17768. DEBUG_INFO("EOF\n");
  17769. fclose(fptr1);
  17770. /*------- End of reading ---------------*/
  17771. return temptransactionId;
  17772. }
  17773. void SetTransactionIdZero(int transactionId)
  17774. {
  17775. char ch;
  17776. FILE *fptr1, *fptr2;
  17777. int temptransactionId = 0;
  17778. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  17779. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  17780. if (!fptr1)
  17781. {
  17782. //printf(" File not found or unable to open the input file!!\n");
  17783. return ;
  17784. }
  17785. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17786. if (!fptr2)
  17787. {
  17788. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17789. fclose(fptr1);
  17790. return ;
  17791. }
  17792. ch=fgetc(fptr1);
  17793. rewind(fptr1);
  17794. if(ch!=EOF)
  17795. {
  17796. // copy all contents to the temporary file except the specific line
  17797. while (fgets(str, 100, fptr1) != NULL)
  17798. {
  17799. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17800. if(str[0]=='\0')
  17801. {
  17802. break;
  17803. }
  17804. char *revbuf[8] = {0};
  17805. int num = 0;
  17806. strcpy(strtemp, str);
  17807. splitstring(str,",",revbuf,&num);
  17808. if(revbuf[2][0] != '\0')
  17809. {
  17810. temptransactionId = atoi(revbuf[2]);
  17811. if(transactionId != temptransactionId)
  17812. {
  17813. fprintf(fptr2, "%s\n", strtemp);
  17814. }
  17815. }
  17816. }
  17817. }
  17818. fclose(fptr1);
  17819. fclose(fptr2);
  17820. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  17821. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  17822. /*------ Read the file ----------------*/
  17823. }
  17824. int InternetDisconnect(void)
  17825. {
  17826. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  17827. }
  17828. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17829. void storeTempStopTransaction(int gun_index)
  17830. {
  17831. char guid[37]={0};
  17832. int tempIndex = 0;
  17833. char TempStopTransaction[256];
  17834. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  17835. DEBUG_INFO("storeTempStopTransaction...\n");
  17836. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  17837. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  17838. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  17839. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17840. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17841. {
  17842. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17843. {
  17844. tempIndex = ((gun_index==2) ? 1: 0);
  17845. }
  17846. else
  17847. {
  17848. tempIndex = gun_index;
  17849. }
  17850. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17851. {
  17852. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17853. {
  17854. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  17855. }
  17856. }// END OF CHAdeMO_QUANTITY
  17857. }
  17858. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17859. {
  17860. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17861. {
  17862. tempIndex = ((gun_index==2) ? 1: 0);
  17863. }
  17864. else
  17865. {
  17866. tempIndex = gun_index;
  17867. }
  17868. for (int index = 0; index < CCS_QUANTITY; index++)
  17869. {
  17870. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17871. {
  17872. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  17873. }
  17874. }// END OF CCS_QUANTITY
  17875. }
  17876. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17877. {
  17878. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17879. {
  17880. tempIndex = ((gun_index==2) ? 1: 0);
  17881. }
  17882. else
  17883. {
  17884. tempIndex = gun_index;
  17885. }
  17886. for (int index = 0; index < GB_QUANTITY; index++)
  17887. {
  17888. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17889. {
  17890. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17891. }
  17892. }// END OF GB_QUANTITY
  17893. }
  17894. else if(gunType[gun_index] == GUN_TYPE_DO)
  17895. {
  17896. tempIndex = gun_index;
  17897. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17898. {
  17899. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17900. {
  17901. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17902. }
  17903. }
  17904. }
  17905. else
  17906. {
  17907. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17908. {
  17909. tempIndex = 2;
  17910. }
  17911. else
  17912. {
  17913. tempIndex = gun_index;
  17914. }
  17915. for (int index = 0; index < AC_QUANTITY; index++)
  17916. {
  17917. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17918. {
  17919. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17920. }
  17921. }// END OF AC_QUANTITY
  17922. }
  17923. //Stop Transaction Time
  17924. struct timeval tmnow;
  17925. struct tm *tm;
  17926. char buf[28];//, usec_buf[6];
  17927. gettimeofday(&tmnow, NULL);
  17928. time_t t;
  17929. t = time(NULL);
  17930. /*UTC time and date*/
  17931. tm = gmtime(&t);
  17932. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17933. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  17934. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  17935. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17936. random_uuid(guid);
  17937. /***********************************transactionData******************************************************/
  17938. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17939. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17940. //=================================
  17941. //1. Transaction_Begin
  17942. //=================================
  17943. //============================== Energy.Active.Import.Interval ===========================================
  17944. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17945. {
  17946. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  17947. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17948. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  17949. 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*/]);
  17950. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17951. 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))
  17952. {
  17953. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  17954. }
  17955. else
  17956. {
  17957. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  17958. }
  17959. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  17960. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17961. }
  17962. //=================================
  17963. //2. Transaction_End
  17964. //=================================
  17965. //2.1====================================== Current.Import L1 ==============================================
  17966. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17967. {
  17968. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17969. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17970. {
  17971. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17972. {
  17973. tempIndex = ((gun_index==2) ? 1: 0);
  17974. }
  17975. else
  17976. {
  17977. tempIndex = gun_index;
  17978. }
  17979. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17980. {
  17981. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17982. {
  17983. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17984. }
  17985. }// End of for CHAdeMO_QUANTITY
  17986. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17987. }
  17988. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17989. {
  17990. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17991. {
  17992. tempIndex = ((gun_index==2) ? 1: 0);
  17993. }
  17994. else
  17995. {
  17996. tempIndex = gun_index;
  17997. }
  17998. for (int index = 0; index < CCS_QUANTITY; index++)
  17999. {
  18000. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18001. {
  18002. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18003. }
  18004. }// End of for CCS_QUANTITY
  18005. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18006. }
  18007. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18008. {
  18009. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18010. {
  18011. tempIndex = ((gun_index==2) ? 1: 0);
  18012. }
  18013. else
  18014. {
  18015. tempIndex = gun_index;
  18016. }
  18017. for (int index = 0; index < GB_QUANTITY; index++)
  18018. {
  18019. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18020. {
  18021. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18022. }
  18023. }// End of for GB_QUANTITY
  18024. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18025. }
  18026. else if(gunType[gun_index] == GUN_TYPE_DO)
  18027. {
  18028. tempIndex = gun_index;
  18029. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18030. {
  18031. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18032. {
  18033. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18034. }
  18035. }
  18036. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18037. }
  18038. else
  18039. {
  18040. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18041. {
  18042. tempIndex = 2;
  18043. }
  18044. else
  18045. {
  18046. tempIndex = gun_index;
  18047. }
  18048. for (int index = 0; index < AC_QUANTITY; index++)
  18049. {
  18050. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18051. {
  18052. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  18053. }
  18054. }// End of for AC_QUANTITY
  18055. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18056. }
  18057. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18058. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  18059. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  18060. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18061. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  18062. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18063. }
  18064. //2.2===================================== Energy.Active.Import.Interval ==========================================
  18065. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  18066. {
  18067. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18068. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18069. {
  18070. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18071. {
  18072. tempIndex = ((gun_index==2) ? 1: 0);
  18073. }
  18074. else
  18075. {
  18076. tempIndex = gun_index;
  18077. }
  18078. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18079. {
  18080. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18081. {
  18082. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  18083. }
  18084. }// END OF CHAdeMO_QUANTITY
  18085. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18086. }
  18087. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18088. {
  18089. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18090. {
  18091. tempIndex = ((gun_index==2) ? 1: 0);
  18092. }
  18093. else
  18094. {
  18095. tempIndex = gun_index;
  18096. }
  18097. for (int index = 0; index < CCS_QUANTITY; index++)
  18098. {
  18099. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18100. {
  18101. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  18102. }
  18103. }// END OF CCS_QUANTITY
  18104. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18105. }
  18106. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18107. {
  18108. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18109. {
  18110. tempIndex = ((gun_index==2) ? 1: 0);
  18111. }
  18112. else
  18113. {
  18114. tempIndex = gun_index;
  18115. }
  18116. for (int index = 0; index < GB_QUANTITY; index++)
  18117. {
  18118. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18119. {
  18120. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  18121. }
  18122. }// END OF GB_QUANTITY
  18123. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18124. }
  18125. else if(gunType[gun_index] == GUN_TYPE_DO)
  18126. {
  18127. tempIndex = gun_index;
  18128. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18129. {
  18130. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18131. {
  18132. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  18133. }
  18134. }
  18135. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18136. }
  18137. else
  18138. {
  18139. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18140. {
  18141. tempIndex = 2;
  18142. }
  18143. else
  18144. {
  18145. tempIndex = gun_index;
  18146. }
  18147. for (int index = 0; index < AC_QUANTITY; index++)
  18148. {
  18149. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18150. {
  18151. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  18152. }
  18153. }// END OF AC_QUANTITY
  18154. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18155. }
  18156. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18157. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  18158. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  18159. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18160. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  18161. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  18162. }
  18163. //2.3====================================== Power.Active.Import =========================================
  18164. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  18165. {
  18166. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18167. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18168. {
  18169. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18170. {
  18171. tempIndex = ((gun_index==2) ? 1: 0);
  18172. }
  18173. else
  18174. {
  18175. tempIndex = gun_index;
  18176. }
  18177. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18178. {
  18179. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18180. {
  18181. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18182. }
  18183. } // End for CHAdeMO_QUANTITY
  18184. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18185. }
  18186. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18187. {
  18188. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18189. {
  18190. tempIndex = ((gun_index==2) ? 1: 0);
  18191. }
  18192. else
  18193. {
  18194. tempIndex = gun_index;
  18195. }
  18196. for (int index = 0; index < CCS_QUANTITY; index++)
  18197. {
  18198. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18199. {
  18200. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18201. }
  18202. } // END for CCS_QUANTITY
  18203. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18204. }
  18205. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18206. {
  18207. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18208. {
  18209. tempIndex = ((gun_index==2) ? 1: 0);
  18210. }
  18211. else
  18212. {
  18213. tempIndex = gun_index;
  18214. }
  18215. for (int index = 0; index < GB_QUANTITY; index++)
  18216. {
  18217. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18218. {
  18219. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18220. }
  18221. }// END for GB_QUANTITY
  18222. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18223. }
  18224. else if(gunType[gun_index] == GUN_TYPE_DO)
  18225. {
  18226. tempIndex = gun_index;
  18227. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18228. {
  18229. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18230. {
  18231. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18232. }
  18233. }
  18234. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18235. }
  18236. else
  18237. {
  18238. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18239. {
  18240. tempIndex = 2;
  18241. }
  18242. else
  18243. {
  18244. tempIndex = gun_index;
  18245. }
  18246. for (int index = 0; index < AC_QUANTITY; index++)
  18247. {
  18248. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18249. {
  18250. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18251. }
  18252. } // END for AC_QUANTITY
  18253. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18254. }
  18255. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18256. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  18257. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  18258. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18259. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  18260. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  18261. }
  18262. //2.4====================================== Voltage L1 ====================================================
  18263. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18264. {
  18265. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18266. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18267. {
  18268. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18269. {
  18270. tempIndex = ((gun_index==2) ? 1: 0);
  18271. }
  18272. else
  18273. {
  18274. tempIndex = gun_index;
  18275. }
  18276. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18277. {
  18278. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18279. {
  18280. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18281. }
  18282. } // END OF FOR CHAdeMO_QUANTITY
  18283. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18284. }
  18285. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18286. {
  18287. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18288. {
  18289. tempIndex = ((gun_index==2) ? 1: 0);
  18290. }
  18291. else
  18292. {
  18293. tempIndex = gun_index;
  18294. }
  18295. for (int index = 0; index < CCS_QUANTITY; index++)
  18296. {
  18297. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18298. {
  18299. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18300. }
  18301. } // END OF FOR CCS_QUANTITY
  18302. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18303. }
  18304. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18305. {
  18306. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18307. {
  18308. tempIndex = ((gun_index==2) ? 1: 0);
  18309. }
  18310. else
  18311. {
  18312. tempIndex = gun_index;
  18313. }
  18314. for (int index = 0; index < GB_QUANTITY; index++)
  18315. {
  18316. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18317. {
  18318. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18319. }
  18320. } // END OF FOR GB_QUANTITY
  18321. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18322. }
  18323. else if(gunType[gun_index] == GUN_TYPE_DO)
  18324. {
  18325. tempIndex = gun_index;
  18326. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18327. {
  18328. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18329. {
  18330. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18331. }
  18332. }
  18333. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18334. }
  18335. else
  18336. {
  18337. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18338. {
  18339. tempIndex = 2;
  18340. }
  18341. else
  18342. {
  18343. tempIndex = gun_index;
  18344. }
  18345. for (int index = 0; index < AC_QUANTITY; index++)
  18346. {
  18347. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18348. {
  18349. 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
  18350. }
  18351. } // END OF FOR AC_QUANTITY
  18352. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18353. }
  18354. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18355. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  18356. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  18357. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18358. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  18359. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18360. }
  18361. //2.5============================================== End SoC =========================================================
  18362. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18363. {
  18364. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18365. 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))
  18366. {
  18367. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18368. {
  18369. tempIndex = ((gun_index==2) ? 1: 0);
  18370. }
  18371. else
  18372. {
  18373. tempIndex = gun_index;
  18374. }
  18375. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18376. {
  18377. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18378. {
  18379. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18380. {
  18381. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  18382. }
  18383. }
  18384. }
  18385. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18386. {
  18387. for (int index = 0; index < CCS_QUANTITY; index++)
  18388. {
  18389. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18390. {
  18391. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  18392. }
  18393. }
  18394. }
  18395. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18396. {
  18397. for (int index = 0; index < GB_QUANTITY; index++)
  18398. {
  18399. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18400. {
  18401. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  18402. }
  18403. }
  18404. }
  18405. else if(gunType[gun_index] == GUN_TYPE_DO)
  18406. {
  18407. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18408. {
  18409. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18410. {
  18411. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  18412. }
  18413. }
  18414. }
  18415. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18416. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  18417. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18418. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  18419. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  18420. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18421. } // END FOR DC CASE
  18422. }
  18423. //2.6====================================== Current.Import L2 ==============================================
  18424. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18425. {
  18426. // AC 3 phase L2 current
  18427. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18428. {
  18429. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18430. {
  18431. tempIndex = 2;
  18432. }
  18433. else
  18434. {
  18435. tempIndex = gun_index;
  18436. }
  18437. for (int index = 0; index < AC_QUANTITY; index++)
  18438. {
  18439. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18440. {
  18441. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  18442. }
  18443. }// End of for AC_QUANTITY
  18444. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  18445. }
  18446. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18447. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  18448. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  18449. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  18450. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18451. }
  18452. //2.7====================================== Current.Import L3 ==============================================
  18453. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18454. {
  18455. // AC 3 phase L3 current
  18456. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18457. {
  18458. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18459. {
  18460. tempIndex = 2;
  18461. }
  18462. else
  18463. {
  18464. tempIndex = gun_index;
  18465. }
  18466. for (int index = 0; index < AC_QUANTITY; index++)
  18467. {
  18468. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18469. {
  18470. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  18471. }
  18472. }// End of for AC_QUANTITY
  18473. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  18474. }
  18475. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18476. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  18477. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  18478. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  18479. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18480. }
  18481. //2.9====================================== Voltage L2 ====================================================
  18482. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18483. {
  18484. // AC 3 phase L2 volatge
  18485. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18486. {
  18487. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18488. {
  18489. tempIndex = 2;
  18490. }
  18491. else
  18492. {
  18493. tempIndex = gun_index;
  18494. }
  18495. for (int index = 0; index < AC_QUANTITY; index++)
  18496. {
  18497. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18498. {
  18499. 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
  18500. }
  18501. } // END OF FOR AC_QUANTITY
  18502. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  18503. }
  18504. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18505. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  18506. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  18507. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  18508. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18509. }
  18510. //2.10====================================== Voltage L3 ====================================================
  18511. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18512. {
  18513. // AC 3 phase L3 volatge
  18514. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18515. {
  18516. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18517. {
  18518. tempIndex = 2;
  18519. }
  18520. else
  18521. {
  18522. tempIndex = gun_index;
  18523. }
  18524. for (int index = 0; index < AC_QUANTITY; index++)
  18525. {
  18526. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18527. {
  18528. 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
  18529. }
  18530. } // END OF FOR AC_QUANTITY
  18531. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  18532. }
  18533. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18534. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  18535. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  18536. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  18537. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18538. }
  18539. //====================== Start SoC ================================
  18540. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18541. {
  18542. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18543. 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))
  18544. {
  18545. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18546. {
  18547. tempIndex = ((gun_index==2) ? 1: 0);
  18548. }
  18549. else
  18550. {
  18551. tempIndex = gun_index;
  18552. }
  18553. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18554. {
  18555. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18556. {
  18557. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18558. {
  18559. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  18560. }
  18561. }
  18562. }
  18563. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18564. {
  18565. for (int index = 0; index < CCS_QUANTITY; index++)
  18566. {
  18567. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18568. {
  18569. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  18570. }
  18571. }
  18572. }
  18573. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18574. {
  18575. for (int index = 0; index < GB_QUANTITY; index++)
  18576. {
  18577. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18578. {
  18579. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  18580. }
  18581. }
  18582. }
  18583. else if(gunType[gun_index] == GUN_TYPE_DO)
  18584. {
  18585. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18586. {
  18587. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18588. {
  18589. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  18590. }
  18591. }
  18592. }
  18593. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18594. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  18595. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18596. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  18597. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  18598. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18599. } // END FOR DC CASE
  18600. }
  18601. //======================================== Message create ==============================================
  18602. json_object *StopTransaction = json_object_new_object();
  18603. json_object *transactionDatas = json_object_new_array();
  18604. json_object *sampledValues = json_object_new_array();
  18605. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  18606. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  18607. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  18608. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  18609. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  18610. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  18611. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  18612. {
  18613. json_object *transactionData = json_object_new_object();
  18614. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  18615. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  18616. {
  18617. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  18618. {
  18619. json_object *sampledValue = json_object_new_object();
  18620. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  18621. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  18622. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  18623. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  18624. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  18625. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  18626. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  18627. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  18628. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  18629. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  18630. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  18631. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  18632. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  18633. json_object_array_add(sampledValues, sampledValue);
  18634. }
  18635. }
  18636. json_object_object_add(transactionData, "sampledValue", sampledValues);
  18637. json_object_array_add(transactionDatas, transactionData);
  18638. }
  18639. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  18640. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  18641. ,MESSAGE_TYPE_CALL
  18642. ,guid
  18643. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  18644. json_object_put(StopTransaction);
  18645. // Check File "TempStopTransaction" Exist
  18646. if((access(TempStopTransaction,F_OK))!=-1)
  18647. {
  18648. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  18649. fclose(fopen(TempStopTransaction, "w"));
  18650. }
  18651. else
  18652. {
  18653. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  18654. FILE *log = fopen(TempStopTransaction, "w+");
  18655. if(log == NULL)
  18656. {
  18657. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  18658. return ;
  18659. }
  18660. else
  18661. {
  18662. fclose(log);
  18663. }
  18664. }
  18665. //Add TempStopTransaction | Update TempStopTransaction
  18666. // open file for writing
  18667. FILE *outfile;
  18668. outfile = fopen (TempStopTransaction, "a");
  18669. //DEBUG_INFO("data = %s\n", queuedata);
  18670. fputs(queuedata, outfile);
  18671. fputs("\n", outfile);
  18672. fclose (outfile);
  18673. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18674. OCPP_updatePeriodEnergy(gun_index);
  18675. }
  18676. void checkTempStopTransaction(int gun_index)
  18677. {
  18678. FILE *fptr1;
  18679. char ch;
  18680. char str[QUEUE_MESSAGE_LENGTH]={0};
  18681. char guid[37]={0};
  18682. char tempdata[65]={0};
  18683. char connectorStr[2]={0};
  18684. char TempStopTransaction[256];
  18685. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  18686. fptr1 = fopen(TempStopTransaction, "r");
  18687. //TempStopTransaction格式: 槍號,StopTransaction封包
  18688. if (!fptr1)
  18689. {
  18690. //printf(" File not found or unable to open the input file!!\n");
  18691. return ;
  18692. }
  18693. ch=fgetc(fptr1);
  18694. //printf(" Now the content of the file %s is : \n",fname);
  18695. rewind(fptr1);
  18696. if(ch!=EOF)
  18697. {
  18698. // copy all contents to the temporary file except the specific line
  18699. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18700. {
  18701. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18702. if(str[0]=='\0')
  18703. {
  18704. break;
  18705. }
  18706. //TempStopTransaction格式: 槍號,StopTransaction封包
  18707. strncpy(connectorStr, str, 1);
  18708. if(atoi(connectorStr) != (gun_index+1))
  18709. {
  18710. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18711. fclose(fptr1);
  18712. return ;
  18713. }
  18714. //random_uuid(guid);
  18715. strncpy(guid, str+6, 36); //copy guid
  18716. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18717. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18718. {
  18719. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18720. }
  18721. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18722. OCPP_insert_transaction_msg(NO, str);
  18723. memset(str,0,ARRAY_SIZE(str));
  18724. }
  18725. }
  18726. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18727. fclose(fptr1);
  18728. remove(TempStopTransaction); // remove the original file
  18729. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18730. }
  18731. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18732. {
  18733. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18734. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18735. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18736. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18737. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18738. }
  18739. int GetWebSocketPingInterval(void)
  18740. {
  18741. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18742. }
  18743. int GetServerSign(void)
  18744. {
  18745. return server_sign;
  18746. }
  18747. uint8_t GetOcppSecurityProfile()
  18748. {
  18749. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18750. }
  18751. void GetOcppChargerBoxId(uint8_t *data)
  18752. {
  18753. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18754. }
  18755. void GetOcppSecurityPassword(uint8_t *data)
  18756. {
  18757. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18758. }
  18759. void SetOcppVersion(uint8_t *version)
  18760. {
  18761. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18762. DEBUG_INFO("ocpp version: %s\n", version);
  18763. if(strstr((char*)version, "ocpp1.6") != NULL)
  18764. {
  18765. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18766. }
  18767. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18768. {
  18769. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18770. system("pkill OcppBackend");
  18771. }
  18772. }
  18773. void SetServerSign(int value)
  18774. {
  18775. server_sign = value;
  18776. }
  18777. int GetBootNotificationInterval(void)
  18778. {
  18779. return BootNotificationInterval;
  18780. }
  18781. int GetInternetConn(void)
  18782. {
  18783. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18784. }
  18785. int GetBackendConnectionTimeout(void)
  18786. {
  18787. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18788. }
  18789. int isConnectorInitMode(int gun_index)
  18790. {
  18791. int tempIndex = 0;
  18792. int result = TRUE;
  18793. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18794. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18795. {
  18796. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18797. {
  18798. tempIndex = ((gun_index==2) ? 1: 0);
  18799. }
  18800. else
  18801. {
  18802. tempIndex = gun_index;
  18803. }
  18804. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18805. {
  18806. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18807. {
  18808. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18809. } //end of the same index
  18810. }//end of for CHAdeMO_QUANTITY
  18811. }
  18812. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18813. {
  18814. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18815. {
  18816. tempIndex = ((gun_index==2) ? 1: 0);
  18817. }
  18818. else
  18819. {
  18820. tempIndex = gun_index;
  18821. }
  18822. for (int index = 0; index < CCS_QUANTITY; index++)
  18823. {
  18824. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18825. {
  18826. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18827. } //end of the same index
  18828. } // end of for CCS_QUANTITY
  18829. }
  18830. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18831. {
  18832. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18833. {
  18834. tempIndex = ((gun_index==2) ? 1: 0);
  18835. }
  18836. else
  18837. {
  18838. tempIndex = gun_index;
  18839. }
  18840. for (int index = 0; index < GB_QUANTITY; index++)
  18841. {
  18842. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18843. {
  18844. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18845. } //end of the same index
  18846. } // end of for GB_QUANTITY
  18847. }
  18848. else if(gunType[gun_index] == GUN_TYPE_DO)
  18849. {
  18850. tempIndex = gun_index;
  18851. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18852. {
  18853. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18854. {
  18855. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18856. } //end of the same index
  18857. }
  18858. }
  18859. else
  18860. {
  18861. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18862. {
  18863. tempIndex = 2;
  18864. }
  18865. else
  18866. {
  18867. tempIndex = gun_index;
  18868. }
  18869. for (int index = 0; index < AC_QUANTITY; index++)
  18870. {
  18871. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18872. {
  18873. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18874. }//end of the same index
  18875. }//end of for AC_QUANTITY
  18876. }
  18877. return result;
  18878. }
  18879. void refreshProcDogTimer()
  18880. {
  18881. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  18882. }
  18883. void InitialSystemValue(void)
  18884. {
  18885. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  18886. locallistVersion=0;
  18887. BootNotificationInterval = 0;
  18888. authorizeRetryTimes = 0;
  18889. GunStatusInterval = 10;
  18890. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18891. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18892. //Hear Beat
  18893. HeartBeatWithNOResponse = 0;
  18894. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18895. FirstHeartBeat = 0;
  18896. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18897. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18898. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18899. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18900. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18901. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18902. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18903. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18904. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18905. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18906. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18907. //Status && ConnectorPlugIn Setting
  18908. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18909. {
  18910. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18911. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18912. }
  18913. for (int index = 0; index < CCS_QUANTITY; index++)
  18914. {
  18915. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18916. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18917. }
  18918. for (int index = 0; index < GB_QUANTITY; index++)
  18919. {
  18920. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18921. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18922. }
  18923. for (int index = 0; index < AC_QUANTITY; index++)
  18924. {
  18925. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18926. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18927. }
  18928. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18929. {
  18930. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18931. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18932. }
  18933. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18934. {
  18935. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18936. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18937. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18938. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18939. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18940. }
  18941. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18942. refreshStartTimer(&clientTime.Heartbeat);
  18943. sleep(1);
  18944. }
  18945. void LWS_Send(char *str)
  18946. {
  18947. //=====================================================
  18948. // Check InternetConn 0: disconnected, 1: connected
  18949. //====================================================
  18950. if(GetOcppConnStatus() == 0)
  18951. {
  18952. DEBUG_INFO("offline now !!!\n");
  18953. return;
  18954. }
  18955. // Only disable isWebsocketSendable operation initiated by charger
  18956. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18957. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18958. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18959. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18960. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18961. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18962. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18963. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18964. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18965. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18966. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18967. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18968. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18969. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18970. {
  18971. isWebsocketSendable = 0;
  18972. }
  18973. pthread_mutex_lock(&lock_send);
  18974. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18975. sprintf((char *)SendBuffer, "%s", str);
  18976. SendBufLen = strlen(str);
  18977. pthread_mutex_unlock(&lock_send);
  18978. lws_callback_on_writable(wsi_client);
  18979. //lws_service(context, 0);
  18980. //sleep(1);
  18981. }
  18982. void LWS_SendNow(char *str)
  18983. {
  18984. //=====================================================
  18985. // Check InternetConn 0: disconnected, 1: connected
  18986. //====================================================
  18987. if(GetOcppConnStatus() == 0)
  18988. {
  18989. DEBUG_INFO("offline now !!!\n");
  18990. return;
  18991. }
  18992. // Only disable isWebsocketSendable operation initiated by charger
  18993. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18994. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18995. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18996. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18997. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18998. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18999. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19000. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  19001. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19002. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  19003. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19004. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19005. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19006. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  19007. {
  19008. isWebsocketSendable = 0;
  19009. }
  19010. pthread_mutex_lock(&lock_send);
  19011. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19012. sprintf((char *)SendBuffer, "%s", str);
  19013. SendBufLen = strlen(str);
  19014. pthread_mutex_unlock(&lock_send);
  19015. lws_callback_on_writable(wsi_client);
  19016. lws_service(context, 0);
  19017. //sleep(1);
  19018. }