MessageHandler.c 947 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758
  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[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1179. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId,"%s","ID_ReaderStatus");
  1180. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].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[gun_index].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. }
  4429. //==========================================
  4430. // CSU Trigger Authorize Request
  4431. //==========================================
  4432. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4433. {
  4434. sendAuthorizeRequest(0);
  4435. authorizeRetryTimes = authorizeRetryTimes + 1;
  4436. if(authorizeRetryTimes < 3)
  4437. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4438. }
  4439. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4440. {
  4441. authorizeRetryTimes = 0;
  4442. SetOcppConnStatus(FALSE);
  4443. server_sign = FALSE;
  4444. }
  4445. 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))
  4446. {
  4447. sendAuthorizeRequest(0);
  4448. }
  4449. //==========================================
  4450. // Charger start transaction
  4451. //==========================================
  4452. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4453. {
  4454. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4455. sendStartTransactionRequest(gun_index);
  4456. refreshStartTimer(&clientTime.StartTransaction);
  4457. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4458. storeTempStopTransaction(gun_index);
  4459. }
  4460. //==========================================
  4461. // Charger stop transaction
  4462. //==========================================
  4463. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4464. {
  4465. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4466. sendStopTransactionRequest(gun_index);
  4467. OCPP_updatePeriodEnergy(gun_index);
  4468. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  4469. refreshStartTimer(&clientTime.StopTransaction);
  4470. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4471. }
  4472. //==========================================
  4473. // Charger status report
  4474. //==========================================
  4475. //--- Check Mode Change ---//
  4476. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4477. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4478. {
  4479. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4480. {
  4481. tempIndex = ((gun_index==2) ? 1: 0);
  4482. }
  4483. else
  4484. {
  4485. tempIndex = gun_index;
  4486. }
  4487. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4488. {
  4489. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4490. {
  4491. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4492. {
  4493. // Sent unplug message for California pricing logic
  4494. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  4495. {
  4496. uint8_t ts[20];
  4497. getNowDatetime(ts);
  4498. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4499. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4500. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4501. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4502. }
  4503. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4504. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4505. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4506. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4507. {
  4508. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4509. if((access(filenmae,F_OK))!=-1)
  4510. {
  4511. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4512. sprintf(str,"rm -f %s",filenmae);
  4513. system(str);
  4514. }
  4515. }
  4516. }
  4517. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4518. #if 1 // for TempStopTransaction
  4519. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4520. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4521. {
  4522. checkTempStopTransaction(gun_index);
  4523. }
  4524. #endif
  4525. }
  4526. }
  4527. }
  4528. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4529. {
  4530. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4531. {
  4532. tempIndex = ((gun_index==2) ? 1: 0);
  4533. }
  4534. else
  4535. {
  4536. tempIndex = gun_index;
  4537. }
  4538. for (int index = 0; index < CCS_QUANTITY; index++)
  4539. {
  4540. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4541. {
  4542. 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]*/ )
  4543. {
  4544. // Sent unplug message for California pricing logic
  4545. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  4546. {
  4547. uint8_t ts[20];
  4548. getNowDatetime(ts);
  4549. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4550. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4551. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4552. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4553. }
  4554. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4555. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4556. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4557. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4558. {
  4559. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4560. if((access(filenmae,F_OK))!=-1)
  4561. {
  4562. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4563. sprintf(str,"rm -f %s",filenmae);
  4564. system(str);
  4565. }
  4566. }
  4567. }
  4568. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4569. #if 1 // for TempStopTransaction
  4570. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4571. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4572. {
  4573. checkTempStopTransaction(gun_index);
  4574. }
  4575. #endif
  4576. }
  4577. }
  4578. }
  4579. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4580. {
  4581. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4582. {
  4583. tempIndex = ((gun_index==2) ? 1: 0);
  4584. }
  4585. else
  4586. {
  4587. tempIndex = gun_index;
  4588. }
  4589. for (int index = 0; index < GB_QUANTITY; index++)
  4590. {
  4591. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4592. {
  4593. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4594. {
  4595. // Sent unplug message for California pricing logic
  4596. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  4597. {
  4598. uint8_t ts[20];
  4599. getNowDatetime(ts);
  4600. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4601. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4602. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4603. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4604. }
  4605. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4606. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4607. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4608. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4609. {
  4610. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4611. if((access(filenmae,F_OK))!=-1)
  4612. {
  4613. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4614. sprintf(str,"rm -f %s",filenmae);
  4615. system(str);
  4616. }
  4617. }
  4618. }
  4619. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4620. #if 1 // for TempStopTransaction
  4621. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4622. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4623. {
  4624. checkTempStopTransaction(gun_index);
  4625. }
  4626. #endif
  4627. }
  4628. }
  4629. }
  4630. else if(gunType[gun_index] == GUN_TYPE_DO)
  4631. {
  4632. tempIndex = gun_index;
  4633. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4634. {
  4635. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4636. {
  4637. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4638. {
  4639. // Sent unplug message for California pricing logic
  4640. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  4641. {
  4642. uint8_t ts[20];
  4643. getNowDatetime(ts);
  4644. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4645. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4646. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4647. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4648. }
  4649. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4650. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4651. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4652. 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
  4653. {
  4654. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4655. if((access(filenmae,F_OK))!=-1)
  4656. {
  4657. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4658. sprintf(str,"rm -f %s",filenmae);
  4659. system(str);
  4660. }
  4661. }
  4662. }
  4663. 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);
  4664. #if 1 // for TempStopTransaction
  4665. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4666. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4667. {
  4668. checkTempStopTransaction(gun_index);
  4669. }
  4670. #endif
  4671. }
  4672. }
  4673. }
  4674. else
  4675. {
  4676. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4677. {
  4678. tempIndex = 2;
  4679. }
  4680. else
  4681. {
  4682. tempIndex = gun_index;
  4683. }
  4684. for (int index = 0; index < AC_QUANTITY; index++)
  4685. {
  4686. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4687. {
  4688. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4689. {
  4690. // Sent unplug message for California pricing logic
  4691. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  4692. {
  4693. uint8_t ts[20];
  4694. getNowDatetime(ts);
  4695. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4696. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4697. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4698. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4699. }
  4700. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4701. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4702. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4703. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4704. {
  4705. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4706. if((access(filenmae,F_OK))!=-1)
  4707. {
  4708. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4709. sprintf(str,"rm -f %s",filenmae);
  4710. system(str);
  4711. }
  4712. }
  4713. }
  4714. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4715. #if 1 // for TempStopTransaction
  4716. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4717. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4718. {
  4719. checkTempStopTransaction(gun_index);
  4720. }
  4721. #endif
  4722. }
  4723. }// END
  4724. }
  4725. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) &&
  4726. (
  4727. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4728. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4729. )
  4730. )
  4731. {
  4732. if(SystemInitial > 0)
  4733. SystemInitial -= 1;
  4734. sendStatusNotificationRequest(gun_index);
  4735. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4736. }
  4737. //==============================================
  4738. // TCCI reader status report
  4739. //==============================================
  4740. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1))
  4741. {
  4742. reportReaderStatus(gun_index);
  4743. //ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4744. }
  4745. //==============================================
  4746. // CSU Trigger Smart Charging Profile
  4747. //==============================================
  4748. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4749. {
  4750. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  4751. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4752. }
  4753. //==============================================
  4754. // Meter report
  4755. //==============================================
  4756. // Trigger MeterValue
  4757. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4758. {
  4759. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4760. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4761. }
  4762. // Clock-aligned Meter value
  4763. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4764. {
  4765. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4766. reqClockAlignMeter[gun_index] = 0;
  4767. }
  4768. // Sample period MeterValue
  4769. 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))))
  4770. {
  4771. //check Transaction active
  4772. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4773. {
  4774. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4775. {
  4776. tempIndex = ((gun_index==2) ? 1: 0);
  4777. }
  4778. else
  4779. {
  4780. tempIndex = gun_index;
  4781. }
  4782. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4783. {
  4784. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4785. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4786. {
  4787. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4788. {
  4789. reqSampleMeter[gun_index] = 1;
  4790. }
  4791. }
  4792. }// End for CHAdeMO
  4793. }
  4794. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4795. {
  4796. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4797. {
  4798. tempIndex = ((gun_index==2) ? 1: 0);
  4799. }
  4800. else
  4801. {
  4802. tempIndex = gun_index;
  4803. }
  4804. for (int index = 0; index < CCS_QUANTITY; index++)
  4805. {
  4806. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4807. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4808. {
  4809. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4810. {
  4811. reqSampleMeter[gun_index] = 1;
  4812. }
  4813. }
  4814. } // End for CCS
  4815. }
  4816. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4817. {
  4818. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4819. {
  4820. tempIndex = ((gun_index==2) ? 1: 0);
  4821. }
  4822. else
  4823. {
  4824. tempIndex = gun_index;
  4825. }
  4826. for (int index = 0; index < GB_QUANTITY; index++)
  4827. {
  4828. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4829. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4830. {
  4831. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4832. {
  4833. reqSampleMeter[gun_index] = 1;
  4834. }
  4835. }
  4836. }// End for GB
  4837. }
  4838. else if(gunType[gun_index] == GUN_TYPE_DO)
  4839. {
  4840. tempIndex = gun_index;
  4841. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4842. {
  4843. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4844. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4845. {
  4846. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4847. {
  4848. reqSampleMeter[gun_index] = 1;
  4849. }
  4850. }
  4851. }
  4852. }
  4853. else
  4854. {
  4855. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4856. {
  4857. tempIndex = 2;
  4858. }
  4859. else
  4860. {
  4861. tempIndex = gun_index;
  4862. }
  4863. for (int index = 0; index < AC_QUANTITY; index++)
  4864. {
  4865. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4866. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4867. {
  4868. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4869. {
  4870. reqSampleMeter[gun_index] = 1;
  4871. }
  4872. }
  4873. }//End for AC
  4874. }
  4875. if(reqSampleMeter[gun_index] == 1)
  4876. {
  4877. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4878. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4879. storeTempStopTransaction(gun_index);
  4880. reqSampleMeter[gun_index] = 0;
  4881. }
  4882. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4883. }
  4884. //==============================================
  4885. // Check Connector reserved
  4886. //==============================================
  4887. //===============================
  4888. // Check if Reserve is expired
  4889. //===============================
  4890. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  4891. {
  4892. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  4893. {
  4894. DEBUG_INFO("reserve expired.\n");
  4895. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  4896. }
  4897. }//END OF Check if Reserve is expired
  4898. //==========================================
  4899. // csu trigger FirmwareStatusNotificationReq
  4900. //==========================================
  4901. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4902. {
  4903. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  4904. }
  4905. //==========================================
  4906. // csu trigger DiagnosticsStatusNotificationReq
  4907. //==========================================
  4908. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4909. {
  4910. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  4911. }
  4912. //==========================================
  4913. // csu trigger CancelReservationConf
  4914. //==========================================
  4915. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4916. {
  4917. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  4918. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4919. }
  4920. //==========================================
  4921. // csu trigger ChangeAvailabilityConf
  4922. //==========================================
  4923. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4924. {
  4925. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  4926. }
  4927. //==========================================
  4928. // csu trigger UnlockConnectorConf
  4929. //==========================================
  4930. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4931. {
  4932. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  4933. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4934. }
  4935. //==========================================
  4936. // csu trigger ReserveNowConf
  4937. //==========================================
  4938. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4939. {
  4940. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  4941. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4942. }
  4943. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  4944. {
  4945. sendSignCertificateRequest();
  4946. }
  4947. }
  4948. }
  4949. //==========================================
  4950. // send request routine
  4951. //==========================================
  4952. int sendAuthorizeRequest(int gun_index)
  4953. {
  4954. mtrace();
  4955. int result = FAIL;
  4956. char message[100]={0};
  4957. char guid[37];
  4958. char tempdata[65]={0};
  4959. DEBUG_INFO("sendAuthorizeRequest...\n");
  4960. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4961. //Local Authorize
  4962. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  4963. {
  4964. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4965. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4966. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4967. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4968. result = PASS;
  4969. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4970. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4971. authorizeRetryTimes = 0;
  4972. return result;
  4973. }
  4974. 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))||
  4975. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4976. {
  4977. // Query from cache
  4978. DEBUG_INFO("Authorize from cache.\n");
  4979. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4980. // Query from list
  4981. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4982. {
  4983. DEBUG_INFO("Authorize from list.\n");
  4984. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4985. }
  4986. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4987. {
  4988. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4989. {
  4990. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4991. }
  4992. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4993. {
  4994. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4995. }
  4996. if(!GetOcppConnStatus())
  4997. {
  4998. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4999. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5000. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5001. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  5002. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5003. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5004. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5005. authorizeRetryTimes = 0;
  5006. return result;
  5007. }
  5008. }
  5009. else
  5010. {
  5011. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  5012. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5013. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5014. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  5015. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  5016. else
  5017. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  5018. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5019. result = PASS;
  5020. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5021. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5022. authorizeRetryTimes = 0;
  5023. return result;
  5024. }
  5025. }
  5026. //initialize struct Authorize
  5027. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  5028. //get data from shared memory
  5029. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5030. random_uuid(guid);
  5031. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  5032. LWS_Send(message);
  5033. sprintf(tempdata, "Authorize,%d", gun_index);
  5034. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5035. {
  5036. result = PASS;
  5037. DEBUG_INFO("Authorize mapItem pass\n");
  5038. }
  5039. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5040. return result;
  5041. }
  5042. int sendBootNotificationRequest(void)
  5043. {
  5044. mtrace();
  5045. int result = FAIL;
  5046. char message[500]={0}, payload[700]={0};
  5047. char guid[37]={0};
  5048. char tempdata[65]={0};
  5049. // Fill BootNotification fields
  5050. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  5051. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  5052. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  5053. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5054. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  5055. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  5056. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  5057. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  5058. ShmOCPP16Data->ChargeBoxId
  5059. ,ShmSysConfigAndInfo->SysConfig.ModelName
  5060. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  5061. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  5062. ,ShmOCPP16Data->BootNotification.CpFwVersion
  5063. ,ShmOCPP16Data->BootNotification.CpIccid
  5064. ,ShmOCPP16Data->BootNotification.CpImsi);
  5065. random_uuid(guid);
  5066. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  5067. LWS_Send(message);
  5068. sprintf(tempdata, "BootNotification,0");
  5069. 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*/)
  5070. {
  5071. result = PASS;
  5072. }
  5073. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5074. strcpy(queuedata,message);
  5075. return result;
  5076. }
  5077. int sendDataTransferRequest(int gun_index)
  5078. {
  5079. mtrace();
  5080. char message[1000]={0};
  5081. char guid[37]={0};
  5082. char tempdata[65]={0};
  5083. int result = FAIL;
  5084. random_uuid(guid);
  5085. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5086. MESSAGE_TYPE_CALL,
  5087. guid,
  5088. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5089. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5090. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5091. LWS_Send(message);
  5092. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5093. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5094. {
  5095. result = PASS;
  5096. DEBUG_INFO("DataTransfer mapItem pass\n");
  5097. }
  5098. return result;
  5099. }
  5100. int sendDiagnosticsStatusNotificationRequest(char *status)
  5101. {
  5102. mtrace();
  5103. int result = FAIL;
  5104. char message[110]={0};
  5105. char guid[37]={0};
  5106. char tempdata[65]={0};
  5107. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  5108. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  5109. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  5110. random_uuid(guid);
  5111. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  5112. LWS_SendNow(message);
  5113. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  5114. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5115. {
  5116. result = PASS;
  5117. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  5118. }
  5119. //#ifdef SystemLogMessage
  5120. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  5121. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5122. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  5123. //#endif
  5124. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  5125. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  5126. //record status
  5127. if(strcmp(status,"Idle")==0)
  5128. {
  5129. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  5130. }
  5131. else if(strcmp(status,"Uploaded")==0)
  5132. {
  5133. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  5134. }
  5135. else if(strcmp(status,"UploadFailed")==0)
  5136. {
  5137. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  5138. }
  5139. else if(strcmp(status,"Uploading")==0)
  5140. {
  5141. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  5142. }
  5143. return result;
  5144. }
  5145. int sendFirmwareStatusNotificationRequest(char *status)
  5146. {
  5147. mtrace();
  5148. int result = FAIL;
  5149. char message[110]={0};
  5150. char guid[37]={0};
  5151. char tempdata[65]={0};
  5152. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  5153. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  5154. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  5155. random_uuid(guid);
  5156. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  5157. LWS_SendNow(message);
  5158. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5159. 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*/)
  5160. {
  5161. result = PASS;
  5162. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  5163. }
  5164. //#ifdef SystemLogMessage
  5165. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  5166. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5167. //#endif
  5168. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  5169. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  5170. //record status
  5171. if(strcmp(status,"Downloaded")==0)
  5172. {
  5173. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  5174. }
  5175. else if(strcmp(status,"DownloadFailed")==0)
  5176. {
  5177. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  5178. }
  5179. else if(strcmp(status,"Downloading")==0)
  5180. {
  5181. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  5182. }
  5183. else if(strcmp(status,"Idle")==0)
  5184. {
  5185. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  5186. }
  5187. else if(strcmp(status,"InstallationFailed")==0)
  5188. {
  5189. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  5190. }
  5191. else if(strcmp(status,"Installing")==0)
  5192. {
  5193. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  5194. }
  5195. else if(strcmp(status,"Installed")==0)
  5196. {
  5197. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  5198. }
  5199. return result;
  5200. }
  5201. int sendHeartbeatRequest(int gun_index)
  5202. {
  5203. mtrace();
  5204. int result = FAIL;
  5205. char message[80]={0};
  5206. char guid[37]={0};
  5207. char tempdata[65]={0};
  5208. random_uuid(guid);
  5209. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  5210. , MESSAGE_TYPE_CALL
  5211. , guid );
  5212. LWS_Send(message);
  5213. sprintf(tempdata, "Heartbeat,%d", 0);
  5214. 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*/)
  5215. {
  5216. result = PASS;
  5217. }
  5218. return result;
  5219. }
  5220. int sendStartTransactionRequest(int gun_index)
  5221. {
  5222. mtrace();
  5223. int result = FAIL;
  5224. char message[250]={0};
  5225. char guid[37]={0};
  5226. struct timeval tmnow;
  5227. struct tm *tm;
  5228. char buf[28];//, usec_buf[6];
  5229. char tempdata[65]={0};
  5230. int tempIndex = 0;
  5231. DEBUG_INFO("sendStartTransactionRequest...\n");
  5232. gettimeofday(&tmnow, NULL);
  5233. time_t t;
  5234. t = time(NULL);
  5235. /*UTC time and date*/
  5236. tm = gmtime(&t);
  5237. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5238. #if 0 // remove temporally
  5239. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5240. strcat(buf,".");
  5241. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5242. strcat(buf,usec_buf);
  5243. #endif
  5244. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  5245. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  5246. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5247. // clear StartTransaction Response
  5248. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  5249. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  5250. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  5251. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  5252. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5253. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5254. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5255. {
  5256. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5257. {
  5258. tempIndex = ((gun_index==2) ? 1: 0);
  5259. }
  5260. else
  5261. {
  5262. tempIndex = gun_index;
  5263. }
  5264. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5265. {
  5266. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5267. {
  5268. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5269. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  5270. }
  5271. }
  5272. }
  5273. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5274. {
  5275. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5276. {
  5277. tempIndex = ((gun_index==2) ? 1: 0);
  5278. }
  5279. else
  5280. {
  5281. tempIndex = gun_index;
  5282. }
  5283. for (int index = 0; index < CCS_QUANTITY; index++)
  5284. {
  5285. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5286. {
  5287. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5288. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  5289. }
  5290. }
  5291. }
  5292. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5293. {
  5294. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5295. {
  5296. tempIndex = ((gun_index==2) ? 1: 0);
  5297. }
  5298. else
  5299. {
  5300. tempIndex = gun_index;
  5301. }
  5302. for (int index = 0; index < GB_QUANTITY; index++)
  5303. {
  5304. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5305. {
  5306. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5307. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  5308. }
  5309. }
  5310. }
  5311. else if(gunType[gun_index] == GUN_TYPE_DO)
  5312. {
  5313. tempIndex = gun_index;
  5314. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5315. {
  5316. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5317. {
  5318. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5319. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5320. }
  5321. }
  5322. }
  5323. else
  5324. {
  5325. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5326. {
  5327. tempIndex = 2;
  5328. }
  5329. else
  5330. {
  5331. tempIndex = gun_index;
  5332. }
  5333. for (int index = 0; index < AC_QUANTITY; index++)
  5334. {
  5335. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5336. {
  5337. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5338. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5339. }
  5340. }
  5341. }
  5342. random_uuid(guid);
  5343. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5344. {
  5345. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5346. , gun_index +1
  5347. , MESSAGE_TYPE_CALL
  5348. , guid
  5349. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5350. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5351. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5352. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5353. }
  5354. else
  5355. {
  5356. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5357. , gun_index +1
  5358. , MESSAGE_TYPE_CALL
  5359. , guid
  5360. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5361. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5362. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5363. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  5364. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5365. }
  5366. #if 1
  5367. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5368. 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*/)
  5369. {
  5370. result = PASS;
  5371. }
  5372. #endif
  5373. strcpy(queuedata, message);
  5374. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5375. OCPP_insert_transaction_msg(YES, queuedata);
  5376. return result;
  5377. }
  5378. int sendStatusNotificationRequest(int gun_index)
  5379. {
  5380. mtrace();
  5381. int result = FAIL;
  5382. char message[600]={0};
  5383. char guid[37];
  5384. int currentStatus = 0;
  5385. struct timeval tmnow;
  5386. struct tm *tm;
  5387. char buf[28];//, usec_buf[6];
  5388. char tempdata[65]={0};
  5389. int tempIndex = 0;
  5390. uint8_t isStateChanged = TRUE;
  5391. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5392. gettimeofday(&tmnow, NULL);
  5393. time_t t;
  5394. t = time(NULL);
  5395. /*UTC time and date*/
  5396. tm = gmtime(&t);
  5397. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5398. #if 0 // remove temporally
  5399. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5400. strcat(buf,".");
  5401. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5402. strcat(buf,usec_buf);
  5403. #endif
  5404. //printf("%s",buf);
  5405. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5406. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5407. // it's option
  5408. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  5409. /*
  5410. enum _SYSTEM_STATUS
  5411. {
  5412. S_BOOTING = 0,
  5413. S_IDLE, = 1
  5414. S_AUTHORIZING, =2
  5415. S_REASSIGN_CHECK, =3
  5416. S_REASSIGN, =4
  5417. S_PRECHARGE, =5
  5418. S_PREPARING_FOR_EV, =6
  5419. S_PREPARING_FOR_EVSE, =7
  5420. S_CHARGING, =8
  5421. S_TERMINATING, =9
  5422. S_COMPLETE, =10
  5423. S_ALARM, =11
  5424. S_FAULT =12
  5425. }
  5426. */
  5427. //check Transaction active
  5428. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5429. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5430. {
  5431. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5432. {
  5433. tempIndex = ((gun_index==2) ? 1: 0);
  5434. }
  5435. else
  5436. {
  5437. tempIndex = gun_index;
  5438. }
  5439. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5440. {
  5441. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5442. {
  5443. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5444. {
  5445. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5446. {
  5447. currentStatus = Preparing; //OCPP Status: Preparing
  5448. }
  5449. else
  5450. {
  5451. currentStatus = Available; //OCPP Status: Available
  5452. }
  5453. }
  5454. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5455. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5456. ) //S_PRECHARGE
  5457. {
  5458. currentStatus = Preparing; //OCPP Status: Preparing
  5459. }
  5460. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5461. {
  5462. currentStatus = Charging; //OCPP Status: Charging
  5463. }
  5464. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5465. {
  5466. currentStatus = Finishing; //OCPP Status: Finishing
  5467. }
  5468. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5469. {
  5470. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5471. }
  5472. 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
  5473. {
  5474. currentStatus = Unavailable; //OCPP Status: Unavailable
  5475. }
  5476. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5477. {
  5478. currentStatus = Faulted; //OCPP Status: Faulted
  5479. }
  5480. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5481. {
  5482. currentStatus = Reserved; //OCPP Status: Reserved
  5483. }
  5484. } //end of the same index
  5485. }//end of for CHAdeMO_QUANTITY
  5486. }
  5487. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5488. {
  5489. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5490. {
  5491. tempIndex = ((gun_index==2) ? 1: 0);
  5492. }
  5493. else
  5494. {
  5495. tempIndex = gun_index;
  5496. }
  5497. for (int index = 0; index < CCS_QUANTITY; index++)
  5498. {
  5499. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5500. {
  5501. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5502. {
  5503. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5504. {
  5505. currentStatus = Preparing; //OCPP Status: Preparing
  5506. }
  5507. else
  5508. {
  5509. currentStatus = Available; //OCPP Status: Available
  5510. }
  5511. }
  5512. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5513. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5514. ) //S_PRECHARGE
  5515. {
  5516. currentStatus = Preparing; //OCPP Status: Preparing
  5517. }
  5518. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5519. {
  5520. currentStatus = Charging; //OCPP Status: Charging
  5521. }
  5522. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5523. {
  5524. currentStatus = Finishing; //OCPP Status: Finishing
  5525. }
  5526. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5527. {
  5528. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5529. }
  5530. 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
  5531. {
  5532. currentStatus = Unavailable; //OCPP Status : Unavailable
  5533. }
  5534. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5535. {
  5536. currentStatus = Faulted; //OCPP Status: Faulted
  5537. }
  5538. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5539. {
  5540. currentStatus = Reserved; //OCPP Status: Reserved
  5541. }
  5542. } //end of the same index
  5543. } // end of for CCS_QUANTITY
  5544. }
  5545. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5546. {
  5547. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5548. {
  5549. tempIndex = ((gun_index==2) ? 1: 0);
  5550. }
  5551. else
  5552. {
  5553. tempIndex = gun_index;
  5554. }
  5555. for (int index = 0; index < GB_QUANTITY; index++)
  5556. {
  5557. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5558. {
  5559. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5560. {
  5561. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5562. {
  5563. currentStatus = Preparing; //OCPP Status: Preparing
  5564. }
  5565. else
  5566. {
  5567. currentStatus = Available; //OCPP Status: Available
  5568. }
  5569. }
  5570. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5571. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5572. ) //S_PRECHARGE
  5573. {
  5574. currentStatus = Preparing; //OCPP Status: Preparing
  5575. }
  5576. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5577. {
  5578. currentStatus = Charging; //OCPP Status: Charging
  5579. }
  5580. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5581. {
  5582. currentStatus = Finishing; //OCPP Status: Finishing
  5583. }
  5584. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5585. {
  5586. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5587. }
  5588. 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
  5589. {
  5590. currentStatus = Unavailable; //OCPP Status: Unavailable
  5591. }
  5592. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5593. {
  5594. currentStatus = Faulted; //OCPP Status: Faulted
  5595. }
  5596. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5597. {
  5598. currentStatus = Reserved; //OCPP Status: Reserved
  5599. }
  5600. } //end of the same index
  5601. } // end of for GB_QUANTITY
  5602. }
  5603. else if(gunType[gun_index] == GUN_TYPE_DO)
  5604. {
  5605. tempIndex = gun_index;
  5606. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5607. {
  5608. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5609. {
  5610. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5611. {
  5612. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5613. {
  5614. currentStatus = Preparing; //OCPP Status: Preparing
  5615. }
  5616. else
  5617. {
  5618. currentStatus = Available; //OCPP Status: Available
  5619. }
  5620. }
  5621. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5622. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5623. ) //S_PRECHARGE
  5624. {
  5625. currentStatus = Preparing; //OCPP Status: Preparing
  5626. }
  5627. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5628. {
  5629. currentStatus = Charging; //OCPP Status: Charging
  5630. }
  5631. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5632. {
  5633. currentStatus = Finishing; //OCPP Status: Finishing
  5634. }
  5635. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5636. {
  5637. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5638. }
  5639. 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
  5640. {
  5641. currentStatus = Unavailable; //OCPP Status: Unavailable
  5642. }
  5643. 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
  5644. {
  5645. currentStatus = Faulted; //OCPP Status: Faulted
  5646. }
  5647. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5648. {
  5649. currentStatus = Reserved; //OCPP Status: Reserved
  5650. }
  5651. } //end of the same index
  5652. }
  5653. }
  5654. else
  5655. {
  5656. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5657. {
  5658. tempIndex = 2;
  5659. }
  5660. else
  5661. {
  5662. tempIndex = gun_index;
  5663. }
  5664. for (int index = 0; index < AC_QUANTITY; index++)
  5665. {
  5666. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5667. {
  5668. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5669. {
  5670. 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))
  5671. {
  5672. currentStatus = Preparing; //OCPP Status: Preparing
  5673. }
  5674. else
  5675. {
  5676. currentStatus = Available; //OCPP Status: Available
  5677. }
  5678. }
  5679. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5680. {
  5681. currentStatus = Preparing; //OCPP Status: Preparing
  5682. }
  5683. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5684. {
  5685. currentStatus = Charging; //OCPP Status: Charging
  5686. }
  5687. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5688. {
  5689. currentStatus = Finishing; //OCPP Status: Finishing
  5690. }
  5691. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5692. {
  5693. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5694. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5695. else
  5696. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5697. }
  5698. 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
  5699. {
  5700. currentStatus = Unavailable; //OCPP Status: Unavailable
  5701. }
  5702. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5703. {
  5704. currentStatus = Faulted; //OCPP Status: Faulted
  5705. }
  5706. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5707. {
  5708. currentStatus = Reserved; //OCPP Status: Reserved
  5709. }
  5710. }//end of the same index
  5711. }//end of for AC_QUANTITY
  5712. }
  5713. //it's option
  5714. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5715. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5716. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5717. {
  5718. isStateChanged = FALSE;
  5719. }
  5720. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5721. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  5722. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5723. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5724. random_uuid(guid);
  5725. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5726. , MESSAGE_TYPE_CALL
  5727. , guid
  5728. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  5729. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  5730. , ShmOCPP16Data->StatusNotification[gun_index].Info
  5731. , ShmOCPP16Data->StatusNotification[gun_index].Status
  5732. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  5733. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  5734. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  5735. if((server_sign == TRUE) && isStateChanged)
  5736. {
  5737. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5738. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5739. LWS_Send(message);
  5740. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5741. 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*/)
  5742. {
  5743. //DEBUG_ERROR("statusNotification mapitem pass");
  5744. result = PASS;
  5745. }
  5746. }
  5747. else
  5748. {
  5749. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5750. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5751. result = PASS;
  5752. }
  5753. return result;
  5754. }
  5755. int sendStopTransactionRequest(int gun_index)
  5756. {
  5757. mtrace();
  5758. int result = FAIL;
  5759. //char message[1500]={0};
  5760. char guid[37]={0};
  5761. char tempdata[65]={0};
  5762. int tempIndex = 0;
  5763. char TempStopTransaction[256];
  5764. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  5765. //int idx_sample=0;
  5766. DEBUG_INFO("sendStopTransactionRequest \n");
  5767. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5768. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  5769. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5770. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5771. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5772. {
  5773. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5774. {
  5775. tempIndex = ((gun_index==2) ? 1: 0);
  5776. }
  5777. else
  5778. {
  5779. tempIndex = gun_index;
  5780. }
  5781. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5782. {
  5783. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5784. {
  5785. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5786. }
  5787. }// END OF CHAdeMO_QUANTITY
  5788. }
  5789. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5790. {
  5791. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5792. {
  5793. tempIndex = ((gun_index==2) ? 1: 0);
  5794. }
  5795. else
  5796. {
  5797. tempIndex = gun_index;
  5798. }
  5799. for (int index = 0; index < CCS_QUANTITY; index++)
  5800. {
  5801. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5802. {
  5803. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5804. }
  5805. }// END OF CCS_QUANTITY
  5806. }
  5807. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5808. {
  5809. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5810. {
  5811. tempIndex = ((gun_index==2) ? 1: 0);
  5812. }
  5813. else
  5814. {
  5815. tempIndex = gun_index;
  5816. }
  5817. for (int index = 0; index < GB_QUANTITY; index++)
  5818. {
  5819. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5820. {
  5821. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5822. }
  5823. }// END OF GB_QUANTITY
  5824. }
  5825. else if(gunType[gun_index] == GUN_TYPE_DO)
  5826. {
  5827. tempIndex = gun_index;
  5828. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5829. {
  5830. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5831. {
  5832. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5833. }
  5834. }// END OF GB_QUANTITY
  5835. }
  5836. else
  5837. {
  5838. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5839. {
  5840. tempIndex = 2;
  5841. }
  5842. else
  5843. {
  5844. tempIndex = gun_index;
  5845. }
  5846. for (int index = 0; index < AC_QUANTITY; index++)
  5847. {
  5848. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5849. {
  5850. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5851. }
  5852. }// END OF AC_QUANTITY
  5853. }
  5854. //====================================== Stop Transaction Time =====================================================
  5855. struct timeval tmnow;
  5856. struct tm *tm;
  5857. char buf[28];//, usec_buf[6];
  5858. gettimeofday(&tmnow, NULL);
  5859. time_t t;
  5860. t = time(NULL);
  5861. /*UTC time and date*/
  5862. tm = gmtime(&t);
  5863. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5864. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  5865. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  5866. random_uuid(guid);
  5867. /***********************************transactionData******************************************************/
  5868. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5869. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5870. //=================================
  5871. // Transaction_Begin
  5872. //=================================
  5873. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5874. {
  5875. //============================================ Energy.Active.Import.Interval ================================
  5876. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5877. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5878. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5879. 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*/]);
  5880. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5881. 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))
  5882. {
  5883. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5884. }
  5885. else
  5886. {
  5887. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5888. }
  5889. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5890. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5891. }
  5892. //=================================
  5893. // Transaction_End
  5894. //=================================
  5895. // ================================= Current.Import L1 ===============================================
  5896. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5897. {
  5898. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5899. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5900. {
  5901. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5902. {
  5903. tempIndex = ((gun_index==2) ? 1: 0);
  5904. }
  5905. else
  5906. {
  5907. tempIndex = gun_index;
  5908. }
  5909. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5910. {
  5911. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5912. {
  5913. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5914. }
  5915. }// End of for CHAdeMO_QUANTITY
  5916. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5917. }
  5918. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5919. {
  5920. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5921. {
  5922. tempIndex = ((gun_index==2) ? 1: 0);
  5923. }
  5924. else
  5925. {
  5926. tempIndex = gun_index;
  5927. }
  5928. for (int index = 0; index < CCS_QUANTITY; index++)
  5929. {
  5930. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5931. {
  5932. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5933. }
  5934. }// End of for CCS_QUANTITY
  5935. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5936. }
  5937. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5938. {
  5939. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5940. {
  5941. tempIndex = ((gun_index==2) ? 1: 0);
  5942. }
  5943. else
  5944. {
  5945. tempIndex = gun_index;
  5946. }
  5947. for (int index = 0; index < GB_QUANTITY; index++)
  5948. {
  5949. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5950. {
  5951. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5952. }
  5953. }// End of for GB_QUANTITY
  5954. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5955. }
  5956. else if(gunType[gun_index] == GUN_TYPE_DO)
  5957. {
  5958. tempIndex = gun_index;
  5959. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5960. {
  5961. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5962. {
  5963. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5964. }
  5965. }
  5966. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5967. }
  5968. else
  5969. {
  5970. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5971. {
  5972. tempIndex = 2;
  5973. }
  5974. else
  5975. {
  5976. tempIndex = gun_index;
  5977. }
  5978. for (int index = 0; index < AC_QUANTITY; index++)
  5979. {
  5980. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5981. {
  5982. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5983. }
  5984. }// End of for AC_QUANTITY
  5985. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5986. }
  5987. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5988. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5989. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5990. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5991. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5992. }
  5993. // ================================= Energy.Active.Import.Interval ==============================================
  5994. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5995. {
  5996. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5997. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5998. {
  5999. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6000. {
  6001. tempIndex = ((gun_index==2) ? 1: 0);
  6002. }
  6003. else
  6004. {
  6005. tempIndex = gun_index;
  6006. }
  6007. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6008. {
  6009. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6010. {
  6011. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  6012. }
  6013. }// END OF CHAdeMO_QUANTITY
  6014. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6015. }
  6016. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6017. {
  6018. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6019. {
  6020. tempIndex = ((gun_index==2) ? 1: 0);
  6021. }
  6022. else
  6023. {
  6024. tempIndex = gun_index;
  6025. }
  6026. for (int index = 0; index < CCS_QUANTITY; index++)
  6027. {
  6028. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6029. {
  6030. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  6031. }
  6032. }// END OF CCS_QUANTITY
  6033. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6034. }
  6035. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6036. {
  6037. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6038. {
  6039. tempIndex = ((gun_index==2) ? 1: 0);
  6040. }
  6041. else
  6042. {
  6043. tempIndex = gun_index;
  6044. }
  6045. for (int index = 0; index < GB_QUANTITY; index++)
  6046. {
  6047. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6048. {
  6049. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  6050. }
  6051. }// END OF GB_QUANTITY
  6052. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6053. }
  6054. else if(gunType[gun_index] == GUN_TYPE_DO)
  6055. {
  6056. tempIndex = gun_index;
  6057. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6058. {
  6059. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6060. {
  6061. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  6062. }
  6063. }
  6064. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6065. }
  6066. else
  6067. {
  6068. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6069. {
  6070. tempIndex = 2;
  6071. }
  6072. else
  6073. {
  6074. tempIndex = gun_index;
  6075. }
  6076. for (int index = 0; index < AC_QUANTITY; index++)
  6077. {
  6078. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6079. {
  6080. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  6081. }
  6082. }// END OF AC_QUANTITY
  6083. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  6084. }
  6085. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6086. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  6087. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  6088. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  6089. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6090. }
  6091. //=================================== Power.Active.Import ==================================================
  6092. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  6093. {
  6094. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6095. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6096. {
  6097. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6098. {
  6099. tempIndex = ((gun_index==2) ? 1: 0);
  6100. }
  6101. else
  6102. {
  6103. tempIndex = gun_index;
  6104. }
  6105. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6106. {
  6107. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6108. {
  6109. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6110. }
  6111. } // End for CHAdeMO_QUANTITY
  6112. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6113. }
  6114. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6115. {
  6116. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6117. {
  6118. tempIndex = ((gun_index==2) ? 1: 0);
  6119. }
  6120. else
  6121. {
  6122. tempIndex = gun_index;
  6123. }
  6124. for (int index = 0; index < CCS_QUANTITY; index++)
  6125. {
  6126. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6127. {
  6128. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6129. }
  6130. } // END for CCS_QUANTITY
  6131. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6132. }
  6133. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6134. {
  6135. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6136. {
  6137. tempIndex = ((gun_index==2) ? 1: 0);
  6138. }
  6139. else
  6140. {
  6141. tempIndex = gun_index;
  6142. }
  6143. for (int index = 0; index < GB_QUANTITY; index++)
  6144. {
  6145. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6146. {
  6147. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6148. }
  6149. }// END for GB_QUANTITY
  6150. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6151. }
  6152. else if(gunType[gun_index] == GUN_TYPE_DO)
  6153. {
  6154. tempIndex = gun_index;
  6155. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6156. {
  6157. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6158. {
  6159. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6160. }
  6161. }
  6162. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6163. }
  6164. else
  6165. {
  6166. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6167. {
  6168. tempIndex = 2;
  6169. }
  6170. else
  6171. {
  6172. tempIndex = gun_index;
  6173. }
  6174. for (int index = 0; index < AC_QUANTITY; index++)
  6175. {
  6176. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6177. {
  6178. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6179. }
  6180. } // END for AC_QUANTITY
  6181. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  6182. }
  6183. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6184. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  6185. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  6186. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  6187. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  6188. }
  6189. //============================ Voltage L1 ====================================
  6190. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6191. {
  6192. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6193. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6194. {
  6195. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6196. {
  6197. tempIndex = ((gun_index==2) ? 1: 0);
  6198. }
  6199. else
  6200. {
  6201. tempIndex = gun_index;
  6202. }
  6203. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6204. {
  6205. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6206. {
  6207. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6208. }
  6209. } // END OF FOR CHAdeMO_QUANTITY
  6210. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6211. }
  6212. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6213. {
  6214. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6215. {
  6216. tempIndex = ((gun_index==2) ? 1: 0);
  6217. }
  6218. else
  6219. {
  6220. tempIndex = gun_index;
  6221. }
  6222. for (int index = 0; index < CCS_QUANTITY; index++)
  6223. {
  6224. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6225. {
  6226. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6227. }
  6228. } // END OF FOR CCS_QUANTITY
  6229. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6230. }
  6231. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6232. {
  6233. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6234. {
  6235. tempIndex = ((gun_index==2) ? 1: 0);
  6236. }
  6237. else
  6238. {
  6239. tempIndex = gun_index;
  6240. }
  6241. for (int index = 0; index < GB_QUANTITY; index++)
  6242. {
  6243. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6244. {
  6245. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6246. }
  6247. } // END OF FOR GB_QUANTITY
  6248. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6249. }
  6250. else if(gunType[gun_index] == GUN_TYPE_DO)
  6251. {
  6252. tempIndex = gun_index;
  6253. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6254. {
  6255. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6256. {
  6257. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6258. }
  6259. }
  6260. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6261. }
  6262. else
  6263. {
  6264. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6265. {
  6266. tempIndex = 2;
  6267. }
  6268. else
  6269. {
  6270. tempIndex = gun_index;
  6271. }
  6272. for (int index = 0; index < AC_QUANTITY; index++)
  6273. {
  6274. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6275. {
  6276. 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
  6277. }
  6278. } // END OF FOR AC_QUANTITY
  6279. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  6280. }
  6281. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6282. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  6283. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  6284. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  6285. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6286. }
  6287. //====================== End SoC ================================
  6288. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6289. {
  6290. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6291. 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))
  6292. {
  6293. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6294. {
  6295. tempIndex = ((gun_index==2) ? 1: 0);
  6296. }
  6297. else
  6298. {
  6299. tempIndex = gun_index;
  6300. }
  6301. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6302. {
  6303. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6304. {
  6305. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6306. {
  6307. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  6308. }
  6309. }
  6310. }
  6311. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6312. {
  6313. for (int index = 0; index < CCS_QUANTITY; index++)
  6314. {
  6315. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6316. {
  6317. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  6318. }
  6319. }
  6320. }
  6321. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6322. {
  6323. for (int index = 0; index < GB_QUANTITY; index++)
  6324. {
  6325. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6326. {
  6327. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6328. }
  6329. }
  6330. }
  6331. else if(gunType[gun_index] == GUN_TYPE_DO)
  6332. {
  6333. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6334. {
  6335. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6336. {
  6337. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6338. }
  6339. }
  6340. }
  6341. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6342. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6343. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6344. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6345. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6346. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6347. } // END FOR DC CASE
  6348. }
  6349. // ================================= Current.Import L2 ===============================================
  6350. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6351. {
  6352. // AC 3 phse L2 current
  6353. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6354. {
  6355. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6356. {
  6357. tempIndex = 2;
  6358. }
  6359. else
  6360. {
  6361. tempIndex = gun_index;
  6362. }
  6363. for (int index = 0; index < AC_QUANTITY; index++)
  6364. {
  6365. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6366. {
  6367. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6368. }
  6369. }// End of for AC_QUANTITY
  6370. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6371. }
  6372. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6373. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6374. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6375. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6376. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6377. }
  6378. // ================================= Current.Import L3 ===============================================
  6379. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6380. {
  6381. // AC 3 phse L3 current
  6382. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6383. {
  6384. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6385. {
  6386. tempIndex = 2;
  6387. }
  6388. else
  6389. {
  6390. tempIndex = gun_index;
  6391. }
  6392. for (int index = 0; index < AC_QUANTITY; index++)
  6393. {
  6394. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6395. {
  6396. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6397. }
  6398. }// End of for AC_QUANTITY
  6399. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6400. }
  6401. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6402. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6403. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6404. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6405. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6406. }
  6407. //============================ Voltage L2 ====================================
  6408. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6409. {
  6410. // AC 3 phse L2 voltage
  6411. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6412. {
  6413. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6414. {
  6415. tempIndex = 2;
  6416. }
  6417. else
  6418. {
  6419. tempIndex = gun_index;
  6420. }
  6421. for (int index = 0; index < AC_QUANTITY; index++)
  6422. {
  6423. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6424. {
  6425. 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
  6426. }
  6427. } // END OF FOR AC_QUANTITY
  6428. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6429. }
  6430. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6431. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6432. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6433. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6434. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6435. }
  6436. //============================ Voltage L3 ====================================
  6437. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6438. {
  6439. // AC 3 phse L3 voltage
  6440. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6441. {
  6442. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6443. {
  6444. tempIndex = 2;
  6445. }
  6446. else
  6447. {
  6448. tempIndex = gun_index;
  6449. }
  6450. for (int index = 0; index < AC_QUANTITY; index++)
  6451. {
  6452. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6453. {
  6454. 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
  6455. }
  6456. } // END OF FOR AC_QUANTITY
  6457. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6458. }
  6459. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6460. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6461. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6462. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6463. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6464. }
  6465. //====================== Start SoC ================================
  6466. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6467. {
  6468. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6469. 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))
  6470. {
  6471. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6472. {
  6473. tempIndex = ((gun_index==2) ? 1: 0);
  6474. }
  6475. else
  6476. {
  6477. tempIndex = gun_index;
  6478. }
  6479. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6480. {
  6481. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6482. {
  6483. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6484. {
  6485. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6486. }
  6487. }
  6488. }
  6489. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6490. {
  6491. for (int index = 0; index < CCS_QUANTITY; index++)
  6492. {
  6493. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6494. {
  6495. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6496. }
  6497. }
  6498. }
  6499. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6500. {
  6501. for (int index = 0; index < GB_QUANTITY; index++)
  6502. {
  6503. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6504. {
  6505. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6506. }
  6507. }
  6508. }
  6509. else if(gunType[gun_index] == GUN_TYPE_DO)
  6510. {
  6511. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6512. {
  6513. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6514. {
  6515. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6516. }
  6517. }
  6518. }
  6519. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6520. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6521. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6522. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6523. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6524. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6525. } // END FOR DC CASE
  6526. }
  6527. //================================================ Message create ====================================================
  6528. json_object *StopTransaction = json_object_new_object();
  6529. json_object *transactionDatas = json_object_new_array();
  6530. json_object *sampledValues = json_object_new_array();
  6531. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6532. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6533. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6534. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6535. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6536. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6537. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6538. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  6539. {
  6540. json_object *transactionData = json_object_new_object();
  6541. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6542. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6543. {
  6544. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6545. {
  6546. json_object *sampledValue = json_object_new_object();
  6547. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6548. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6549. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6550. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6551. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6552. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6553. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6554. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6555. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6556. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6557. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6558. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6559. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6560. json_object_array_add(sampledValues, sampledValue);
  6561. }
  6562. }
  6563. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6564. json_object_array_add(transactionDatas, transactionData);
  6565. }
  6566. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6567. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6568. ,MESSAGE_TYPE_CALL
  6569. ,guid
  6570. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6571. json_object_put(StopTransaction);
  6572. #if 1 // for TempStopTransaction
  6573. //Delete TempStopTransaction
  6574. if((access(TempStopTransaction,F_OK))!=-1)
  6575. {
  6576. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6577. }
  6578. #endif
  6579. #if 1
  6580. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6581. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6582. {
  6583. result = PASS;
  6584. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6585. }
  6586. #endif
  6587. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6588. OCPP_insert_transaction_msg(NO, queuedata);
  6589. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6590. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6591. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6592. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6593. {
  6594. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6595. }
  6596. //for test
  6597. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6598. return result;
  6599. }
  6600. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6601. {
  6602. mtrace();
  6603. int result = FAIL;
  6604. char guid[37]={0};
  6605. char tempdata[65]={0};
  6606. int tempIndex = 0;
  6607. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6608. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6609. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6610. //set value
  6611. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6612. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6613. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6614. -1);
  6615. random_uuid(guid);
  6616. //UTC Date time
  6617. struct timeval tmnow;
  6618. struct tm *tm;
  6619. char buf[28];//, usec_buf[6];
  6620. gettimeofday(&tmnow, NULL);
  6621. time_t t;
  6622. t = time(NULL);
  6623. /*UTC time and date*/
  6624. tm = gmtime(&t);
  6625. if(dataType == ReadingContext_Sample_Clock)
  6626. {
  6627. struct tm *tmTarget;
  6628. struct timeb tbTarget;
  6629. tbTarget.time = mktime(tm);
  6630. tbTarget.time -= (atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6631. tmTarget = gmtime(&tbTarget.time);
  6632. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6633. }
  6634. else
  6635. {
  6636. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6637. }
  6638. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6639. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6640. //********************************(1)Current.Import L1************************************************/
  6641. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6642. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6643. (dataType == ReadingContext_Trigger))
  6644. {
  6645. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6646. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6647. {
  6648. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6649. {
  6650. tempIndex = ((gun_index==2) ? 1: 0);
  6651. }
  6652. else
  6653. {
  6654. tempIndex = gun_index;
  6655. }
  6656. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6657. {
  6658. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6659. {
  6660. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6661. }
  6662. }
  6663. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6664. }
  6665. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6666. {
  6667. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6668. {
  6669. tempIndex = ((gun_index==2) ? 1: 0);
  6670. }
  6671. else
  6672. {
  6673. tempIndex = gun_index;
  6674. }
  6675. for (int index = 0; index < CCS_QUANTITY; index++)
  6676. {
  6677. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6678. {
  6679. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6680. }
  6681. }
  6682. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6683. }
  6684. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6685. {
  6686. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6687. {
  6688. tempIndex = ((gun_index==2) ? 1: 0);
  6689. }
  6690. else
  6691. {
  6692. tempIndex = gun_index;
  6693. }
  6694. for (int index = 0; index < GB_QUANTITY; index++)
  6695. {
  6696. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6697. {
  6698. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6699. }
  6700. }
  6701. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6702. }
  6703. else if(gunType[gun_index] == GUN_TYPE_DO)
  6704. {
  6705. tempIndex = gun_index;
  6706. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6707. {
  6708. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6709. {
  6710. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6711. }
  6712. }
  6713. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6714. }
  6715. else
  6716. {
  6717. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6718. {
  6719. tempIndex = 2;
  6720. }
  6721. else
  6722. {
  6723. tempIndex = gun_index;
  6724. }
  6725. for (int index = 0; index < AC_QUANTITY; index++)
  6726. {
  6727. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6728. {
  6729. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6730. }
  6731. }
  6732. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6733. }
  6734. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6735. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6736. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6737. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6738. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6739. }
  6740. //********************************(2)Energy.Active.Import.Register ************************************************/
  6741. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6742. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6743. (dataType == ReadingContext_Trigger))
  6744. {
  6745. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6746. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6747. {
  6748. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6749. {
  6750. tempIndex = ((gun_index==2) ? 1: 0);
  6751. }
  6752. else
  6753. {
  6754. tempIndex = gun_index;
  6755. }
  6756. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6757. {
  6758. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6759. {
  6760. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6761. }
  6762. }
  6763. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6764. }
  6765. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6766. {
  6767. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6768. {
  6769. tempIndex = ((gun_index==2) ? 1: 0);
  6770. }
  6771. else
  6772. {
  6773. tempIndex = gun_index;
  6774. }
  6775. for (int index = 0; index < CCS_QUANTITY; index++)
  6776. {
  6777. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6778. {
  6779. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6780. }
  6781. }
  6782. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6783. }
  6784. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6785. {
  6786. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6787. {
  6788. tempIndex = ((gun_index==2) ? 1: 0);
  6789. }
  6790. else
  6791. {
  6792. tempIndex = gun_index;
  6793. }
  6794. for (int index = 0; index < GB_QUANTITY; index++)
  6795. {
  6796. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6797. {
  6798. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6799. }
  6800. }
  6801. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6802. }
  6803. else if(gunType[gun_index] == GUN_TYPE_DO)
  6804. {
  6805. tempIndex = gun_index;
  6806. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6807. {
  6808. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6809. {
  6810. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6811. }
  6812. }
  6813. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6814. }
  6815. else
  6816. {
  6817. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6818. {
  6819. tempIndex = 2;
  6820. }
  6821. else
  6822. {
  6823. tempIndex = gun_index;
  6824. }
  6825. for (int index = 0; index < AC_QUANTITY; index++)
  6826. {
  6827. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6828. {
  6829. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6830. }
  6831. }
  6832. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6833. }
  6834. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6835. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6836. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6837. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6838. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6839. }
  6840. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6841. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6842. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6843. (dataType == ReadingContext_Trigger))
  6844. {
  6845. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6846. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6847. {
  6848. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6849. {
  6850. tempIndex = ((gun_index==2) ? 1: 0);
  6851. }
  6852. else
  6853. {
  6854. tempIndex = gun_index;
  6855. }
  6856. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6857. {
  6858. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6859. {
  6860. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6861. }
  6862. } // END OF FOR CHAdeMO_QUANTITY
  6863. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6864. }
  6865. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6866. {
  6867. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6868. {
  6869. tempIndex = ((gun_index==2) ? 1: 0);
  6870. }
  6871. else
  6872. {
  6873. tempIndex = gun_index;
  6874. }
  6875. for (int index = 0; index < CCS_QUANTITY; index++)
  6876. {
  6877. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6878. {
  6879. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6880. }
  6881. } // END OF CCS_QUANTITY
  6882. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6883. }
  6884. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6885. {
  6886. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6887. {
  6888. tempIndex = ((gun_index==2) ? 1: 0);
  6889. }
  6890. else
  6891. {
  6892. tempIndex = gun_index;
  6893. }
  6894. for (int index = 0; index < GB_QUANTITY; index++)
  6895. {
  6896. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6897. {
  6898. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6899. }
  6900. } // END OF GB_QUANTITY
  6901. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6902. }
  6903. else if(gunType[gun_index] == GUN_TYPE_DO)
  6904. {
  6905. tempIndex = gun_index;
  6906. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6907. {
  6908. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6909. {
  6910. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6911. }
  6912. }
  6913. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6914. }
  6915. else
  6916. {
  6917. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6918. {
  6919. tempIndex = 2;
  6920. }
  6921. else
  6922. {
  6923. tempIndex = gun_index;
  6924. }
  6925. for (int index = 0; index < AC_QUANTITY; index++)
  6926. {
  6927. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6928. {
  6929. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6930. }
  6931. }
  6932. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6933. }
  6934. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6935. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6936. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6937. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6938. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6939. }
  6940. //********************************(4)Power.Active.Import************************************************/
  6941. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6942. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6943. (dataType == ReadingContext_Trigger))
  6944. {
  6945. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6946. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6947. {
  6948. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6949. {
  6950. tempIndex = ((gun_index==2) ? 1: 0);
  6951. }
  6952. else
  6953. {
  6954. tempIndex = gun_index;
  6955. }
  6956. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6957. {
  6958. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6959. {
  6960. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6961. }
  6962. } // END OF FOR
  6963. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6964. }
  6965. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6966. {
  6967. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6968. {
  6969. tempIndex = ((gun_index==2) ? 1: 0);
  6970. }
  6971. else
  6972. {
  6973. tempIndex = gun_index;
  6974. }
  6975. for (int index = 0; index < CCS_QUANTITY; index++)
  6976. {
  6977. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6978. {
  6979. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6980. }
  6981. }
  6982. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6983. }
  6984. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6985. {
  6986. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6987. {
  6988. tempIndex = ((gun_index==2) ? 1: 0);
  6989. }
  6990. else
  6991. {
  6992. tempIndex = gun_index;
  6993. }
  6994. for (int index = 0; index < GB_QUANTITY; index++)
  6995. {
  6996. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6997. {
  6998. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6999. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  7000. }
  7001. }
  7002. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7003. }
  7004. else if(gunType[gun_index] == GUN_TYPE_DO)
  7005. {
  7006. tempIndex = gun_index;
  7007. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7008. {
  7009. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7010. {
  7011. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7012. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  7013. }
  7014. }
  7015. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7016. }
  7017. else
  7018. {
  7019. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7020. {
  7021. tempIndex = 2;
  7022. }
  7023. else
  7024. {
  7025. tempIndex = gun_index;
  7026. }
  7027. for (int index = 0; index < AC_QUANTITY; index++)
  7028. {
  7029. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7030. {
  7031. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  7032. }
  7033. }
  7034. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  7035. }
  7036. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  7037. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  7038. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  7039. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  7040. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  7041. }
  7042. //***********************************************(5)VOLTAGE L1******************************************************/
  7043. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7044. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7045. (dataType == ReadingContext_Trigger))
  7046. {
  7047. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7048. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7049. {
  7050. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7051. {
  7052. tempIndex = ((gun_index==2) ? 1: 0);
  7053. }
  7054. else
  7055. {
  7056. tempIndex = gun_index;
  7057. }
  7058. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7059. {
  7060. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7061. {
  7062. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  7063. }
  7064. }
  7065. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7066. }
  7067. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7068. {
  7069. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7070. {
  7071. tempIndex = ((gun_index==2) ? 1: 0);
  7072. }
  7073. else
  7074. {
  7075. tempIndex = gun_index;
  7076. }
  7077. for (int index = 0; index < CCS_QUANTITY; index++)
  7078. {
  7079. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7080. {
  7081. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  7082. }
  7083. }
  7084. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7085. }
  7086. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7087. {
  7088. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7089. {
  7090. tempIndex = ((gun_index==2) ? 1: 0);
  7091. }
  7092. else
  7093. {
  7094. tempIndex = gun_index;
  7095. }
  7096. for (int index = 0; index < GB_QUANTITY; index++)
  7097. {
  7098. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7099. {
  7100. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  7101. }
  7102. }
  7103. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7104. }
  7105. else if(gunType[gun_index] == GUN_TYPE_DO)
  7106. {
  7107. tempIndex = gun_index;
  7108. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7109. {
  7110. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7111. {
  7112. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  7113. }
  7114. }
  7115. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7116. }
  7117. else
  7118. {
  7119. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7120. {
  7121. tempIndex = 2;
  7122. }
  7123. else
  7124. {
  7125. tempIndex = gun_index;
  7126. }
  7127. for (int index = 0; index < AC_QUANTITY; index++)
  7128. {
  7129. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7130. {
  7131. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  7132. }
  7133. }
  7134. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  7135. }
  7136. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  7137. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  7138. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  7139. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  7140. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7141. }
  7142. //***********************************************(6)SOC******************************************************/
  7143. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7144. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7145. (dataType == ReadingContext_Trigger))
  7146. {
  7147. 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))
  7148. {
  7149. //idx_sample=5;
  7150. //sampledValue = NULL;
  7151. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7152. {
  7153. tempIndex = ((gun_index==2) ? 1: 0);
  7154. }
  7155. else
  7156. {
  7157. tempIndex = gun_index;
  7158. }
  7159. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7160. {
  7161. //tempIndex = ((gun_index==2) ? 1: 0);
  7162. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7163. {
  7164. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7165. {
  7166. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  7167. }
  7168. }
  7169. }
  7170. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7171. {
  7172. //tempIndex = ((gun_index==2) ? 1: 0);
  7173. for (int index = 0; index < CCS_QUANTITY; index++)
  7174. {
  7175. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7176. {
  7177. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  7178. }
  7179. }
  7180. }
  7181. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7182. {
  7183. //tempIndex = ((gun_index==2) ? 1: 0);
  7184. for (int index = 0; index < GB_QUANTITY; index++)
  7185. {
  7186. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7187. {
  7188. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  7189. }
  7190. }
  7191. }
  7192. else if(gunType[gun_index] == GUN_TYPE_DO)
  7193. {
  7194. //tempIndex = ((gun_index==2) ? 1: 0);
  7195. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7196. {
  7197. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7198. {
  7199. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  7200. }
  7201. }
  7202. }
  7203. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  7204. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  7205. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  7206. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  7207. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  7208. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  7209. }
  7210. }
  7211. //********************************(7)Current.Import L2************************************************/
  7212. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7213. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7214. (dataType == ReadingContext_Trigger))
  7215. {
  7216. // Only for AC 3 phase
  7217. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7218. {
  7219. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7220. {
  7221. tempIndex = 2;
  7222. }
  7223. else
  7224. {
  7225. tempIndex = gun_index;
  7226. }
  7227. for (int index = 0; index < AC_QUANTITY; index++)
  7228. {
  7229. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7230. {
  7231. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7232. }
  7233. }
  7234. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7235. }
  7236. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7237. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7238. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7239. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7240. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7241. }
  7242. //********************************(8)Current.Import L3************************************************/
  7243. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7244. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7245. (dataType == ReadingContext_Trigger))
  7246. {
  7247. // Only for AC 3 phase
  7248. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7249. {
  7250. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7251. {
  7252. tempIndex = 2;
  7253. }
  7254. else
  7255. {
  7256. tempIndex = gun_index;
  7257. }
  7258. for (int index = 0; index < AC_QUANTITY; index++)
  7259. {
  7260. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7261. {
  7262. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7263. }
  7264. }
  7265. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7266. }
  7267. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7268. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7269. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7270. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7271. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7272. }
  7273. //***********************************************(9)VOLTAGE L2******************************************************/
  7274. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7275. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7276. (dataType == ReadingContext_Trigger))
  7277. {
  7278. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7279. {
  7280. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7281. {
  7282. tempIndex = 2;
  7283. }
  7284. else
  7285. {
  7286. tempIndex = gun_index;
  7287. }
  7288. for (int index = 0; index < AC_QUANTITY; index++)
  7289. {
  7290. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7291. {
  7292. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7293. }
  7294. }
  7295. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7296. }
  7297. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7298. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7299. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7300. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7301. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7302. }
  7303. //***********************************************(10)VOLTAGE L3******************************************************/
  7304. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7305. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7306. (dataType == ReadingContext_Trigger))
  7307. {
  7308. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7309. {
  7310. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7311. {
  7312. tempIndex = 2;
  7313. }
  7314. else
  7315. {
  7316. tempIndex = gun_index;
  7317. }
  7318. for (int index = 0; index < AC_QUANTITY; index++)
  7319. {
  7320. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7321. {
  7322. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7323. }
  7324. }
  7325. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7326. }
  7327. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7328. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7329. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7330. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7331. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7332. }
  7333. //***********************************************(11)Current.Offered******************************************************/
  7334. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7335. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7336. (dataType == ReadingContext_Trigger))
  7337. {
  7338. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7339. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7340. {
  7341. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7342. {
  7343. tempIndex = ((gun_index==2) ? 1: 0);
  7344. }
  7345. else
  7346. {
  7347. tempIndex = gun_index;
  7348. }
  7349. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7350. {
  7351. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7352. {
  7353. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7354. }
  7355. } // END OF FOR CHAdeMO_QUANTITY
  7356. }
  7357. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7358. {
  7359. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7360. {
  7361. tempIndex = ((gun_index==2) ? 1: 0);
  7362. }
  7363. else
  7364. {
  7365. tempIndex = gun_index;
  7366. }
  7367. for (int index = 0; index < CCS_QUANTITY; index++)
  7368. {
  7369. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7370. {
  7371. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7372. }
  7373. } // END OF CCS_QUANTITY
  7374. }
  7375. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7376. {
  7377. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7378. {
  7379. tempIndex = ((gun_index==2) ? 1: 0);
  7380. }
  7381. else
  7382. {
  7383. tempIndex = gun_index;
  7384. }
  7385. for (int index = 0; index < GB_QUANTITY; index++)
  7386. {
  7387. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7388. {
  7389. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7390. }
  7391. } // END OF GB_QUANTITY
  7392. }
  7393. else if(gunType[gun_index] == GUN_TYPE_DO)
  7394. {
  7395. tempIndex = gun_index;
  7396. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7397. {
  7398. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7399. {
  7400. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7401. }
  7402. }
  7403. }
  7404. else
  7405. {
  7406. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7407. {
  7408. tempIndex = 2;
  7409. }
  7410. else
  7411. {
  7412. tempIndex = gun_index;
  7413. }
  7414. for (int index = 0; index < AC_QUANTITY; index++)
  7415. {
  7416. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7417. {
  7418. uint16_t currentOffer;
  7419. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7420. {
  7421. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7422. }
  7423. else
  7424. {
  7425. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7426. }
  7427. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7428. }
  7429. }
  7430. }
  7431. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7432. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7433. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7434. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7435. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7436. }
  7437. //***********************************************(12)Power.Offered******************************************************/
  7438. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7439. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7440. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7441. {
  7442. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7443. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7444. {
  7445. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7446. {
  7447. tempIndex = ((gun_index==2) ? 1: 0);
  7448. }
  7449. else
  7450. {
  7451. tempIndex = gun_index;
  7452. }
  7453. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7454. {
  7455. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7456. {
  7457. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7458. }
  7459. } // END OF FOR CHAdeMO_QUANTITY
  7460. }
  7461. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7462. {
  7463. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7464. {
  7465. tempIndex = ((gun_index==2) ? 1: 0);
  7466. }
  7467. else
  7468. {
  7469. tempIndex = gun_index;
  7470. }
  7471. for (int index = 0; index < CCS_QUANTITY; index++)
  7472. {
  7473. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7474. {
  7475. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7476. }
  7477. } // END OF CCS_QUANTITY
  7478. }
  7479. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7480. {
  7481. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7482. {
  7483. tempIndex = ((gun_index==2) ? 1: 0);
  7484. }
  7485. else
  7486. {
  7487. tempIndex = gun_index;
  7488. }
  7489. for (int index = 0; index < GB_QUANTITY; index++)
  7490. {
  7491. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7492. {
  7493. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7494. }
  7495. } // END OF GB_QUANTITY
  7496. }
  7497. else if(gunType[gun_index] == GUN_TYPE_DO)
  7498. {
  7499. tempIndex = gun_index;
  7500. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7501. {
  7502. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7503. {
  7504. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7505. }
  7506. }
  7507. }
  7508. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7509. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7510. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7511. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7512. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7513. }
  7514. // Message create ====================================================================================================
  7515. if(TRUE)
  7516. {
  7517. json_object *MeterValueReq = json_object_new_object();
  7518. json_object *MeterValues = json_object_new_array();
  7519. json_object *sampledValues = json_object_new_array();
  7520. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7521. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7522. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7523. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7524. {
  7525. json_object *MeterValue = json_object_new_object();
  7526. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7527. {
  7528. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7529. {
  7530. json_object *sampledValue = json_object_new_object();
  7531. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7532. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7533. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7534. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7535. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7536. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7537. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7538. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7539. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7540. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7541. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7542. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7543. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7544. json_object_array_add(sampledValues, sampledValue);
  7545. }
  7546. }
  7547. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7548. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7549. json_object_array_add(MeterValues, MeterValue);
  7550. }
  7551. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7552. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7553. ,gun_index + 1
  7554. ,MESSAGE_TYPE_CALL
  7555. ,guid
  7556. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7557. json_object_put(MeterValueReq);
  7558. }
  7559. // Put request guid to hash map
  7560. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7561. 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*/)
  7562. {
  7563. result = PASS;
  7564. //DEBUG_INFO("MeterValues mapitem pass\n");
  7565. }
  7566. if((dataType != ReadingContext_Trigger) &&
  7567. (dataType != ReadingContext_Sample_Clock) &&
  7568. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7569. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7570. else
  7571. {
  7572. if(FirstHeartBeat)
  7573. LWS_Send(queuedata +2);
  7574. }
  7575. return result;
  7576. }
  7577. int sendLogStatusNotificationRequest(char *status)
  7578. {
  7579. mtrace();
  7580. int result = PASS;
  7581. char message[4096]={0};
  7582. char guid[37]={0};
  7583. char tempdata[128]={0};
  7584. json_object *LogStatusNotification = json_object_new_object();
  7585. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7586. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7587. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7588. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7589. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7590. random_uuid(guid);
  7591. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7592. json_object_put(LogStatusNotification);
  7593. LWS_Send(message);
  7594. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7595. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7596. {
  7597. result = PASS;
  7598. }
  7599. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7600. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7601. return result;
  7602. }
  7603. int sendSecurityEventNotificationRequest()
  7604. {
  7605. mtrace();
  7606. int result = PASS;
  7607. char message[4096]={0};
  7608. char guid[37]={0};
  7609. char tempdata[128]={0};
  7610. json_object *SecurityEventNotification = json_object_new_object();
  7611. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7612. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7613. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7614. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7615. random_uuid(guid);
  7616. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7617. json_object_put(SecurityEventNotification);
  7618. LWS_Send(message);
  7619. sprintf(tempdata, "SecurityEventNotification,0");
  7620. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7621. {
  7622. result = PASS;
  7623. }
  7624. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7625. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7626. return result;
  7627. }
  7628. int sendSignCertificateRequest()
  7629. {
  7630. mtrace();
  7631. int result = PASS;
  7632. char message[4096]={0};
  7633. char guid[37]={0};
  7634. char tempdata[128]={0};
  7635. json_object *SignCertificate = json_object_new_object();
  7636. DEBUG_INFO("sendSignCertificateRequest...\n");
  7637. // Read csr file content
  7638. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7639. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  7640. char *line = NULL;
  7641. size_t len = 0;
  7642. while(getline(&line, &len, fp) != -1)
  7643. {
  7644. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7645. {
  7646. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7647. }
  7648. }
  7649. fclose(fp);
  7650. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7651. random_uuid(guid);
  7652. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7653. json_object_put(SignCertificate);
  7654. LWS_Send(message);
  7655. sprintf(tempdata, "SignCertificate,0");
  7656. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7657. {
  7658. result = PASS;
  7659. }
  7660. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7661. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7662. return result;
  7663. }
  7664. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7665. {
  7666. mtrace();
  7667. int result = PASS;
  7668. char message[110]={0};
  7669. char guid[37]={0};
  7670. char tempdata[65]={0};
  7671. json_object *FirmwareStatusNotification = json_object_new_object();
  7672. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7673. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7674. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7675. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7676. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7677. random_uuid(guid);
  7678. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7679. json_object_put(FirmwareStatusNotification);
  7680. LWS_Send(message);
  7681. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7682. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7683. {
  7684. result = PASS;
  7685. }
  7686. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7687. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7688. return result;
  7689. }
  7690. //==========================================
  7691. // send confirm routine
  7692. //==========================================
  7693. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7694. {
  7695. mtrace();
  7696. int result = FAIL;
  7697. char message[100]={0};
  7698. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7699. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7700. LWS_Send(message);
  7701. result = TRUE;
  7702. return result;
  7703. }
  7704. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7705. {
  7706. mtrace();
  7707. int result = FAIL;
  7708. char message[100]={0};
  7709. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7710. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7711. LWS_Send(message);
  7712. result = TRUE;
  7713. return result;
  7714. }
  7715. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7716. {
  7717. mtrace();
  7718. int result = FAIL;
  7719. char message[100]={0};
  7720. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7721. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7722. LWS_Send(message);
  7723. result = TRUE;
  7724. return result;
  7725. }
  7726. int sendClearCacheConfirmation(char *uuid,char *payload)
  7727. {
  7728. mtrace();
  7729. int result = FAIL;
  7730. char message[500]={0};
  7731. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7732. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7733. LWS_Send(message);
  7734. return result;
  7735. }
  7736. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7737. {
  7738. mtrace();
  7739. int result = FAIL;
  7740. char message[500]={0};
  7741. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7742. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7743. LWS_Send(message);
  7744. return result;
  7745. }
  7746. int sendDataTransferConfirmation(char *uuid,char *payload)
  7747. {
  7748. mtrace();
  7749. char statusStr[20]={0};
  7750. char dataStr[10]={0};
  7751. char sstr[20]={0};
  7752. int c = 0;
  7753. char *loc;
  7754. int result = FAIL;
  7755. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7756. /**********************status**************************/
  7757. loc = strstr(payload, "status");
  7758. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7759. c = 0;
  7760. while (loc[3+strlen("status")+c] != '\"')
  7761. {
  7762. sstr[c] = loc[3+strlen("status")+c];
  7763. c++;
  7764. }
  7765. sstr[c] = '\0';
  7766. strcpy(statusStr, sstr);
  7767. /**********************data**************************/
  7768. loc = strstr(payload, "data");
  7769. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7770. c = 0;
  7771. while (loc[3+strlen("data")+c] != '\"')
  7772. {
  7773. sstr[c] = loc[3+strlen("data")+c];
  7774. c++;
  7775. }
  7776. sstr[c] = '\0';
  7777. strcpy(dataStr, sstr);
  7778. return result;
  7779. }
  7780. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7781. {
  7782. mtrace();
  7783. int result = FAIL;
  7784. char message[1000]={0};
  7785. int CompositeScheduleIndex = 0;
  7786. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7787. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7788. if(nPeriod == 0)
  7789. {
  7790. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7791. {
  7792. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7793. ,MESSAGE_TYPE_CALLRESULT
  7794. ,uuid
  7795. ,payload
  7796. ,connectorIdInt);
  7797. }
  7798. else
  7799. {
  7800. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7801. ,MESSAGE_TYPE_CALLRESULT
  7802. ,uuid
  7803. ,payload
  7804. ,connectorIdInt
  7805. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7806. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7807. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7808. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7809. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7810. }
  7811. }
  7812. else
  7813. {
  7814. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7815. ,MESSAGE_TYPE_CALLRESULT
  7816. ,uuid
  7817. ,payload
  7818. ,connectorIdInt
  7819. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7820. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7821. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7822. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7823. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7824. {
  7825. if (idx_sample == 0)
  7826. {
  7827. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7828. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7829. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7830. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7831. }
  7832. else
  7833. {
  7834. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7835. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7836. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7837. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7838. }
  7839. }
  7840. sprintf(message + strlen(message), "]}}]");
  7841. }
  7842. LWS_Send(message);
  7843. result = TRUE;
  7844. return result;
  7845. }
  7846. int sendGetConfigurationConfirmation(char *uuid)
  7847. {
  7848. mtrace();
  7849. int result = FAIL;
  7850. int MaxKeySupported = 0;
  7851. int sentConfigurationNumber= 0;
  7852. int sentunConfigurationNumber= 0;
  7853. char message[1024*10]={0};
  7854. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7855. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7856. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7857. ,MESSAGE_TYPE_CALLRESULT
  7858. ,uuid );
  7859. //configuration key
  7860. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7861. {
  7862. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7863. {
  7864. if (sentConfigurationNumber == 0)
  7865. {
  7866. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7867. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7868. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7869. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7870. }
  7871. else
  7872. {
  7873. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7874. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7875. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7876. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7877. }
  7878. sentConfigurationNumber = sentConfigurationNumber + 1;
  7879. }
  7880. }
  7881. sprintf(message + strlen(message), "]");
  7882. if(UnknownKeynum != 0)
  7883. {
  7884. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7885. //unkown key
  7886. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7887. {
  7888. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7889. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7890. if(sentunConfigurationNumber == 0)
  7891. {
  7892. sprintf(message + strlen(message), "\"%s\""
  7893. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7894. }
  7895. else
  7896. {
  7897. sprintf(message + strlen(message), ",\"%s\""
  7898. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7899. }
  7900. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7901. }
  7902. sprintf(message + strlen(message), "]");
  7903. }
  7904. sprintf(message + strlen(message), "}]");
  7905. LWS_Send(message);
  7906. return result;
  7907. }
  7908. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7909. {
  7910. mtrace();
  7911. int result = FAIL;
  7912. char message[400]={0};
  7913. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7914. if(strcmp(payload,"")==0)
  7915. {
  7916. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7917. }
  7918. else
  7919. {
  7920. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7921. }
  7922. LWS_Send(message);
  7923. result = TRUE;
  7924. return result;
  7925. }
  7926. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7927. {
  7928. mtrace();
  7929. int result = FAIL;
  7930. char message[80]={0};
  7931. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7932. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  7933. LWS_Send(message);
  7934. result = TRUE;
  7935. return result;
  7936. }
  7937. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7938. {
  7939. mtrace();
  7940. int result = FAIL;
  7941. char message[80]={0};
  7942. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7943. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7944. LWS_Send(message);
  7945. result = TRUE;
  7946. return result;
  7947. }
  7948. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7949. {
  7950. mtrace();
  7951. int result = FAIL;
  7952. char message[80]={0};
  7953. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7954. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7955. LWS_Send(message);
  7956. result = TRUE;
  7957. return result;
  7958. }
  7959. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7960. {
  7961. mtrace();
  7962. int result = FAIL;
  7963. char message[80]={0};
  7964. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7965. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7966. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7967. LWS_Send(message);
  7968. result = TRUE;
  7969. return result;
  7970. }
  7971. int sendResetConfirmation(char *uuid,char *payload)
  7972. {
  7973. mtrace();
  7974. int result = FAIL;
  7975. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7976. char message[80]={0};
  7977. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  7978. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7979. LWS_Send(message);
  7980. result = TRUE;
  7981. return result;
  7982. }
  7983. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7984. {
  7985. mtrace();
  7986. int result = FAIL;
  7987. char message[500]={0};
  7988. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7989. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7990. LWS_Send(message);
  7991. result = TRUE;
  7992. return result;
  7993. }
  7994. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7995. {
  7996. mtrace();
  7997. int result = FAIL;
  7998. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7999. char message[80]={0};
  8000. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  8001. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8002. LWS_Send(message);
  8003. result = TRUE;
  8004. return result;
  8005. }
  8006. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  8007. {
  8008. mtrace();
  8009. int result = FAIL;
  8010. char message[80]={0};
  8011. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  8012. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8013. LWS_Send(message);
  8014. result = TRUE;
  8015. return result;
  8016. }
  8017. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  8018. {
  8019. mtrace();
  8020. int result = FAIL;
  8021. char message[80]={0};
  8022. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8023. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  8024. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8025. LWS_Send(message);
  8026. result = TRUE;
  8027. return result;
  8028. }
  8029. int sendUpdateFirmwareConfirmation(char *uuid)
  8030. {
  8031. mtrace();
  8032. int result = FAIL;
  8033. char message[60]={0};
  8034. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8035. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  8036. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8037. LWS_Send(message);
  8038. result = TRUE;
  8039. return result;
  8040. }
  8041. int sendCertificateSignedConfirmation(char *uuid)
  8042. {
  8043. mtrace();
  8044. int result = PASS;
  8045. char message[4096]={0};
  8046. json_object *CertificateSigned = json_object_new_object();
  8047. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  8048. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  8049. sprintf(message,"[%d,\"%s\",%s]"
  8050. ,MESSAGE_TYPE_CALLRESULT
  8051. ,uuid
  8052. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  8053. json_object_put(CertificateSigned);
  8054. LWS_Send(message);
  8055. return result;
  8056. }
  8057. int sendDeleteCertificateConfirmation(char *uuid)
  8058. {
  8059. mtrace();
  8060. int result = PASS;
  8061. char message[4096]={0};
  8062. json_object *DeleteCertificate = json_object_new_object();
  8063. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  8064. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  8065. sprintf(message,"[%d,\"%s\",%s]"
  8066. ,MESSAGE_TYPE_CALLRESULT
  8067. ,uuid
  8068. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  8069. json_object_put(DeleteCertificate);
  8070. LWS_Send(message);
  8071. return result;
  8072. }
  8073. int sendExtendedTriggerMessageConfirmation(char *uuid)
  8074. {
  8075. mtrace();
  8076. int result = PASS;
  8077. char message[4096]={0};
  8078. json_object *ExtendedTriggerMessage = json_object_new_object();
  8079. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  8080. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  8081. sprintf(message,"[%d,\"%s\",%s]"
  8082. ,MESSAGE_TYPE_CALLRESULT
  8083. ,uuid
  8084. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  8085. json_object_put(ExtendedTriggerMessage);
  8086. LWS_Send(message);
  8087. return result;
  8088. }
  8089. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  8090. {
  8091. mtrace();
  8092. int result = PASS;
  8093. char message[4096]={0};
  8094. json_object *GetInstalledCertificateIds = json_object_new_object();
  8095. json_object *certificateHashDataDatas = json_object_new_array();
  8096. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  8097. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  8098. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  8099. {
  8100. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  8101. {
  8102. json_object *certificateHashData = json_object_new_object();
  8103. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  8104. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  8105. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  8106. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  8107. json_object_array_add(certificateHashDataDatas, certificateHashData);
  8108. }
  8109. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  8110. }
  8111. else
  8112. {
  8113. json_object_put(certificateHashDataDatas);
  8114. }
  8115. sprintf(message,"[%d,\"%s\",%s]"
  8116. ,MESSAGE_TYPE_CALLRESULT
  8117. ,uuid
  8118. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  8119. json_object_put(GetInstalledCertificateIds);
  8120. LWS_Send(message);
  8121. return result;
  8122. }
  8123. int sendGetLogConfirmation(char *uuid)
  8124. {
  8125. mtrace();
  8126. int result = PASS;
  8127. char message[4096]={0};
  8128. json_object *GetLog = json_object_new_object();
  8129. DEBUG_INFO("sendGetLogConfirmation...\n");
  8130. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  8131. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  8132. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  8133. sprintf(message,"[%d,\"%s\",%s]"
  8134. ,MESSAGE_TYPE_CALLRESULT
  8135. ,uuid
  8136. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  8137. json_object_put(GetLog);
  8138. LWS_Send(message);
  8139. return result;
  8140. }
  8141. int sendInstallCertificateConfirmation(char *uuid)
  8142. {
  8143. mtrace();
  8144. int result = PASS;
  8145. char message[4096]={0};
  8146. json_object *InstallCertificate = json_object_new_object();
  8147. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  8148. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  8149. sprintf(message,"[%d,\"%s\",%s]"
  8150. ,MESSAGE_TYPE_CALLRESULT
  8151. ,uuid
  8152. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  8153. json_object_put(InstallCertificate);
  8154. LWS_Send(message);
  8155. return result;
  8156. }
  8157. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  8158. {
  8159. mtrace();
  8160. int result = PASS;
  8161. char message[4096]={0};
  8162. json_object *SignedUpdateFirmware = json_object_new_object();
  8163. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  8164. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  8165. sprintf(message,"[%d,\"%s\",%s]"
  8166. ,MESSAGE_TYPE_CALLRESULT
  8167. ,uuid
  8168. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  8169. json_object_put(SignedUpdateFirmware);
  8170. LWS_Send(message);
  8171. return result;
  8172. }
  8173. int sendUnknownConfirmation(char *uuid)
  8174. {
  8175. mtrace();
  8176. int result = PASS;
  8177. char message[256]={0};
  8178. DEBUG_INFO("sendUnknownConfirmation...\n");
  8179. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  8180. LWS_Send(message);
  8181. return result;
  8182. }
  8183. //==========================================
  8184. // Handle server request routine Start
  8185. //==========================================
  8186. int handleCancelReservationRequest(char *uuid, char *payload)
  8187. {
  8188. mtrace();
  8189. int result = FAIL;
  8190. int gunNO = 0;
  8191. int reservationIdInt = -1;
  8192. char comfirmstr[20];
  8193. DEBUG_INFO("handleCancelReservationRequest...\n");
  8194. json_object *CancelReservation;
  8195. CancelReservation = json_tokener_parse(payload);
  8196. if(!is_error(CancelReservation))
  8197. {
  8198. // Required data
  8199. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  8200. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  8201. }
  8202. json_object_put(CancelReservation);
  8203. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  8204. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8205. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  8206. if(reservationIdInt != -1)
  8207. {
  8208. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8209. //check Transaction active
  8210. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8211. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8212. {
  8213. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  8214. {
  8215. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8216. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8217. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8218. {
  8219. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8220. }
  8221. else
  8222. {
  8223. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8224. }
  8225. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8226. goto end;
  8227. }
  8228. }
  8229. for (int index = 0; index < CCS_QUANTITY; index++)
  8230. {
  8231. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8232. {
  8233. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8234. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8235. if(gunType[2] == GUN_TYPE_CCS)
  8236. {
  8237. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8238. }
  8239. else
  8240. {
  8241. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8242. }
  8243. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8244. goto end;
  8245. }
  8246. }
  8247. for (int index = 0; index < GB_QUANTITY; index++)
  8248. {
  8249. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8250. {
  8251. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8252. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8253. if(gunType[2] == GUN_TYPE_GBT)
  8254. {
  8255. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8256. }
  8257. else
  8258. {
  8259. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8260. }
  8261. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8262. goto end;
  8263. }
  8264. }
  8265. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8266. {
  8267. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8268. {
  8269. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8270. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8271. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8272. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8273. goto end;
  8274. }
  8275. }
  8276. for (int index = 0; index < AC_QUANTITY; index++)
  8277. {
  8278. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8279. {
  8280. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8281. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8282. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8283. {
  8284. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8285. }
  8286. else
  8287. {
  8288. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8289. }
  8290. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8291. goto end;
  8292. }
  8293. }
  8294. }
  8295. //The reservationId does NOT match the reservationId
  8296. sendCancelReservationConfirmation(uuid, comfirmstr);
  8297. end:
  8298. // Fill in ocpp packet uuid
  8299. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  8300. return result;
  8301. }
  8302. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8303. {
  8304. mtrace();
  8305. int result = FAIL;
  8306. int gunIndex = -1;
  8307. char typeStr[16]={0};
  8308. char comfirmstr[20];
  8309. int specificId = FALSE;
  8310. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8311. json_object *ChangeAvailability;
  8312. ChangeAvailability = json_tokener_parse(payload);
  8313. if(!is_error(ChangeAvailability))
  8314. {
  8315. // Required data
  8316. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8317. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8318. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8319. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8320. }
  8321. json_object_put(ChangeAvailability);
  8322. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8323. {
  8324. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8325. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8326. }
  8327. else if(gunIndex == 0)
  8328. {
  8329. for(int i=0; i < gunTotalNumber; i++)
  8330. {
  8331. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8332. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8333. }
  8334. }
  8335. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8336. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8337. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8338. {
  8339. specificId = TRUE;
  8340. }
  8341. if(specificId == FALSE)
  8342. goto end;
  8343. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8344. {
  8345. //----------------------gunIndex is 0 ------------------------------------------------//
  8346. if(gunIndex == 0)
  8347. {
  8348. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8349. {
  8350. for(int i=0; i < gunTotalNumber; i++)
  8351. {
  8352. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8353. {
  8354. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8355. {
  8356. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8357. {
  8358. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8359. goto end;
  8360. }
  8361. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8362. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8363. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8364. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8365. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8366. {
  8367. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8368. goto end;
  8369. }
  8370. }
  8371. }//END FOR CHAdeMO_QUANTITY
  8372. for (int index = 0; index < CCS_QUANTITY; index++)
  8373. {
  8374. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8375. {
  8376. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8377. {
  8378. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8379. goto end;
  8380. }
  8381. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8382. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8383. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8384. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8385. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8386. {
  8387. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8388. goto end;
  8389. }
  8390. }
  8391. }//END FOR CCS_QUANTITY
  8392. for (int index = 0; index < GB_QUANTITY; index++)
  8393. {
  8394. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8395. {
  8396. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8397. {
  8398. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8399. goto end;
  8400. }
  8401. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8402. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8403. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8404. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8405. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8406. {
  8407. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8408. goto end;
  8409. }
  8410. }
  8411. }// END FOR GB_QUANTITY
  8412. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8413. {
  8414. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8415. {
  8416. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8417. {
  8418. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8419. goto end;
  8420. }
  8421. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8422. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8423. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8424. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8425. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8426. {
  8427. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8428. goto end;
  8429. }
  8430. }
  8431. }// END FOR GENERAL_GUN_QUANTITY
  8432. for (int index = 0; index < AC_QUANTITY; index++)
  8433. {
  8434. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8435. {
  8436. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8437. {
  8438. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8439. goto end;
  8440. }
  8441. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8442. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8443. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8444. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8445. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8446. {
  8447. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8448. goto end;
  8449. }
  8450. }
  8451. }//END FOR AC_QUANTITY
  8452. }// END FOR gunTotalNumber
  8453. }
  8454. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8455. {
  8456. for(int i=0; i < gunTotalNumber; i++)
  8457. {
  8458. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8459. {
  8460. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8461. goto end;
  8462. }
  8463. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8464. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8465. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8466. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8467. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8468. {
  8469. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8470. goto end;
  8471. }
  8472. }
  8473. }
  8474. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8475. goto end;
  8476. }
  8477. //----------------------gunIndex is not 0 ------------------------------------------------//
  8478. //check Transaction active
  8479. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8480. {
  8481. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8482. {
  8483. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8484. {
  8485. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8486. goto end;
  8487. }
  8488. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8489. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8490. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8491. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8492. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8493. {
  8494. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8495. goto end;
  8496. }
  8497. else
  8498. {
  8499. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8500. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8501. goto end;
  8502. }
  8503. }
  8504. }//END FOR CHAdeMO_QUANTITY
  8505. for (int index = 0; index < CCS_QUANTITY; index++)
  8506. {
  8507. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8508. {
  8509. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8510. {
  8511. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8512. goto end;
  8513. }
  8514. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8515. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8516. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8517. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8518. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8519. {
  8520. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8521. goto end;
  8522. }
  8523. else
  8524. {
  8525. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8526. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8527. goto end;
  8528. }
  8529. }
  8530. }//END FOR CCS_QUANTITY
  8531. for (int index = 0; index < GB_QUANTITY; index++)
  8532. {
  8533. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8534. {
  8535. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8536. {
  8537. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8538. goto end;
  8539. }
  8540. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8541. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8542. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8543. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8544. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8545. {
  8546. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8547. goto end;
  8548. }
  8549. else
  8550. {
  8551. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8552. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8553. goto end;
  8554. }
  8555. }
  8556. }// END FOR GB_QUANTITY
  8557. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8558. {
  8559. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8560. {
  8561. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8562. {
  8563. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8564. goto end;
  8565. }
  8566. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8567. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8568. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8569. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8570. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8571. {
  8572. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8573. goto end;
  8574. }
  8575. else
  8576. {
  8577. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8578. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8579. goto end;
  8580. }
  8581. }
  8582. }// END FOR GENERAL_GUN_QUANTITY
  8583. for (int index = 0; index < AC_QUANTITY; index++)
  8584. {
  8585. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8586. {
  8587. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8588. {
  8589. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8590. goto end;
  8591. }
  8592. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8593. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8594. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8595. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8596. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8597. {
  8598. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8599. goto end;
  8600. }
  8601. else
  8602. {
  8603. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8604. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8605. goto end;
  8606. }
  8607. }
  8608. }//END FOR AC_QUANTITY
  8609. }//END FOR AvailabilityTypeStr[Inoperative]
  8610. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8611. {
  8612. //----------------------gunIndex is 0 ------------------------------------------------//
  8613. if(gunIndex == 0)
  8614. {
  8615. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8616. {
  8617. for(int i=0; i < gunTotalNumber; i++)
  8618. {
  8619. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8620. {
  8621. 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
  8622. {
  8623. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8624. goto end;
  8625. }
  8626. }//END FOR CHAdeMO_QUANTITY
  8627. for (int index = 0; index < CCS_QUANTITY; index++)
  8628. {
  8629. 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
  8630. {
  8631. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8632. goto end;
  8633. }
  8634. }//END FOR CCS_QUANTITY
  8635. for (int index = 0; index < GB_QUANTITY; index++)
  8636. {
  8637. 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
  8638. {
  8639. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8640. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8641. goto end;
  8642. }
  8643. }// END FOR GB_QUANTITY
  8644. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8645. {
  8646. 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
  8647. {
  8648. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8649. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8650. goto end;
  8651. }
  8652. }// END FOR GENERAL_GUN_QUANTITY
  8653. for (int index = 0; index < AC_QUANTITY; index++)
  8654. {
  8655. 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
  8656. {
  8657. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8658. goto end;
  8659. }
  8660. }//END FOR CHAdeMO_QUANTITY
  8661. }// END FOR gunTotalNumber
  8662. }
  8663. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8664. {
  8665. for(int i=0; i < gunTotalNumber; i++)
  8666. {
  8667. for (int index = 0; index < AC_QUANTITY; index++)
  8668. {
  8669. 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
  8670. {
  8671. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8672. goto end;
  8673. }
  8674. }//END FOR CHAdeMO_QUANTITY
  8675. } // END FOR gunTotalNumber
  8676. }
  8677. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8678. goto end;
  8679. }
  8680. //----------------------gunIndex is not 0 ------------------------------------------------//
  8681. //check Transaction active
  8682. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8683. {
  8684. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8685. {
  8686. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8687. goto end;
  8688. }
  8689. }//END FOR CHAdeMO_QUANTITY
  8690. for (int index = 0; index < CCS_QUANTITY; index++)
  8691. {
  8692. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8693. {
  8694. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8695. goto end;
  8696. }
  8697. }//END FOR CCS_QUANTITY
  8698. for (int index = 0; index < GB_QUANTITY; index++)
  8699. {
  8700. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8701. {
  8702. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8703. goto end;
  8704. }
  8705. }// END FOR GB_QUANTITY
  8706. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8707. {
  8708. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8709. {
  8710. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8711. goto end;
  8712. }
  8713. }// END FOR GENERAL_GUN_QUANTITY
  8714. for (int index = 0; index < AC_QUANTITY; index++)
  8715. {
  8716. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8717. {
  8718. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8719. goto end;
  8720. }
  8721. }//END FOR AC_QUANTITY
  8722. }//END FOR AvailabilityTypeStr[Operative]
  8723. end:
  8724. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8725. {
  8726. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8727. }
  8728. else
  8729. {
  8730. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8731. }
  8732. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8733. {
  8734. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8735. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8736. }
  8737. else if(gunIndex == 0)
  8738. {
  8739. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8740. {
  8741. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8742. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8743. }
  8744. }
  8745. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8746. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8747. return result;
  8748. }
  8749. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8750. {
  8751. mtrace();
  8752. int valueInvalid = NO;
  8753. int result = FAIL;
  8754. char keystr[40]={0};
  8755. char valuestr[501]={0}; //value should be limited in 500 bytes
  8756. char comfirmstr[20]={0};
  8757. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8758. json_object *ChangeConfiguration;
  8759. ChangeConfiguration = json_tokener_parse(payload);
  8760. if(!is_error(ChangeConfiguration))
  8761. {
  8762. // Required data
  8763. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8764. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8765. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8766. {
  8767. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8768. }
  8769. else
  8770. {
  8771. valueInvalid = YES;
  8772. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8773. }
  8774. }
  8775. json_object_put(ChangeConfiguration);
  8776. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  8777. {
  8778. DEBUG_ERROR("Payload is null or value is invalid.\n");
  8779. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8780. }
  8781. else
  8782. {
  8783. int status = setKeyValue(keystr, valuestr);
  8784. switch(status)
  8785. {
  8786. case ConfigurationStatus_Accepted:
  8787. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8788. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  8789. StoreConfigurationTable();
  8790. break;
  8791. case RebootRequired:
  8792. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8793. StoreConfigurationTable();
  8794. break;
  8795. case NotSupported:
  8796. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8797. break;
  8798. case ConfigurationStatus_Rejected:
  8799. default:
  8800. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8801. break;
  8802. }
  8803. }
  8804. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8805. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  8806. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8807. {
  8808. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8809. SetOcppConnStatus(FALSE);
  8810. }
  8811. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8812. {
  8813. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8814. }
  8815. return result;
  8816. }
  8817. int handleClearCacheRequest(char *uuid, char *payload)
  8818. {
  8819. mtrace();
  8820. int result = FAIL;
  8821. char comfirmstr[20];
  8822. char rmFileCmd[100]={0};
  8823. struct stat stats;
  8824. DEBUG_INFO("handleClearCacheRequest...\n");
  8825. stat("/Storage/OCPP", &stats);
  8826. // Check for directory existence
  8827. if (S_ISDIR(stats.st_mode) == 1)
  8828. {}
  8829. else
  8830. {
  8831. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8832. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  8833. system(rmFileCmd);
  8834. }
  8835. if(OCPP_cleanLocalCache())
  8836. {
  8837. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8838. }
  8839. else
  8840. {
  8841. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8842. }
  8843. sendClearCacheConfirmation(uuid, comfirmstr);
  8844. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8845. return result;
  8846. }
  8847. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8848. {
  8849. mtrace();
  8850. int result = FAIL;
  8851. int resultRename;
  8852. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8853. char chargingProfilePurposeStr[26]={0};
  8854. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8855. char tempchargingProfilePurposeStr[26]={0};
  8856. char str[100]={0};
  8857. char fname[200]={0};
  8858. char comfirmstr[20]={0};
  8859. char word[1600]={0};
  8860. int clearflag = FALSE;
  8861. int chargingProfileIdIsNULL = FALSE;
  8862. int connectorIsNULL = FALSE;
  8863. int chargingProfilePurposeIsNULL = FALSE;
  8864. int stackLevelIsNULL = FALSE;
  8865. //int GotoEnd = FALSE;
  8866. FILE *fptr1, *fptr2;
  8867. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  8868. int n_chargingProfile=0;
  8869. int isEmptyFile = FALSE;
  8870. char sLineWord[1600]={0};
  8871. char chargingProfiles[10][100]={0};
  8872. int ChargeProfileCount = 0;
  8873. int ch;
  8874. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8875. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8876. json_object *ClearChargingProfile;
  8877. ClearChargingProfile = json_tokener_parse(payload);
  8878. if(!is_error(ClearChargingProfile))
  8879. {
  8880. // Optional data
  8881. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8882. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8883. else
  8884. chargingProfileIdIsNULL = TRUE;
  8885. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8886. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8887. else
  8888. connectorIsNULL = TRUE;
  8889. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8890. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8891. else
  8892. chargingProfilePurposeIsNULL = TRUE;
  8893. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8894. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8895. else
  8896. stackLevelIsNULL = TRUE;
  8897. }
  8898. json_object_put(ClearChargingProfile);
  8899. if(connectorIsNULL == FALSE)
  8900. {
  8901. switch(connectorIdInt)
  8902. {
  8903. case 0:
  8904. if(chargingProfilePurposeIsNULL == TRUE)
  8905. {
  8906. int l = 0;
  8907. strcpy(fname, ChargePointMaxProfile_JSON);
  8908. if((access(fname,F_OK))!=-1)
  8909. {
  8910. strcpy(chargingProfiles[l], fname);
  8911. l = l + 1;
  8912. }
  8913. strcpy(fname, TxDefaultProfile_0_JSON);
  8914. if((access(fname,F_OK))!=-1)
  8915. {
  8916. strcpy(chargingProfiles[l], fname);
  8917. l = l + 1;
  8918. }
  8919. ChargeProfileCount = l;
  8920. }
  8921. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8922. {
  8923. strcpy(fname, ChargePointMaxProfile_JSON);
  8924. if((access(fname,F_OK))!=-1)
  8925. {
  8926. strcpy(chargingProfiles[0], fname);
  8927. ChargeProfileCount = 1;
  8928. }
  8929. }
  8930. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8931. {
  8932. strcpy(fname, TxDefaultProfile_0_JSON);
  8933. if((access(fname,F_OK))!=-1)
  8934. {
  8935. strcpy(chargingProfiles[0], fname);
  8936. ChargeProfileCount = 1;
  8937. }
  8938. }
  8939. break;
  8940. default:
  8941. if(chargingProfilePurposeIsNULL == TRUE)
  8942. {
  8943. int m = 0;
  8944. memset(fname, 0, ARRAY_SIZE(fname));
  8945. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8946. if((access(fname,F_OK))!=-1)
  8947. {
  8948. strcpy(chargingProfiles[m], fname);
  8949. m = m + 1;
  8950. }
  8951. memset(fname, 0, ARRAY_SIZE(fname));
  8952. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8953. if((access(fname,F_OK))!=-1)
  8954. {
  8955. strcpy(chargingProfiles[m], fname);
  8956. m = m + 1;
  8957. }
  8958. ChargeProfileCount = m;
  8959. }
  8960. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8961. {
  8962. //strcpy(fname, TxDefaultProfile_1_JSON);
  8963. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8964. if((access(fname,F_OK))!=-1)
  8965. {
  8966. strcpy(chargingProfiles[0], fname);
  8967. ChargeProfileCount = 1;
  8968. }
  8969. }
  8970. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8971. {
  8972. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8973. if((access(fname,F_OK))!=-1)
  8974. {
  8975. strcpy(chargingProfiles[0], fname);
  8976. ChargeProfileCount = 1;
  8977. }
  8978. //strcpy(fname, TxProfile_1_JSON);
  8979. }
  8980. //strcpy(fname, ChargePointMaxProfile_JSON );
  8981. break;
  8982. }
  8983. }
  8984. else // Check all Charging Profiles
  8985. {
  8986. int i = 0;
  8987. char fnametemp[200]={0};
  8988. ChargeProfileCount = 0;
  8989. //Check ChargePointMaxProfile.json exit
  8990. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8991. {
  8992. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  8993. i = i + 1;
  8994. }
  8995. //Check TxDefaultProfile_0.json exit
  8996. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8997. {
  8998. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  8999. i = i + 1;
  9000. }
  9001. //Check TxDefaultProfile_%d.json
  9002. for(int j=1; j <= gunTotalNumber; j++)
  9003. {
  9004. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9005. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9006. if((access(fnametemp,F_OK))!=-1)
  9007. {
  9008. strcpy(chargingProfiles[i], fnametemp);
  9009. i = i + 1;
  9010. }
  9011. }
  9012. //Check TxProfile_%d.json
  9013. for(int j=1; j <= gunTotalNumber; j++)
  9014. {
  9015. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9016. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9017. if((access(fnametemp,F_OK))!=-1)
  9018. {
  9019. strcpy(chargingProfiles[i], fnametemp);
  9020. i = i + 1;
  9021. }
  9022. }
  9023. ChargeProfileCount = i;
  9024. }// End connectorIsNULL is TRUE
  9025. if(ChargeProfileCount == 0)
  9026. {
  9027. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9028. goto end;
  9029. }
  9030. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  9031. {
  9032. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9033. goto end;
  9034. }
  9035. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  9036. {
  9037. memset(str, 0, ARRAY_SIZE(str));
  9038. // clear temp file
  9039. sprintf(str,"rm -f %s",temp);
  9040. system(str);
  9041. for(int k=0; k < ChargeProfileCount; k++)
  9042. {
  9043. memset(str, 0, ARRAY_SIZE(str));
  9044. //clear file in C
  9045. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9046. system(str);
  9047. }
  9048. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9049. goto end;
  9050. }
  9051. else if(connectorIsNULL == TRUE)
  9052. {
  9053. for(int k=0; k < ChargeProfileCount; k++)
  9054. {
  9055. fptr1 = fopen(chargingProfiles[k], "r");
  9056. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  9057. //Check Charging Profile Count
  9058. while(fscanf(fptr1, "%s", word) != EOF)
  9059. {
  9060. //DEBUG_INFO("word=%s\n",word);
  9061. if(strstr(word, "chargingProfileId")!= NULL)
  9062. {
  9063. //DEBUG_INFO("test chargingProfileId \n");
  9064. n_chargingProfile = n_chargingProfile + 1;
  9065. //DEBUG_INFO("chargingProfileId Found\n");
  9066. }
  9067. }
  9068. rewind(fptr1);
  9069. //search Charging Profile Element
  9070. //int i= 0;
  9071. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9072. {
  9073. json_object *tmpProfilee;
  9074. tmpProfilee = json_tokener_parse(sLineWord);
  9075. if(!is_error(tmpProfilee))
  9076. {
  9077. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9078. {
  9079. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9080. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9081. }
  9082. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9083. {
  9084. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9085. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9086. }
  9087. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9088. {
  9089. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9090. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9091. }
  9092. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9093. {
  9094. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9095. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9096. }
  9097. }
  9098. json_object_put(tmpProfilee);
  9099. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9100. {
  9101. //------- not write to fptr2-------//
  9102. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9103. //clearflag = TRUE;
  9104. }
  9105. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9106. {
  9107. //------- not write to fptr2-------//
  9108. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9109. }
  9110. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9111. {
  9112. //------- not write to fptr2-------//
  9113. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9114. }
  9115. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  9116. {
  9117. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9118. }
  9119. else
  9120. {
  9121. fprintf(fptr2, sLineWord);//writing data into file
  9122. }
  9123. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9124. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9125. if(clearflag == TRUE)
  9126. {
  9127. fclose(fptr1);
  9128. fclose(fptr2);
  9129. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9130. system(str);
  9131. // clear temp file
  9132. sprintf(str,"rm -f %s",temp);
  9133. system(str);
  9134. }
  9135. else
  9136. {
  9137. fclose(fptr1);
  9138. fclose(fptr2);
  9139. memset(str, 0, ARRAY_SIZE(str));
  9140. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9141. system(str);
  9142. resultRename = rename(temp, chargingProfiles[k]);
  9143. if(resultRename == 0)
  9144. {
  9145. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  9146. }
  9147. else
  9148. {
  9149. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  9150. }
  9151. if(comfirmstr[0]== 0)
  9152. {
  9153. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9154. }
  9155. //Check chargingProfile is empty file
  9156. /*------ Read the file ----------------*/
  9157. fptr1=fopen(chargingProfiles[k],"r");
  9158. ch=fgetc(fptr1);
  9159. rewind(fptr1);
  9160. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9161. if(ch!=EOF)
  9162. {
  9163. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9164. {
  9165. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9166. if(sLineWord[0]=='\0')
  9167. {
  9168. isEmptyFile = TRUE;
  9169. break;
  9170. }
  9171. else
  9172. {
  9173. isEmptyFile = FALSE;
  9174. break;
  9175. }
  9176. }
  9177. }
  9178. else
  9179. isEmptyFile = TRUE;
  9180. fclose(fptr1);
  9181. if(isEmptyFile == TRUE)
  9182. {
  9183. memset(str, 0, ARRAY_SIZE(str));
  9184. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9185. system(str);
  9186. }
  9187. }
  9188. }// End of while(int k=0; k < ChargePointCount; k++)
  9189. }
  9190. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  9191. {
  9192. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  9193. for(int k=0; k < ChargeProfileCount; k++)
  9194. {
  9195. fptr1 = fopen(chargingProfiles[k], "r");
  9196. fptr2 = fopen(temp, "w+");
  9197. //Check Charging Profile Count
  9198. while(fscanf(fptr1, "%s", word) != EOF)
  9199. {
  9200. //DEBUG_INFO("word=%s\n",word);
  9201. if(strstr(word, "chargingProfileId")!= NULL)
  9202. {
  9203. n_chargingProfile = n_chargingProfile + 1;
  9204. }
  9205. }
  9206. rewind(fptr1);
  9207. //search Charging Profile Element
  9208. //int i= 0;
  9209. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9210. {
  9211. json_object *tmpProfilee;
  9212. tmpProfilee = json_tokener_parse(sLineWord);
  9213. if(!is_error(tmpProfilee))
  9214. {
  9215. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9216. {
  9217. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9218. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9219. }
  9220. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9221. {
  9222. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9223. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9224. }
  9225. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9226. {
  9227. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9228. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9229. }
  9230. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9231. {
  9232. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9233. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9234. }
  9235. }
  9236. json_object_put(tmpProfilee);
  9237. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9238. {
  9239. //------- not write to fptr2-------//
  9240. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9241. //clearflag = TRUE;
  9242. }
  9243. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9244. {
  9245. //------- not write to fptr2-------//
  9246. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9247. }
  9248. else if(stackLevelIsNULL == TRUE)
  9249. {
  9250. //Clear Whole File
  9251. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9252. clearflag = TRUE;
  9253. break;
  9254. }
  9255. else
  9256. {
  9257. fprintf(fptr2, sLineWord);//writing data into file
  9258. }
  9259. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9260. }
  9261. if(clearflag == TRUE)
  9262. {
  9263. fclose(fptr1);
  9264. fclose(fptr2);
  9265. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9266. system(str);
  9267. // clear temp file
  9268. sprintf(str,"rm -f %s",temp);
  9269. system(str);
  9270. }
  9271. else
  9272. {
  9273. fclose(fptr1);
  9274. fclose(fptr2);
  9275. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9276. system(str);
  9277. resultRename = rename(temp, chargingProfiles[k]);
  9278. if(resultRename == 0)
  9279. {
  9280. DEBUG_INFO("File ChargingProfile renamed successfully");
  9281. }
  9282. else
  9283. {
  9284. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9285. }
  9286. if(comfirmstr[0]== 0)
  9287. {
  9288. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9289. }
  9290. //Check chargingProfile is empty file
  9291. /*------ Read the file ----------------*/
  9292. fptr1=fopen(chargingProfiles[k],"r");
  9293. ch=fgetc(fptr1);
  9294. rewind(fptr1);
  9295. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9296. if(ch!=EOF)
  9297. {
  9298. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9299. {
  9300. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9301. if(sLineWord[0]=='\0')
  9302. {
  9303. isEmptyFile = TRUE;
  9304. break;
  9305. }
  9306. else
  9307. {
  9308. isEmptyFile = FALSE;
  9309. break;
  9310. }
  9311. }
  9312. }
  9313. else
  9314. isEmptyFile = TRUE;
  9315. fclose(fptr1);
  9316. if(isEmptyFile == TRUE)
  9317. {
  9318. memset(str, 0, ARRAY_SIZE(str));
  9319. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9320. system(str);
  9321. }
  9322. /*------- End of reading ---------------*/
  9323. }
  9324. } // while(int k=0; k < ChargeProfileCount; k++)
  9325. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9326. end:
  9327. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9328. {
  9329. if(connectorIdInt == 0)
  9330. {
  9331. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9332. {
  9333. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9334. }
  9335. }
  9336. else
  9337. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9338. }
  9339. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9340. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9341. return result;
  9342. }
  9343. void createFirmwareVersionByDataTransfer(void)
  9344. {
  9345. json_object *FirmwareDataTransfer = json_object_new_object();
  9346. // AC & DC model
  9347. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9348. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9349. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9350. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9351. // DC model
  9352. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9353. {
  9354. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9355. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9356. (gunType[3] != GUN_TYPE_UNKNOWN))
  9357. {
  9358. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9359. }
  9360. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9361. {
  9362. // DS DM DW
  9363. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9364. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9365. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9366. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9367. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9368. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9369. }
  9370. else
  9371. {
  9372. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9373. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9374. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9375. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9376. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9377. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9378. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9379. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9380. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9381. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9382. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9383. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9384. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9385. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9386. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9387. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9388. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9389. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9390. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9391. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9392. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9393. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9394. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9395. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9396. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9397. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9398. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9399. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9400. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9401. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9402. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9403. }
  9404. }
  9405. // 4G model
  9406. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9407. {
  9408. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9409. }
  9410. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9411. json_object_put(FirmwareDataTransfer);
  9412. }
  9413. int handleDataTransferRequest(char *uuid, char *payload)
  9414. {
  9415. mtrace();
  9416. json_object *response = json_object_new_object();
  9417. int result = FAIL;
  9418. char tempvendorId[255]={0};
  9419. char tempmessageId[50]={0};
  9420. char tempdata[512]={0};
  9421. char message[2048]={0};
  9422. DEBUG_INFO("handleDataTransferRequest...\n");
  9423. if((uuid != NULL) && (payload != NULL))
  9424. {
  9425. json_object *DataTransfer;
  9426. DataTransfer = json_tokener_parse(payload);
  9427. if(!is_error(DataTransfer))
  9428. {
  9429. // Required data
  9430. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9431. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9432. // Optional data
  9433. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9434. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9435. if(json_object_object_get(DataTransfer, "data") != NULL)
  9436. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9437. result = PASS;
  9438. }
  9439. json_object_put(DataTransfer);
  9440. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9441. {
  9442. // Send all moudle firmware version on EVSE
  9443. createFirmwareVersionByDataTransfer();
  9444. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9445. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9446. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9447. json_object_put(response);
  9448. }
  9449. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9450. {
  9451. system("/usr/bin/run_tmate_restart.sh &");
  9452. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9453. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9454. json_object_put(response);
  9455. }
  9456. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9457. {
  9458. json_object *data;
  9459. data = json_tokener_parse(tempdata);
  9460. if(!is_error(data))
  9461. {
  9462. 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))
  9463. {
  9464. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9465. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9466. if(json_object_object_get(data, "SOC") != NULL)
  9467. {
  9468. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9469. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9470. }
  9471. if(json_object_object_get(data, "Energy") != NULL)
  9472. {
  9473. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9474. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9475. }
  9476. if(json_object_object_get(data, "Duration") != NULL)
  9477. {
  9478. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9479. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9480. }
  9481. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9482. }
  9483. else
  9484. {
  9485. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9486. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9487. }
  9488. }
  9489. else
  9490. {
  9491. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9492. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9493. }
  9494. json_object_put(data);
  9495. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9496. json_object_put(response);
  9497. }
  9498. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9499. {
  9500. json_object *data;
  9501. data = json_tokener_parse(tempdata);
  9502. if(!is_error(data))
  9503. {
  9504. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9505. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9506. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9507. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9508. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9509. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9510. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9511. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9512. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9513. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9514. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9515. }
  9516. else
  9517. {
  9518. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9519. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9520. }
  9521. json_object_put(data);
  9522. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9523. json_object_put(response);
  9524. }
  9525. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9526. {
  9527. json_object *data;
  9528. data = json_tokener_parse(tempdata);
  9529. if(!is_error(data))
  9530. {
  9531. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9532. if(json_object_object_get(data, "idToken") != NULL)
  9533. {
  9534. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9535. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9536. }
  9537. if(json_object_object_get(data, "price") != NULL)
  9538. {
  9539. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9540. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9541. }
  9542. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9543. }
  9544. else
  9545. {
  9546. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9547. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9548. }
  9549. json_object_put(data);
  9550. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9551. json_object_put(response);
  9552. }
  9553. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9554. {
  9555. json_object *data;
  9556. data = json_tokener_parse(tempdata);
  9557. if(!is_error(data))
  9558. {
  9559. if(json_object_object_get(data, "txId") != NULL)
  9560. {
  9561. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9562. for(int idx = 0;idx<gunTotalNumber;idx++)
  9563. {
  9564. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9565. {
  9566. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9567. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9568. if(json_object_object_get(data, "description") != NULL)
  9569. {
  9570. // California pricing V1.0
  9571. DEBUG_INFO("California pricing V1.0\n");
  9572. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9573. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9574. }
  9575. else
  9576. {
  9577. // California pricing V1.1
  9578. DEBUG_INFO("California pricing V1.1\n");
  9579. if(json_object_object_get(data, "timestamp") != NULL)
  9580. {
  9581. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9582. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9583. }
  9584. if(json_object_object_get(data, "meterValue") != NULL)
  9585. {
  9586. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9587. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9588. }
  9589. if(json_object_object_get(data, "cost") != NULL)
  9590. {
  9591. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9592. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9593. }
  9594. if(json_object_object_get(data, "state") != NULL)
  9595. {
  9596. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9597. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9598. }
  9599. if(json_object_object_get(data, "chargingPrice") != NULL)
  9600. {
  9601. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9602. {
  9603. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9604. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9605. }
  9606. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9607. {
  9608. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9609. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9610. }
  9611. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9612. {
  9613. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9614. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9615. }
  9616. }
  9617. if(json_object_object_get(data, "idlePrice") != NULL)
  9618. {
  9619. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9620. {
  9621. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9622. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9623. }
  9624. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9625. {
  9626. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9627. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9628. }
  9629. }
  9630. if(json_object_object_get(data, "nextPeriod") != NULL)
  9631. {
  9632. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9633. {
  9634. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9635. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9636. }
  9637. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9638. {
  9639. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9640. {
  9641. 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")));
  9642. 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"));
  9643. }
  9644. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9645. {
  9646. 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")));
  9647. 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"));
  9648. }
  9649. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9650. {
  9651. 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")));
  9652. 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"));
  9653. }
  9654. }
  9655. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9656. {
  9657. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9658. {
  9659. 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")));
  9660. 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"));
  9661. }
  9662. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9663. {
  9664. 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")));
  9665. 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"));
  9666. }
  9667. }
  9668. }
  9669. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9670. {
  9671. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9672. {
  9673. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9674. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9675. }
  9676. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9677. {
  9678. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9679. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9680. }
  9681. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9682. {
  9683. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9684. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9685. }
  9686. }
  9687. }
  9688. }
  9689. }
  9690. }
  9691. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9692. }
  9693. else
  9694. {
  9695. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9696. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9697. }
  9698. json_object_put(data);
  9699. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9700. json_object_put(response);
  9701. }
  9702. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9703. {
  9704. json_object *data;
  9705. data = json_tokener_parse(tempdata);
  9706. if(!is_error(data))
  9707. {
  9708. if(json_object_object_get(data, "txId") != NULL)
  9709. {
  9710. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9711. for(int idx = 0;idx<gunTotalNumber;idx++)
  9712. {
  9713. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9714. {
  9715. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9716. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9717. if(json_object_object_get(data, "description") != NULL)
  9718. {
  9719. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9720. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9721. }
  9722. }
  9723. }
  9724. }
  9725. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9726. }
  9727. else
  9728. {
  9729. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9730. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9731. }
  9732. json_object_put(data);
  9733. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9734. json_object_put(response);
  9735. }
  9736. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9737. {
  9738. json_object *data;
  9739. data = json_tokener_parse(tempdata);
  9740. if(!is_error(data))
  9741. {
  9742. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9743. if(json_object_object_get(data, "Content_Type") != NULL)
  9744. {
  9745. 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))
  9746. {
  9747. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9748. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9749. {
  9750. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9751. }
  9752. }
  9753. else
  9754. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9755. }
  9756. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9757. }
  9758. else
  9759. {
  9760. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9761. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9762. }
  9763. json_object_put(data);
  9764. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9765. json_object_put(response);
  9766. }
  9767. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9768. {
  9769. json_object *data;
  9770. data = json_tokener_parse(tempdata);
  9771. if(!is_error(data))
  9772. {
  9773. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9774. if(json_object_object_get(data, "ConnectorId") != NULL)
  9775. {
  9776. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9777. }
  9778. if(json_object_object_get(data, "SerialNo") != NULL)
  9779. {
  9780. sprintf((char *)ShmOCPP16Data->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9781. }
  9782. if(json_object_object_get(data, "Page_Index") != NULL)
  9783. {
  9784. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9785. }
  9786. if(json_object_object_get(data, "Duration") != NULL)
  9787. {
  9788. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9789. }
  9790. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9791. }
  9792. else
  9793. {
  9794. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9795. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9796. }
  9797. json_object_put(data);
  9798. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9799. json_object_put(response);
  9800. }
  9801. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9802. {
  9803. json_object *data;
  9804. data = json_tokener_parse(tempdata);
  9805. if(!is_error(data))
  9806. {
  9807. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9808. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9809. {
  9810. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9811. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9812. else
  9813. {
  9814. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9815. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9816. }
  9817. }
  9818. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9819. {
  9820. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9821. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9822. else
  9823. {
  9824. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9825. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9826. }
  9827. }
  9828. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9829. {
  9830. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9831. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9832. else
  9833. {
  9834. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9835. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9836. }
  9837. }
  9838. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9839. {
  9840. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9841. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9842. else
  9843. {
  9844. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9845. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9846. }
  9847. }
  9848. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9849. {
  9850. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9851. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9852. else
  9853. {
  9854. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9855. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9856. }
  9857. }
  9858. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9859. {
  9860. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9861. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9862. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9863. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9864. else
  9865. {
  9866. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9867. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9868. }
  9869. }
  9870. if(json_object_object_get(data, "isAuthentication") != NULL)
  9871. {
  9872. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9873. {
  9874. case 0:
  9875. case 1:
  9876. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9877. break;
  9878. default:
  9879. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9880. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9881. break;
  9882. }
  9883. }
  9884. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9885. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9886. }
  9887. else
  9888. {
  9889. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9890. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9891. }
  9892. json_object_put(data);
  9893. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9894. json_object_put(response);
  9895. }
  9896. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  9897. {
  9898. json_object *data;
  9899. data = json_tokener_parse(tempdata);
  9900. if(!is_error(data))
  9901. {
  9902. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9903. {
  9904. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  9905. {
  9906. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9907. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9908. }
  9909. else
  9910. {
  9911. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9912. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  9913. }
  9914. }
  9915. else
  9916. {
  9917. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9918. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9919. }
  9920. }
  9921. else
  9922. {
  9923. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9924. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9925. }
  9926. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9927. json_object_put(response);
  9928. }
  9929. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9930. {
  9931. json_object *data;
  9932. data = json_tokener_parse(tempdata);
  9933. if(!is_error(data))
  9934. {
  9935. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9936. if(json_object_object_get(data, "stationName") != NULL)
  9937. {
  9938. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9939. }
  9940. else
  9941. {
  9942. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9943. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9944. }
  9945. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9946. {
  9947. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  9948. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9949. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  9950. }
  9951. }
  9952. else
  9953. {
  9954. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9955. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9956. }
  9957. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9958. json_object_put(response);
  9959. }
  9960. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9961. {
  9962. json_object *data;
  9963. data = json_tokener_parse(tempdata);
  9964. if(!is_error(data))
  9965. {
  9966. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9967. if(json_object_object_get(data, "weatherId") != NULL)
  9968. {
  9969. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9970. }
  9971. else
  9972. {
  9973. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9974. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9975. }
  9976. if(json_object_object_get(data, "Temperature") != NULL)
  9977. {
  9978. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9979. }
  9980. else
  9981. {
  9982. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9983. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9984. }
  9985. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9986. {
  9987. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  9988. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9989. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  9990. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  9991. );
  9992. }
  9993. }
  9994. else
  9995. {
  9996. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9997. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9998. }
  9999. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10000. json_object_put(response);
  10001. }
  10002. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  10003. {
  10004. json_object *data;
  10005. data = json_tokener_parse(tempdata);
  10006. if(!is_error(data))
  10007. {
  10008. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10009. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  10010. {
  10011. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  10012. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  10013. }
  10014. else
  10015. {
  10016. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10017. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  10018. }
  10019. }
  10020. else
  10021. {
  10022. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10023. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10024. }
  10025. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10026. json_object_put(response);
  10027. }
  10028. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  10029. {
  10030. json_object *data;
  10031. data = json_tokener_parse(tempdata);
  10032. if(!is_error(data))
  10033. {
  10034. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10035. {
  10036. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10037. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10038. if(gun_index < gunTotalNumber)
  10039. {
  10040. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10041. {
  10042. json_object *responsedata = json_object_new_object();
  10043. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  10044. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  10045. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  10046. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  10047. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  10048. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10049. }
  10050. else
  10051. {
  10052. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10053. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  10054. }
  10055. }
  10056. else
  10057. {
  10058. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10059. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  10060. }
  10061. }
  10062. else
  10063. {
  10064. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10065. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10066. }
  10067. }
  10068. else
  10069. {
  10070. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10071. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10072. }
  10073. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10074. json_object_put(response);
  10075. }
  10076. else
  10077. {
  10078. // Can not find valid message id
  10079. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  10080. }
  10081. }
  10082. else
  10083. {
  10084. // Payload is null
  10085. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  10086. }
  10087. LWS_Send(message);
  10088. return result;
  10089. }
  10090. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  10091. {
  10092. mtrace();
  10093. int result = FAIL;
  10094. int connectorIdInt, durationInt;
  10095. char chargingRateUnitStr[4]={0};
  10096. char comfirmstr[20];
  10097. int confirmPeriods = 0;
  10098. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  10099. json_object *GetCompositeSchedule;
  10100. GetCompositeSchedule = json_tokener_parse(payload);
  10101. if(!is_error(GetCompositeSchedule))
  10102. {
  10103. // Required data
  10104. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  10105. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  10106. else
  10107. connectorIdInt = -1;
  10108. if(json_object_object_get(GetCompositeSchedule, "duration"))
  10109. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  10110. else
  10111. durationInt = 86400;
  10112. // Optional data
  10113. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  10114. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  10115. }
  10116. json_object_put(GetCompositeSchedule);
  10117. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  10118. if((connectorIdInt == 0) ||
  10119. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  10120. {
  10121. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  10122. struct StructChargingProfile tmpProfile[1];
  10123. if(strstr(chargingRateUnitStr, "W") != NULL)
  10124. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  10125. else
  10126. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  10127. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10128. {
  10129. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10130. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10131. }
  10132. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  10133. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  10134. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  10135. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10136. {
  10137. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10138. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10139. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  10140. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  10141. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  10142. {
  10143. confirmPeriods = idx;
  10144. break;
  10145. }
  10146. }
  10147. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  10148. {
  10149. confirmPeriods += 1;
  10150. }
  10151. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  10152. }
  10153. else
  10154. {
  10155. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  10156. }
  10157. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  10158. return result;
  10159. }
  10160. int handleGetConfigurationRequest(char *uuid, char *payload)
  10161. {
  10162. mtrace();
  10163. int result = FAIL;
  10164. int MaxKeySupported = 0;
  10165. int n_keys = 0;
  10166. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  10167. DEBUG_INFO("handleGetConfigurationRequest...\n");
  10168. json_object *GetConfiguration;
  10169. GetConfiguration = json_tokener_parse(payload);
  10170. if(!is_error(GetConfiguration))
  10171. {
  10172. // Optional data
  10173. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10174. {
  10175. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10176. {
  10177. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10178. n_keys = idx + 1;
  10179. }
  10180. }
  10181. }
  10182. json_object_put(GetConfiguration);
  10183. UnknownKeynum = 0;
  10184. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10185. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10186. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10187. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10188. if(n_keys != 0)
  10189. {
  10190. for(int i=0;i<n_keys;i++)
  10191. {
  10192. getKeyValue(requestKey[i]);
  10193. }
  10194. }
  10195. else
  10196. {
  10197. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10198. getKeyValue("");
  10199. }
  10200. processUnkownKey();
  10201. sendGetConfigurationConfirmation(uuid);
  10202. return result;
  10203. }
  10204. static char fnamePlusPath[100]={0};
  10205. static char fnamePWithNoPath[60]={0};
  10206. void checkUploadLog(void)
  10207. {
  10208. FILE *fp;
  10209. /* Open the command for reading. */
  10210. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10211. if (fp == NULL) {
  10212. DEBUG_WARN("Failed to run command\n" );
  10213. exit(1);
  10214. }
  10215. int ftppathlen = 0;
  10216. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10217. int i = 0;
  10218. /* Read the output a line at a time - output it. */
  10219. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10220. if(i==0)
  10221. {
  10222. ftppathlen = strlen(fnamePlusPath);
  10223. DEBUG_INFO("%s\n", fnamePlusPath);
  10224. fnamePlusPath[ftppathlen]='\0';
  10225. break;
  10226. }
  10227. i= i+1;
  10228. }
  10229. /* close */
  10230. pclose(fp);
  10231. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10232. {
  10233. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10234. {
  10235. fnamePlusPath[k]='\0';
  10236. }
  10237. }
  10238. i=1;
  10239. //char fname[60]={0};
  10240. while(i < ftppathlen)
  10241. {
  10242. int len=ftppathlen-i;
  10243. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10244. {
  10245. DEBUG_INFO("compare '/' all right\n");
  10246. break;
  10247. }
  10248. i=i+1;
  10249. }
  10250. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  10251. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  10252. fnamePWithNoPath[i+1] = '\0';
  10253. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  10254. {
  10255. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  10256. {
  10257. fnamePWithNoPath[j]='\0';
  10258. }
  10259. }
  10260. FILE* fp1 = fopen(fnamePlusPath, "r");
  10261. if (fp1)
  10262. {
  10263. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  10264. // file exists
  10265. fclose(fp1);
  10266. }
  10267. else
  10268. {
  10269. // file doesn't exist
  10270. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  10271. }
  10272. }
  10273. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  10274. {
  10275. mtrace();
  10276. int result = FAIL;
  10277. time_t CurrentTime;
  10278. struct tm *tm;
  10279. pthread_t th_Status;
  10280. CurrentTime = time(NULL);
  10281. tm = localtime(&CurrentTime);
  10282. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  10283. 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);
  10284. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10285. if(!interLock.isGetDiagnosticGoing)
  10286. {
  10287. interLock.isGetDiagnosticGoing = 1;
  10288. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  10289. sleep(1);
  10290. }
  10291. else
  10292. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  10293. return result;
  10294. }
  10295. void* GetDiagnosticsProcess(void* data)
  10296. {
  10297. pthread_detach(pthread_self());
  10298. mtrace();
  10299. int retriesInt=0, retryIntervalInt=0;
  10300. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  10301. 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};
  10302. int port=0;
  10303. int isSuccess = FALSE;
  10304. char cmdBuf[2048];
  10305. struct tm *tmNow;
  10306. time_t CurrentTime;
  10307. struct tm tmStart;
  10308. struct tm tmStop;
  10309. CurrentTime = time(NULL);
  10310. tmNow=localtime(&CurrentTime);
  10311. uint16_t targetYear, targetMonth;
  10312. json_object *GetDiagnostics;
  10313. DEBUG_INFO("GetDiagnosticsProcess...\n");
  10314. GetDiagnostics = json_tokener_parse(data);
  10315. if(!is_error(GetDiagnostics))
  10316. {
  10317. // Required data
  10318. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  10319. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  10320. // Optional data
  10321. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  10322. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  10323. else
  10324. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  10325. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  10326. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  10327. else
  10328. retryIntervalInt = 30;
  10329. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  10330. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  10331. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  10332. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  10333. }
  10334. json_object_put(GetDiagnostics);
  10335. // Pack log to compress file
  10336. 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) &&
  10337. (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))
  10338. {
  10339. // Pack system log
  10340. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10341. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10342. targetYear = tmStart.tm_year;
  10343. targetMonth = tmStart.tm_mon;
  10344. do
  10345. {
  10346. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10347. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  10348. if(targetMonth+1>=13)
  10349. {
  10350. targetYear += 1;
  10351. targetMonth = 1;
  10352. }
  10353. else
  10354. {
  10355. targetMonth += 1;
  10356. }
  10357. }while((targetYear < (tmNow->tm_year+1900)) ||
  10358. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10359. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  10360. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  10361. system(cmdBuf);
  10362. // Pack charging & event log
  10363. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10364. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  10365. targetYear = tmStart.tm_year;
  10366. targetMonth = tmStart.tm_mon;
  10367. do
  10368. {
  10369. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10370. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  10371. if(targetMonth+1>=13)
  10372. {
  10373. targetYear += 1;
  10374. targetMonth = 1;
  10375. }
  10376. else
  10377. {
  10378. targetMonth += 1;
  10379. }
  10380. }while((targetYear < (tmNow->tm_year+1900)) ||
  10381. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10382. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10383. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10384. system(cmdBuf);
  10385. // Combine log file
  10386. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10387. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10388. }
  10389. else
  10390. {
  10391. system("exec /root/logPackTools 'log' 6");
  10392. }
  10393. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10394. system(cmdBuf);
  10395. checkUploadLog();
  10396. //****************location*******************/
  10397. if(strcmp(locationstr,"")==0)
  10398. {
  10399. DEBUG_INFO("location is <Empty>!\n");
  10400. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10401. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10402. goto end;
  10403. }
  10404. memset(protocol, 0, ARRAY_SIZE(protocol));
  10405. memset(user, 0, ARRAY_SIZE(user) );
  10406. memset(password, 0, ARRAY_SIZE(password));
  10407. memset(host, 0, ARRAY_SIZE(host));
  10408. memset(path, 0, ARRAY_SIZE(path));
  10409. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10410. memset(host1, 0, ARRAY_SIZE(host1));
  10411. memset(path1, 0, ARRAY_SIZE(path1));
  10412. /*location: ftp://user:password@host:port/path*/
  10413. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10414. if((access(fnamePlusPath,F_OK))!=-1)
  10415. {
  10416. DEBUG_INFO("fnamePlusPath exist.\n");
  10417. }
  10418. else
  10419. {
  10420. DEBUG_INFO("fnamePlusPath not exist!\n");
  10421. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10422. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10423. goto end;
  10424. }
  10425. if(strchr(locationstr,'@')==NULL)
  10426. {
  10427. sscanf(locationstr,
  10428. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10429. protocol, host, &port, path);
  10430. strcpy(user,"anonymous");
  10431. strcpy(password,"");
  10432. }
  10433. else
  10434. {
  10435. //DEBUG_INFO("pch=%s\n", pch);
  10436. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10437. protocol, user, password, host, &port, path);
  10438. }
  10439. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10440. {
  10441. DEBUG_INFO("protocol is not ftp/http ! \n");
  10442. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10443. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10444. goto end;
  10445. }
  10446. if(strncmp(locationstr,"http", 4) == 0)
  10447. {
  10448. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10449. sprintf(ftppath,"/%s", path);
  10450. do
  10451. {
  10452. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10453. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10454. sleep(3);
  10455. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10456. if(!isSuccess)
  10457. {
  10458. DEBUG_INFO("Diagnostics fail.\n");
  10459. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10460. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10461. sleep(retryIntervalInt);
  10462. }
  10463. else
  10464. {
  10465. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10466. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10467. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10468. }
  10469. retriesInt--;
  10470. }while((isSuccess == 0)&&(retriesInt >= 0));
  10471. }
  10472. else
  10473. {
  10474. sscanf(host,"%[^/]%s",host1, path1);
  10475. if(strlen(path) > 0)
  10476. sprintf(ftppath,"/%s", path);
  10477. else
  10478. sprintf(ftppath,"/%s", path1);
  10479. int ftppathlen=strlen(ftppath);
  10480. int i=1;
  10481. char filenametemp[50];
  10482. while(i < ftppathlen)
  10483. {
  10484. int len=ftppathlen-i;
  10485. if(ftppath[len]== 47) // '/' ascll code: 47
  10486. {
  10487. DEBUG_INFO("find '/' all right\n");
  10488. break;
  10489. }
  10490. i=i+1;
  10491. }
  10492. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10493. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10494. filenametemp[i+1] = 0;
  10495. if(port == 0)
  10496. port = 21;
  10497. do
  10498. {
  10499. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10500. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10501. sleep(3);
  10502. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10503. if(!isSuccess)
  10504. {
  10505. DEBUG_INFO("Diagnostics fail.\n");
  10506. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10507. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10508. sleep(retryIntervalInt);
  10509. }
  10510. else
  10511. {
  10512. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10513. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10514. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10515. }
  10516. retriesInt--;
  10517. }while((!isSuccess)&&(retriesInt >= 0));
  10518. }
  10519. end:
  10520. system("rm -f /mnt/*");
  10521. sleep(5);
  10522. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10523. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10524. interLock.isGetDiagnosticGoing = 0;
  10525. pthread_exit(NULL);
  10526. }
  10527. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10528. {
  10529. mtrace();
  10530. int result = FAIL;
  10531. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10532. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10533. {
  10534. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10535. locallistVersion = -1;
  10536. }
  10537. else
  10538. {
  10539. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10540. OCPP_getListVerion();
  10541. }
  10542. //from db.OCPP_getListVerion
  10543. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10544. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  10545. sendGetLocalListVersionConfirmation(uuid,"");
  10546. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  10547. return result;
  10548. }
  10549. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10550. {
  10551. mtrace();
  10552. int result = FAIL;
  10553. int connectorIdInt=-1;
  10554. int tempIndex = 0;
  10555. int connectorIdIsNULL, chargingProfileIsNULL;
  10556. char comfirmstr[20]={0};
  10557. char cmdBuf[512];
  10558. json_object *RemoteStartTransaction;
  10559. FILE *fp;
  10560. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10561. if(server_pending == TRUE)
  10562. {
  10563. return 0;
  10564. }
  10565. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10566. RemoteStartTransaction = json_tokener_parse(payload);
  10567. if(!is_error(RemoteStartTransaction))
  10568. {
  10569. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10570. {
  10571. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10572. }
  10573. else
  10574. {
  10575. connectorIdIsNULL = TRUE;
  10576. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10577. {
  10578. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10579. {
  10580. connectorIdIsNULL = FALSE;
  10581. connectorIdInt = (gun_index+1);
  10582. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10583. break;
  10584. }
  10585. }
  10586. }
  10587. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10588. {
  10589. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10590. // Required data
  10591. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10592. // Optional data
  10593. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10594. {
  10595. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10596. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10597. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10598. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10599. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10600. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10601. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10602. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10603. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10604. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10605. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10606. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10607. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10608. {
  10609. 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")));
  10610. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10611. 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"));
  10612. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10613. 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"));
  10614. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10615. 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")));
  10616. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10617. {
  10618. 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++)
  10619. {
  10620. 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"));
  10621. 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"));
  10622. 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)
  10623. 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"));
  10624. }
  10625. }
  10626. }
  10627. }
  10628. else
  10629. {
  10630. chargingProfileIsNULL = TRUE;
  10631. }
  10632. }
  10633. }
  10634. else
  10635. {
  10636. connectorIdIsNULL = TRUE;
  10637. }
  10638. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10639. {
  10640. DEBUG_WARN("Connector id is NULL\n.");
  10641. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10642. goto end;
  10643. }
  10644. /*
  10645. enum _SYSTEM_STATUS
  10646. {
  10647. S_BOOTING = 0,
  10648. S_IDLE, = 1
  10649. S_AUTHORIZING, = 2
  10650. S_REASSIGN_CHECK, = 3
  10651. S_REASSIGN, = 4
  10652. S_PRECHARGE, = 5
  10653. S_PREPARING_FOR_EV, = 6
  10654. S_PREPARING_FOR_EVSE, = 7
  10655. S_CHARGING, = 8
  10656. S_TERMINATING, = 9
  10657. S_COMPLETE, = 10
  10658. S_ALARM, = 11
  10659. S_FAULT = 12
  10660. }
  10661. */
  10662. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10663. {
  10664. //check Transaction active
  10665. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10666. {
  10667. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10668. {
  10669. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10670. }
  10671. else
  10672. {
  10673. tempIndex = connectorIdInt -1;
  10674. }
  10675. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10676. {
  10677. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10678. {
  10679. 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))
  10680. {
  10681. //Reserved
  10682. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10683. }
  10684. 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))
  10685. {
  10686. //Reserved
  10687. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10688. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10689. goto end;
  10690. }
  10691. else
  10692. {
  10693. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10694. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10695. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10696. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10697. {
  10698. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10699. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10700. goto end;
  10701. }
  10702. }//END FOR ELSE
  10703. }
  10704. }// END FOR CHAdeMO_QUANTITY
  10705. }
  10706. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10707. {
  10708. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10709. {
  10710. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10711. }
  10712. else
  10713. {
  10714. tempIndex = connectorIdInt -1;
  10715. }
  10716. for (int index = 0; index < CCS_QUANTITY; index++)
  10717. {
  10718. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10719. {
  10720. 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))
  10721. {
  10722. //Reserved
  10723. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10724. }
  10725. 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))
  10726. {
  10727. //Reserved
  10728. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10729. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10730. goto end;
  10731. }
  10732. else
  10733. {
  10734. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10735. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10736. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10737. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10738. {
  10739. DEBUG_WARN("CCS connector not allow start\n.");
  10740. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10741. goto end;
  10742. }
  10743. }// END FOR ELSE
  10744. }
  10745. }// END FOR CCS_QUANTITY
  10746. }
  10747. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10748. {
  10749. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10750. {
  10751. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10752. }
  10753. else
  10754. {
  10755. tempIndex = connectorIdInt -1;
  10756. }
  10757. for (int index = 0; index < GB_QUANTITY; index++)
  10758. {
  10759. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10760. {
  10761. 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))
  10762. {
  10763. //Reserved
  10764. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10765. }
  10766. 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))
  10767. {
  10768. //Reserved
  10769. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10770. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10771. goto end;
  10772. }
  10773. else
  10774. {
  10775. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10776. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10777. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10778. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10779. {
  10780. DEBUG_WARN("GB connector not allow start\n.");
  10781. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10782. goto end;
  10783. }
  10784. }// END FOR ELSE
  10785. }
  10786. } // END FOR GB_QUANTITY
  10787. }
  10788. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10789. {
  10790. tempIndex = connectorIdInt -1;
  10791. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10792. {
  10793. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10794. {
  10795. 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))
  10796. {
  10797. //Reserved
  10798. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10799. }
  10800. 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))
  10801. {
  10802. //Reserved
  10803. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10804. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10805. goto end;
  10806. }
  10807. else
  10808. {
  10809. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10810. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10811. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10812. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10813. {
  10814. DEBUG_WARN("GB connector not allow start\n.");
  10815. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10816. goto end;
  10817. }
  10818. }// END FOR ELSE
  10819. }
  10820. } // END FOR GB_QUANTITY
  10821. }
  10822. else
  10823. {
  10824. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10825. {
  10826. tempIndex = 2;
  10827. }
  10828. else
  10829. {
  10830. tempIndex = connectorIdInt -1;
  10831. }
  10832. for (int index = 0; index < AC_QUANTITY; index++)
  10833. {
  10834. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10835. {
  10836. 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))
  10837. {
  10838. //Reserved
  10839. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10840. }
  10841. 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))
  10842. {
  10843. //Reserved
  10844. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10845. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10846. goto end;
  10847. }
  10848. else
  10849. {
  10850. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10851. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10852. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10853. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10854. {
  10855. DEBUG_WARN("AC connector not allow start\n.");
  10856. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10857. goto end;
  10858. }
  10859. }//END FOR ELSE
  10860. }
  10861. }// END FOR AC_QUANTITY
  10862. }
  10863. if(chargingProfileIsNULL == FALSE)
  10864. {
  10865. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10866. {
  10867. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10868. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10869. //memset idTag
  10870. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10871. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10872. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10873. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10874. // Save profile to file
  10875. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10876. system(cmdBuf);
  10877. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10878. fp = fopen(cmdBuf, "w");
  10879. 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));
  10880. fclose(fp);
  10881. }
  10882. else
  10883. {
  10884. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10885. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10886. }
  10887. }
  10888. else
  10889. {
  10890. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10891. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10892. //memset idTag
  10893. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10894. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10895. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10896. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10897. }
  10898. }
  10899. else
  10900. {
  10901. DEBUG_WARN("Connector id over\n.");
  10902. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10903. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10904. }
  10905. end:
  10906. json_object_put(RemoteStartTransaction);
  10907. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10908. {
  10909. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10910. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10911. }
  10912. //OCPP send RemoteStartConfirmation by first.
  10913. sendRemoteStartConfirmation(uuid, comfirmstr);
  10914. return result;
  10915. }
  10916. int handleRemoteStartRequest(char *uuid, char *payload)
  10917. {
  10918. mtrace();
  10919. int result = PASS;
  10920. int connectorIdInt=-1;
  10921. int tempIndex = 0;
  10922. char comfirmstr[20]={0};
  10923. char cmdBuf[512];
  10924. json_object *RemoteStartTransaction;
  10925. FILE *fp;
  10926. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10927. if(server_pending == TRUE)
  10928. {
  10929. result = FAIL;
  10930. }
  10931. RemoteStartTransaction = json_tokener_parse(payload);
  10932. if(!is_error(RemoteStartTransaction))
  10933. {
  10934. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10935. {
  10936. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10937. }
  10938. else
  10939. {
  10940. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10941. {
  10942. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10943. {
  10944. connectorIdInt = (gun_index+1);
  10945. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10946. break;
  10947. }
  10948. }
  10949. }
  10950. if(connectorIdInt == 0)
  10951. {
  10952. DEBUG_WARN("Connector id shall not equal 0.\n");
  10953. result = FAIL;
  10954. }
  10955. else if(connectorIdInt == -1)
  10956. {
  10957. DEBUG_INFO("Connector id does not specific.\n");
  10958. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10959. {
  10960. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10961. // Required data
  10962. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10963. // Optional data
  10964. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10965. {
  10966. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10967. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10968. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10969. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10970. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10971. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10972. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10973. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10974. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10975. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10976. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10977. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10978. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10979. {
  10980. 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")));
  10981. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10982. 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"));
  10983. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10984. 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"));
  10985. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10986. 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")));
  10987. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10988. {
  10989. 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++)
  10990. {
  10991. 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"));
  10992. 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"));
  10993. 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)
  10994. 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"));
  10995. }
  10996. }
  10997. }
  10998. }
  10999. else
  11000. {
  11001. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  11002. }
  11003. }
  11004. }
  11005. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  11006. {
  11007. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  11008. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  11009. // Required data
  11010. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11011. // Optional data
  11012. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11013. {
  11014. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11015. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11016. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11017. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11018. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11019. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11020. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11021. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11022. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11023. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11024. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11025. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11026. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11027. {
  11028. 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")));
  11029. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11030. 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"));
  11031. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11032. 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"));
  11033. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11034. 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")));
  11035. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11036. {
  11037. 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++)
  11038. {
  11039. 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"));
  11040. 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"));
  11041. 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)
  11042. 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"));
  11043. }
  11044. }
  11045. }
  11046. }
  11047. else
  11048. {
  11049. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  11050. }
  11051. }
  11052. else
  11053. {
  11054. DEBUG_WARN("Connector id is over maximun value.\n");
  11055. result = FAIL;
  11056. }
  11057. }
  11058. if(result == PASS)
  11059. {
  11060. if(connectorIdInt > 0)
  11061. {
  11062. //check Transaction active
  11063. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11064. {
  11065. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11066. {
  11067. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11068. }
  11069. else
  11070. {
  11071. tempIndex = connectorIdInt -1;
  11072. }
  11073. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11074. {
  11075. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11076. {
  11077. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11078. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11079. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11080. {
  11081. //Reserved
  11082. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  11083. }
  11084. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11085. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11086. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11087. {
  11088. //Reserved
  11089. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  11090. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11091. goto end;
  11092. }
  11093. else
  11094. {
  11095. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11096. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  11097. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  11098. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  11099. {
  11100. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  11101. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11102. goto end;
  11103. }
  11104. }//END FOR ELSE
  11105. }
  11106. }// END FOR CHAdeMO_QUANTITY
  11107. }
  11108. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11109. {
  11110. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11111. {
  11112. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11113. }
  11114. else
  11115. {
  11116. tempIndex = connectorIdInt -1;
  11117. }
  11118. for (int index = 0; index < CCS_QUANTITY; index++)
  11119. {
  11120. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11121. {
  11122. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11123. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11124. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11125. {
  11126. //Reserved
  11127. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  11128. }
  11129. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11130. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11131. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11132. {
  11133. //Reserved
  11134. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  11135. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11136. goto end;
  11137. }
  11138. else
  11139. {
  11140. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11141. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11142. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11143. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11144. {
  11145. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11146. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11147. goto end;
  11148. }
  11149. }// END FOR ELSE
  11150. }
  11151. }// END FOR CCS_QUANTITY
  11152. }
  11153. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11154. {
  11155. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11156. {
  11157. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11158. }
  11159. else
  11160. {
  11161. tempIndex = connectorIdInt -1;
  11162. }
  11163. for (int index = 0; index < GB_QUANTITY; index++)
  11164. {
  11165. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11166. {
  11167. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11168. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11169. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11170. {
  11171. //Reserved
  11172. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11173. }
  11174. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11175. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11176. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11177. {
  11178. //Reserved
  11179. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11180. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11181. goto end;
  11182. }
  11183. else
  11184. {
  11185. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11186. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11187. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11188. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11189. {
  11190. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11191. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11192. goto end;
  11193. }
  11194. }// END FOR ELSE
  11195. }
  11196. } // END FOR GB_QUANTITY
  11197. }
  11198. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11199. {
  11200. tempIndex = connectorIdInt -1;
  11201. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11202. {
  11203. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11204. {
  11205. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11206. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11207. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11208. {
  11209. //Reserved
  11210. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11211. }
  11212. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11213. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11214. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11215. {
  11216. //Reserved
  11217. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11218. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11219. goto end;
  11220. }
  11221. else
  11222. {
  11223. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11224. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11225. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11226. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11227. {
  11228. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11229. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11230. goto end;
  11231. }
  11232. }// END FOR ELSE
  11233. }
  11234. } // END FOR GB_QUANTITY
  11235. }
  11236. else
  11237. {
  11238. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11239. {
  11240. tempIndex = 2;
  11241. }
  11242. else
  11243. {
  11244. tempIndex = connectorIdInt -1;
  11245. }
  11246. for (int index = 0; index < AC_QUANTITY; index++)
  11247. {
  11248. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11249. {
  11250. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11251. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11252. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11253. {
  11254. //Reserved
  11255. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11256. }
  11257. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11258. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11259. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11260. {
  11261. //Reserved
  11262. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11263. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11264. goto end;
  11265. }
  11266. else
  11267. {
  11268. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11269. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11270. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11271. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11272. {
  11273. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11274. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11275. goto end;
  11276. }
  11277. }//END FOR ELSE
  11278. }
  11279. }// END FOR AC_QUANTITY
  11280. }
  11281. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11282. {
  11283. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11284. {
  11285. // Save profile to file
  11286. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11287. system(cmdBuf);
  11288. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11289. fp = fopen(cmdBuf, "w");
  11290. 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));
  11291. fclose(fp);
  11292. }
  11293. else
  11294. {
  11295. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11296. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11297. goto end;
  11298. }
  11299. }
  11300. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11301. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11302. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11303. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11304. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11305. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11306. }
  11307. else
  11308. {
  11309. uint8_t isHasIdleConnector = FALSE;
  11310. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11311. {
  11312. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11313. {
  11314. isHasIdleConnector = TRUE;
  11315. break;
  11316. }
  11317. }
  11318. if(isHasIdleConnector == TRUE)
  11319. {
  11320. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11321. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11322. {
  11323. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11324. {
  11325. // Save profile to file
  11326. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11327. system(cmdBuf);
  11328. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11329. fp = fopen(cmdBuf, "w");
  11330. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11331. fclose(fp);
  11332. refreshStartTimer(&clientTime.RemoteStartWait);
  11333. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11334. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11335. }
  11336. else
  11337. {
  11338. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11339. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11340. }
  11341. }
  11342. else
  11343. {
  11344. refreshStartTimer(&clientTime.RemoteStartWait);
  11345. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11346. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11347. }
  11348. }
  11349. else
  11350. {
  11351. DEBUG_INFO("There is not any connector is idle.\n");
  11352. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11353. }
  11354. }
  11355. }
  11356. else
  11357. {
  11358. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11359. }
  11360. end:
  11361. json_object_put(RemoteStartTransaction);
  11362. sendRemoteStartConfirmation(uuid, comfirmstr);
  11363. return result;
  11364. }
  11365. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11366. {
  11367. mtrace();
  11368. int result = FAIL;
  11369. int match = FALSE;
  11370. int GunNO = 0;
  11371. int tempIndex = 0;
  11372. int transactionIdInt=0;
  11373. int transactionIdIsNULL= TRUE;
  11374. char comfirmstr[20];
  11375. json_object *RemoteStopTransaction;
  11376. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11377. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11378. if(server_pending == TRUE)
  11379. {
  11380. return 0;
  11381. }
  11382. RemoteStopTransaction = json_tokener_parse(payload);
  11383. if(!is_error(RemoteStopTransaction))
  11384. {
  11385. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11386. {
  11387. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11388. transactionIdIsNULL = FALSE;
  11389. }
  11390. }
  11391. json_object_put(RemoteStopTransaction);
  11392. if(transactionIdIsNULL == FALSE)
  11393. {
  11394. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11395. {
  11396. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11397. {
  11398. //check Transaction active
  11399. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11400. {
  11401. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11402. {
  11403. tempIndex = ((gun_index==2) ? 1: 0);
  11404. }
  11405. else
  11406. {
  11407. tempIndex = gun_index;
  11408. }
  11409. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11410. {
  11411. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11412. {
  11413. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11414. {
  11415. match = TRUE;
  11416. GunNO = gun_index;
  11417. }
  11418. }
  11419. }// END FOR CHAdeMO_QUANTITY
  11420. }
  11421. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11422. {
  11423. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11424. {
  11425. tempIndex = ((gun_index==2) ? 1: 0);
  11426. }
  11427. else
  11428. {
  11429. tempIndex = gun_index;
  11430. }
  11431. for (int index = 0; index < CCS_QUANTITY; index++)
  11432. {
  11433. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11434. {
  11435. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11436. {
  11437. match = TRUE;
  11438. GunNO = gun_index;
  11439. }
  11440. }
  11441. }// END FOR CCS_QUANTITY
  11442. }
  11443. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11444. {
  11445. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11446. {
  11447. tempIndex = ((gun_index==2) ? 1: 0);
  11448. }
  11449. else
  11450. {
  11451. tempIndex = gun_index;
  11452. }
  11453. for (int index = 0; index < GB_QUANTITY; index++)
  11454. {
  11455. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11456. {
  11457. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11458. {
  11459. match = TRUE;
  11460. GunNO = gun_index;
  11461. }
  11462. }
  11463. }// END FOR GB_QUANTITY
  11464. }
  11465. else if(gunType[gun_index] == GUN_TYPE_DO)
  11466. {
  11467. tempIndex = gun_index;
  11468. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11469. {
  11470. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11471. {
  11472. 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
  11473. {
  11474. match = TRUE;
  11475. GunNO = gun_index;
  11476. }
  11477. }
  11478. }// END FOR GB_QUANTITY
  11479. }
  11480. else
  11481. {
  11482. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11483. {
  11484. tempIndex = 2;
  11485. }
  11486. else
  11487. {
  11488. tempIndex = gun_index;
  11489. }
  11490. for (int index = 0; index < AC_QUANTITY; index++)
  11491. {
  11492. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11493. {
  11494. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11495. {
  11496. match = TRUE;
  11497. GunNO = gun_index;
  11498. }
  11499. }
  11500. }// END FOR CHAdeMO_QUANTITY
  11501. } // END FOR AC ELSE
  11502. }// CHECK IF ResponseTransactionId == transactionIdInt
  11503. }//END FOR
  11504. if( match == TRUE)
  11505. {
  11506. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11507. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11508. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11509. }
  11510. else
  11511. {
  11512. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11513. }
  11514. }
  11515. else
  11516. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11517. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11518. return result;
  11519. }
  11520. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11521. {
  11522. mtrace();
  11523. int result = FAIL;
  11524. int connectorIdInt=0, reservationIdInt=0;
  11525. int tempIndex = 0;
  11526. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  11527. char comfirmstr[20]={0};
  11528. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11529. int c = 0;
  11530. char *loc;
  11531. //char *ptr;
  11532. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11533. strcpy(sstrtemp, stringtrimspace(payload));
  11534. //***(1)connectorId ****/
  11535. c=0;
  11536. loc = strstr(sstrtemp, "connectorId");
  11537. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11538. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11539. {
  11540. sstr[c] = loc[strlen("connectorId")+2+c];
  11541. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11542. c++;
  11543. }
  11544. sstr[c] = '\0';
  11545. connectorIdInt = atoi(sstr);
  11546. //***(2)expiryDate ****/
  11547. loc = strstr(sstrtemp, "expiryDate");
  11548. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11549. c = 0;
  11550. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11551. {
  11552. sstr[c] = loc[3+strlen("expiryDate")+c];
  11553. c++;
  11554. }
  11555. sstr[c] = '\0';
  11556. strcpy(expiryDatestr, sstr);
  11557. //***(3)idTag ****/
  11558. loc = strstr(sstrtemp, "idTag");
  11559. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11560. c = 0;
  11561. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11562. {
  11563. sstr[c] = loc[3+strlen("idTag")+c];
  11564. c++;
  11565. }
  11566. sstr[c] = '\0';
  11567. strcpy(idTagstr, sstr);
  11568. //***(4)parentIdTag ****/
  11569. loc = strstr(sstrtemp, "parentIdTag");
  11570. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11571. c = 0;
  11572. if(loc == NULL)
  11573. {
  11574. strcpy(parentIdTagstr, "");
  11575. }
  11576. else
  11577. {
  11578. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11579. {
  11580. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11581. c++;
  11582. }
  11583. sstr[c] = '\0';
  11584. strcpy(parentIdTagstr, sstr);
  11585. }
  11586. //***(5)reservationId ****/
  11587. c=0;
  11588. loc = strstr(sstrtemp, "reservationId");
  11589. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11590. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11591. {
  11592. sstr[c] = loc[strlen("reservationId")+2+c];
  11593. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11594. c++;
  11595. }
  11596. sstr[c] = '\0';
  11597. reservationIdInt = atoi(sstr);
  11598. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11599. /*
  11600. enum SYSTEM_STATUS
  11601. {
  11602. SYS_MODE_BOOTING = 0,
  11603. SYS_MODE_IDLE = 1,
  11604. SYS_MODE_AUTHORIZING = 2,
  11605. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11606. SYS_MODE_REASSIGN = 4,
  11607. SYS_MODE_PREPARING = 5,
  11608. SYS_MODE_PREPARE_FOR_EV = 6,
  11609. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11610. SYS_MODE_CHARGING = 8,
  11611. SYS_MODE_TERMINATING = 9,
  11612. SYS_MODE_COMPLETE = 10,
  11613. SYS_MODE_ALARM = 11,
  11614. SYS_MODE_FAULT = 12,
  11615. SYS_MODE_RESERVATION = 13,
  11616. SYS_MODE_BOOKING = 14,
  11617. SYS_MODE_MAINTAIN = 15,
  11618. SYS_MODE_DEBUG = 16,
  11619. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11620. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11621. SYS_MODE_UPDATE = 19
  11622. };
  11623. */
  11624. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11625. {
  11626. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11627. goto end;
  11628. }
  11629. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11630. {
  11631. //check Transaction active
  11632. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11633. {
  11634. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11635. {
  11636. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11637. }
  11638. else
  11639. {
  11640. tempIndex = connectorIdInt -1;
  11641. }
  11642. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11643. {
  11644. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11645. {
  11646. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11647. {
  11648. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11649. {
  11650. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11651. {
  11652. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11653. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11654. }
  11655. 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'))
  11656. {
  11657. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11658. }
  11659. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11660. {
  11661. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11662. }
  11663. else
  11664. {
  11665. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11666. }
  11667. }
  11668. 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
  11669. {
  11670. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11671. }
  11672. }
  11673. else
  11674. {
  11675. //replace reservation
  11676. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11677. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11678. }
  11679. }
  11680. } // END FOR CHAdeMO_QUANTITY
  11681. }
  11682. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11683. {
  11684. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11685. {
  11686. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11687. }
  11688. else
  11689. {
  11690. tempIndex = connectorIdInt -1;
  11691. }
  11692. for (int index = 0; index < CCS_QUANTITY; index++)
  11693. {
  11694. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11695. {
  11696. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11697. {
  11698. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11699. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11700. {
  11701. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11702. {
  11703. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11704. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11705. }
  11706. 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'))
  11707. {
  11708. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11709. }
  11710. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11711. {
  11712. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11713. }
  11714. else
  11715. {
  11716. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11717. }
  11718. }
  11719. 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
  11720. {
  11721. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11722. }
  11723. }
  11724. else
  11725. {
  11726. //replace reservation
  11727. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11728. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11729. }
  11730. }
  11731. } // END FOR CCS_QUANTITY
  11732. }
  11733. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11734. {
  11735. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11736. {
  11737. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11738. }
  11739. else
  11740. {
  11741. tempIndex = connectorIdInt -1;
  11742. }
  11743. for (int index = 0; index < GB_QUANTITY; index++)
  11744. {
  11745. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11746. {
  11747. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11748. {
  11749. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11750. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11751. {
  11752. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11753. {
  11754. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11755. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11756. }
  11757. 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'))
  11758. {
  11759. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11760. }
  11761. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11762. {
  11763. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11764. }
  11765. else
  11766. {
  11767. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11768. }
  11769. }
  11770. 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
  11771. {
  11772. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11773. }
  11774. }
  11775. else
  11776. {
  11777. //replace reservation
  11778. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11779. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11780. }
  11781. }
  11782. }// END FOR GB_QUANTITY
  11783. }
  11784. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11785. {
  11786. tempIndex = connectorIdInt -1;
  11787. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11788. {
  11789. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11790. {
  11791. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11792. {
  11793. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11794. 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
  11795. {
  11796. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11797. {
  11798. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11799. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11800. }
  11801. 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'))
  11802. {
  11803. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11804. }
  11805. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11806. {
  11807. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11808. }
  11809. else
  11810. {
  11811. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11812. }
  11813. }
  11814. 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
  11815. {
  11816. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11817. }
  11818. }
  11819. else
  11820. {
  11821. //replace reservation
  11822. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11823. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11824. }
  11825. }
  11826. }// END FOR GB_QUANTITY
  11827. }
  11828. else
  11829. {
  11830. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11831. {
  11832. tempIndex = 2;
  11833. }
  11834. else
  11835. {
  11836. tempIndex = (connectorIdInt -1);
  11837. }
  11838. for (int index = 0; index < AC_QUANTITY; index++)
  11839. {
  11840. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11841. {
  11842. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11843. {
  11844. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11845. {
  11846. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11847. {
  11848. 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))
  11849. {
  11850. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11851. }
  11852. else
  11853. {
  11854. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11855. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11856. }
  11857. }
  11858. 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'))
  11859. {
  11860. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11861. }
  11862. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11863. {
  11864. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11865. }
  11866. else
  11867. {
  11868. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11869. }
  11870. }
  11871. 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
  11872. {
  11873. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11874. }
  11875. }
  11876. else
  11877. {
  11878. //replace reservation
  11879. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11880. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11881. }
  11882. }
  11883. } // END FOR AC_QUANTITY
  11884. }
  11885. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11886. }
  11887. else if(connectorIdInt == 0)
  11888. {
  11889. //check Transaction active
  11890. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11891. {
  11892. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11893. {
  11894. 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'))
  11895. {
  11896. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11897. goto end;
  11898. }
  11899. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11900. {
  11901. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11902. goto end;
  11903. }
  11904. 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
  11905. {
  11906. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11907. goto end;
  11908. }
  11909. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11910. {
  11911. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11912. goto end;
  11913. }
  11914. }
  11915. }// END FOR CHAdeMO_QUANTITY
  11916. for (int index = 0; index < CCS_QUANTITY; index++)
  11917. {
  11918. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11919. {
  11920. 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'))
  11921. {
  11922. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11923. goto end;
  11924. }
  11925. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11926. {
  11927. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11928. goto end;
  11929. }
  11930. 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
  11931. {
  11932. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11933. goto end;
  11934. }
  11935. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11936. {
  11937. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11938. goto end;
  11939. }
  11940. }
  11941. } // END FOR CCS_QUANTITY
  11942. for (int index = 0; index < GB_QUANTITY; index++)
  11943. {
  11944. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11945. {
  11946. 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'))
  11947. {
  11948. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11949. goto end;
  11950. }
  11951. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11952. {
  11953. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11954. goto end;
  11955. }
  11956. 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
  11957. {
  11958. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11959. goto end;
  11960. }
  11961. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11962. {
  11963. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11964. goto end;
  11965. }
  11966. }
  11967. } // END FOR GB_QUANTITY
  11968. for (int index = 0; index < AC_QUANTITY; index++)
  11969. {
  11970. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11971. {
  11972. 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'))
  11973. {
  11974. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11975. goto end;
  11976. }
  11977. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11978. {
  11979. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11980. goto end;
  11981. }
  11982. 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
  11983. {
  11984. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11985. goto end;
  11986. }
  11987. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11988. {
  11989. 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))
  11990. {
  11991. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11992. goto end;
  11993. }
  11994. }
  11995. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11996. {
  11997. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11998. goto end;
  11999. }
  12000. }
  12001. }// END FOR AC_QUANTITY
  12002. //The connectorId is 0
  12003. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  12004. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12005. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  12006. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  12007. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  12008. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  12009. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  12010. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  12011. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  12012. result = TRUE;
  12013. return result;
  12014. }
  12015. else
  12016. {
  12017. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12018. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12019. }
  12020. if(strcmp(comfirmstr,"Accepted") == 0)
  12021. {
  12022. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  12023. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  12024. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  12025. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  12026. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  12027. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12028. result = TRUE;
  12029. return result;
  12030. }
  12031. end:
  12032. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  12033. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  12034. return result;
  12035. }
  12036. int handleResetRequest(char *uuid, char *payload)
  12037. {
  12038. mtrace();
  12039. int result = FAIL;
  12040. char sstr[10]={0},sstrtemp[30]={ 0 };
  12041. char typestr[10]={0};
  12042. char comfirmstr[20]={0};
  12043. int c = 0;
  12044. char *loc;
  12045. DEBUG_INFO("handleResetRequest...\n");
  12046. strcpy(sstrtemp, stringtrimspace(payload));
  12047. loc = strstr(sstrtemp, "type");
  12048. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12049. c = 0;
  12050. while (loc[3+strlen("type")+c] != '\"')
  12051. {
  12052. sstr[c] = loc[3+strlen("type")+c];
  12053. c++;
  12054. }
  12055. sstr[c] = '\0';
  12056. strcpy(typestr,sstr);
  12057. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  12058. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  12059. {
  12060. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  12061. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  12062. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  12063. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12064. }
  12065. else
  12066. {
  12067. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  12068. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12069. result = PASS;
  12070. }
  12071. sendResetConfirmation(uuid, comfirmstr);
  12072. return result;
  12073. }
  12074. int handleSendLocalListRequest(char *uuid, char *payload)
  12075. {
  12076. mtrace();
  12077. int result = FAIL;
  12078. char comfirmstr[20];
  12079. int checkState_Faulted = FALSE;
  12080. json_object *SendLocalList;
  12081. DEBUG_INFO("handleSendLocalListRequest...\n");
  12082. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  12083. {
  12084. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12085. goto end;
  12086. }
  12087. //check Charge Point state
  12088. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12089. {
  12090. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12091. {
  12092. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12093. }
  12094. }
  12095. for (int index = 0; index < CCS_QUANTITY; index++)
  12096. {
  12097. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12098. {
  12099. checkState_Faulted = TRUE; //OCPP Status
  12100. }
  12101. }
  12102. for (int index = 0; index < GB_QUANTITY; index++)
  12103. {
  12104. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12105. {
  12106. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12107. }
  12108. }
  12109. //check Charge Point state
  12110. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12111. {
  12112. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12113. {
  12114. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12115. }
  12116. }
  12117. //check Charge Point state
  12118. for (int index = 0; index < AC_QUANTITY; index++)
  12119. {
  12120. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12121. {
  12122. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12123. }
  12124. }
  12125. if(checkState_Faulted == TRUE)
  12126. {
  12127. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12128. goto end;
  12129. }
  12130. // Parsing payload
  12131. SendLocalList = json_tokener_parse(payload);
  12132. if(!is_error(SendLocalList))
  12133. {
  12134. // Required data
  12135. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12136. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12137. // Optional data
  12138. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12139. {
  12140. //Check UpdateType
  12141. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12142. {
  12143. //Local list full update
  12144. DEBUG_INFO("Local list full update.\n");
  12145. OCPP_getListVerion();
  12146. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12147. {
  12148. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12149. goto end;
  12150. }
  12151. OCPP_cleanLocalList();
  12152. }
  12153. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12154. {
  12155. //Local list different update
  12156. DEBUG_INFO("Local list different update.\n");
  12157. OCPP_getListVerion();
  12158. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12159. {
  12160. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12161. goto end;
  12162. }
  12163. }
  12164. else
  12165. {
  12166. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12167. goto end;
  12168. }
  12169. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12170. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12171. {
  12172. 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")));
  12173. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12174. {
  12175. 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")));
  12176. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12177. 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")));
  12178. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12179. 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")));
  12180. }
  12181. // Add to db
  12182. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12183. {
  12184. //Local list full update
  12185. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12186. idx,
  12187. ShmOCPP16Data->SendLocalList.ListVersion,
  12188. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12189. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12190. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12191. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12192. // update list
  12193. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12194. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12195. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12196. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12197. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12198. }
  12199. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12200. {
  12201. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12202. idx,
  12203. ShmOCPP16Data->SendLocalList.ListVersion,
  12204. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12205. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12206. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12207. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12208. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12209. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12210. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12211. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12212. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12213. }
  12214. }
  12215. }
  12216. else
  12217. {
  12218. //Check UpdateType
  12219. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12220. {
  12221. //Local list full update
  12222. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12223. OCPP_cleanLocalList();
  12224. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12225. goto end;
  12226. }
  12227. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12228. {
  12229. //Local list different update
  12230. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12231. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12232. goto end;
  12233. }
  12234. }
  12235. result = PASS;
  12236. }
  12237. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12238. end:
  12239. json_object_put(SendLocalList);
  12240. sendSendLocalListConfirmation(uuid, comfirmstr);
  12241. return result;
  12242. }
  12243. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12244. {
  12245. mtrace();
  12246. int result = FAIL;
  12247. struct StructSetChargingProfile SetProfileReq = {0};
  12248. int tempchargingProfileIdInt;
  12249. int tempstackLevelInt;
  12250. int chargingSchedulePeriodCount = 0;
  12251. char comfirmstr[20]={0};
  12252. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  12253. char rmFileCmd[128]={0};
  12254. int profileQuantity = 0;
  12255. int isReplaceable = FALSE;
  12256. json_object *SetChargingProfile;
  12257. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12258. SetChargingProfile = json_tokener_parse(payload);
  12259. if(!is_error(SetChargingProfile))
  12260. {
  12261. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12262. {
  12263. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12264. }
  12265. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12266. {
  12267. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12268. {
  12269. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12270. }
  12271. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12272. {
  12273. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12274. }
  12275. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12276. {
  12277. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12278. }
  12279. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12280. {
  12281. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12282. }
  12283. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12284. {
  12285. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12286. }
  12287. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12288. {
  12289. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12290. }
  12291. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12292. {
  12293. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12294. }
  12295. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12296. {
  12297. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12298. }
  12299. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12300. {
  12301. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12302. {
  12303. 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")));
  12304. }
  12305. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12306. {
  12307. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12308. }
  12309. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12310. {
  12311. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12312. }
  12313. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12314. {
  12315. 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")));
  12316. }
  12317. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12318. {
  12319. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12320. if(chargingSchedulePeriodCount <= 10)
  12321. {
  12322. 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++)
  12323. {
  12324. 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)
  12325. {
  12326. 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"));
  12327. }
  12328. 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)
  12329. {
  12330. 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"));
  12331. }
  12332. 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)
  12333. {
  12334. 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"));
  12335. }
  12336. }
  12337. }
  12338. }
  12339. }
  12340. }
  12341. }
  12342. // Profile periods quantity check
  12343. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12344. {
  12345. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12346. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12347. goto end;
  12348. }
  12349. // Check invalid limit
  12350. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12351. {
  12352. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12353. {
  12354. 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)))) ||
  12355. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12356. {
  12357. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12358. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12359. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12360. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12361. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12362. goto end;
  12363. }
  12364. }
  12365. }
  12366. else
  12367. {
  12368. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12369. {
  12370. 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))
  12371. {
  12372. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12373. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12374. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12375. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12376. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12377. goto end;
  12378. }
  12379. }
  12380. }
  12381. // Profile purpose info check
  12382. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12383. {
  12384. FILE *fp;
  12385. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12386. if(SetProfileReq.ConnectorId != 0)
  12387. {
  12388. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12389. DEBUG_WARN("Profile connector id is not 0.\n");
  12390. goto end;
  12391. }
  12392. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12393. if (!fp)
  12394. {
  12395. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12396. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12397. }
  12398. else
  12399. {
  12400. char *line = NULL;
  12401. size_t len = 0;
  12402. while(getline(&line, &len, fp) != -1)
  12403. {
  12404. json_object *obj = NULL;
  12405. obj = json_tokener_parse(line);
  12406. if(is_error(obj))
  12407. {
  12408. DEBUG_ERROR("Parse txProfile from file error.\n");
  12409. }
  12410. else
  12411. {
  12412. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12413. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12414. {
  12415. profileQuantity += 1;
  12416. }
  12417. else
  12418. isReplaceable = TRUE;
  12419. }
  12420. }
  12421. }
  12422. fclose(fp);
  12423. }
  12424. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12425. {
  12426. FILE *fp;
  12427. char filename[128]={0};
  12428. int tmpProfileQuantity;
  12429. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12430. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12431. {
  12432. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12433. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12434. goto end;
  12435. }
  12436. if(SetProfileReq.ConnectorId == 0)
  12437. {
  12438. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12439. {
  12440. tmpProfileQuantity = 0;
  12441. memset(filename, 0, ARRAY_SIZE(filename));
  12442. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12443. fp = fopen(filename, "r");
  12444. if (!fp)
  12445. {
  12446. DEBUG_INFO("%s does not create.\n", filename);
  12447. fp = fopen(filename, "w+");
  12448. }
  12449. else
  12450. {
  12451. char *line = NULL;
  12452. size_t len = 0;
  12453. while(getline(&line, &len, fp) != -1)
  12454. {
  12455. json_object *obj = NULL;
  12456. obj = json_tokener_parse(line);
  12457. if(is_error(obj))
  12458. {
  12459. DEBUG_ERROR("Parse txProfile from file error.\n");
  12460. }
  12461. else
  12462. {
  12463. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12464. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12465. {
  12466. tmpProfileQuantity += 1;
  12467. }
  12468. else
  12469. isReplaceable = TRUE;
  12470. }
  12471. }
  12472. }
  12473. fclose(fp);
  12474. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12475. }
  12476. }
  12477. else
  12478. {
  12479. memset(filename, 0, ARRAY_SIZE(filename));
  12480. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12481. fp = fopen(filename, "r");
  12482. if (!fp)
  12483. {
  12484. DEBUG_INFO("%s does not create.\n", filename);
  12485. fp = fopen(filename, "w+");
  12486. }
  12487. else
  12488. {
  12489. char *line = NULL;
  12490. size_t len = 0;
  12491. while(getline(&line, &len, fp) != -1)
  12492. {
  12493. json_object *obj = NULL;
  12494. obj = json_tokener_parse(line);
  12495. if(is_error(obj))
  12496. {
  12497. DEBUG_ERROR("Parse txProfile from file error.\n");
  12498. }
  12499. else
  12500. {
  12501. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12502. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12503. {
  12504. profileQuantity += 1;
  12505. }
  12506. else
  12507. isReplaceable = TRUE;
  12508. }
  12509. }
  12510. }
  12511. fclose(fp);
  12512. }
  12513. }
  12514. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12515. {
  12516. int isMatchTransactiodId= FALSE;
  12517. FILE *fp;
  12518. char filename[128]={0};
  12519. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12520. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12521. if(SetProfileReq.ConnectorId == 0)
  12522. {
  12523. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12524. DEBUG_WARN("Profile connector id is 0.\n");
  12525. goto end;
  12526. }
  12527. int tempIndex = 0;
  12528. //check Transaction active
  12529. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12530. {
  12531. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12532. {
  12533. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12534. }
  12535. else
  12536. {
  12537. tempIndex = SetProfileReq.ConnectorId -1;
  12538. }
  12539. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12540. {
  12541. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12542. {
  12543. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12544. {
  12545. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12546. {
  12547. isMatchTransactiodId = TRUE;
  12548. break;
  12549. }
  12550. }
  12551. }
  12552. }
  12553. }
  12554. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12555. {
  12556. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12557. {
  12558. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12559. }
  12560. else
  12561. {
  12562. tempIndex = SetProfileReq.ConnectorId -1;
  12563. }
  12564. for (int index = 0; index < CCS_QUANTITY; index++)
  12565. {
  12566. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12567. {
  12568. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12569. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12570. {
  12571. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12572. {
  12573. isMatchTransactiodId = TRUE;
  12574. break;
  12575. }
  12576. }
  12577. }
  12578. }
  12579. }
  12580. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12581. {
  12582. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12583. {
  12584. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12585. }
  12586. else
  12587. {
  12588. tempIndex = SetProfileReq.ConnectorId -1;
  12589. }
  12590. for (int index = 0; index < GB_QUANTITY; index++)
  12591. {
  12592. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12593. {
  12594. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12595. {
  12596. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12597. {
  12598. isMatchTransactiodId = TRUE;
  12599. break;
  12600. }
  12601. }
  12602. }
  12603. }
  12604. }
  12605. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12606. {
  12607. tempIndex = SetProfileReq.ConnectorId -1;
  12608. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12609. {
  12610. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12611. {
  12612. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12613. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12614. {
  12615. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12616. {
  12617. isMatchTransactiodId = TRUE;
  12618. break;
  12619. }
  12620. }
  12621. }
  12622. }
  12623. }
  12624. else
  12625. {
  12626. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12627. {
  12628. tempIndex = 2;
  12629. }
  12630. else
  12631. {
  12632. tempIndex = (SetProfileReq.ConnectorId -1);
  12633. }
  12634. for (int index = 0; index < AC_QUANTITY; index++)
  12635. {
  12636. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12637. {
  12638. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12639. {
  12640. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12641. {
  12642. isMatchTransactiodId = TRUE;
  12643. break;
  12644. }
  12645. }
  12646. }
  12647. }
  12648. }
  12649. //check Transaction active
  12650. if(isMatchTransactiodId == FALSE)
  12651. {
  12652. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12653. DEBUG_WARN("Tx profile transaction id is not match.\n");
  12654. goto end;
  12655. }
  12656. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12657. {
  12658. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12659. DEBUG_WARN("Connector id is over max gun number.\n");
  12660. goto end;
  12661. }
  12662. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12663. fp = fopen(filename, "r");
  12664. if (!fp)
  12665. {
  12666. DEBUG_INFO("%s does not create.\n", filename);
  12667. fp = fopen(filename, "w+");
  12668. }
  12669. else
  12670. {
  12671. char *line = NULL;
  12672. size_t len = 0;
  12673. while(getline(&line, &len, fp) != -1)
  12674. {
  12675. json_object *obj = NULL;
  12676. obj = json_tokener_parse(line);
  12677. if(is_error(obj))
  12678. {
  12679. DEBUG_ERROR("Parse txProfile from file error.\n");
  12680. }
  12681. else
  12682. {
  12683. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12684. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12685. {
  12686. profileQuantity += 1;
  12687. }
  12688. else
  12689. isReplaceable = TRUE;
  12690. }
  12691. }
  12692. }
  12693. fclose(fp);
  12694. }
  12695. // Check ChargeProfileMaxStackLevel
  12696. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12697. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12698. {
  12699. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12700. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12701. goto end;
  12702. }
  12703. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12704. {
  12705. FILE *fp;
  12706. char dataLine[4096]={0};
  12707. char fnametemp[128]={0};
  12708. int tmpProfileQuantity;
  12709. //Check ChargePointMaxProfile.json exit
  12710. profileQuantity = 0;
  12711. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12712. {
  12713. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  12714. //Check Charging Profile Count
  12715. tmpProfileQuantity = 0;
  12716. while(fscanf(fp, "%s", dataLine) != EOF)
  12717. {
  12718. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12719. {
  12720. profileQuantity += 1;
  12721. tmpProfileQuantity += 1;
  12722. }
  12723. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12724. }
  12725. fclose(fp);
  12726. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12727. }
  12728. //Check TxDefaultProfile_%d.json
  12729. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12730. {
  12731. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12732. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12733. if((access(fnametemp,F_OK))!=-1)
  12734. {
  12735. fp = fopen(fnametemp, "r");
  12736. //Check Charging Profile Count
  12737. tmpProfileQuantity = 0;
  12738. while(fscanf(fp, "%s", dataLine) != EOF)
  12739. {
  12740. //DEBUG_INFO("word=%s\n",word);
  12741. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12742. {
  12743. profileQuantity += 1;
  12744. tmpProfileQuantity += 1;
  12745. }
  12746. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12747. }
  12748. fclose(fp);
  12749. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12750. }
  12751. }
  12752. //Check TxProfile_%d.json
  12753. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12754. {
  12755. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12756. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  12757. if((access(fnametemp,F_OK))!=-1)
  12758. {
  12759. fp = fopen(fnametemp, "r");
  12760. //Check Charging Profile Count
  12761. tmpProfileQuantity = 0;
  12762. while(fscanf(fp, "%s", dataLine) != EOF)
  12763. {
  12764. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12765. {
  12766. profileQuantity += 1;
  12767. tmpProfileQuantity += 1;
  12768. }
  12769. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12770. }
  12771. fclose(fp);
  12772. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12773. }
  12774. }
  12775. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12776. if((profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData)) && (isReplaceable != TRUE))
  12777. {
  12778. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12779. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12780. goto end;
  12781. }
  12782. }
  12783. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12784. //**********************************Write to File********************************************************/
  12785. {
  12786. FILE *infile;
  12787. FILE *outfile;
  12788. char dataLine[4096]={0};
  12789. char filename[128]={0};
  12790. int chkChar=0;
  12791. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12792. {
  12793. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12794. {
  12795. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12796. }
  12797. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12798. {
  12799. if(SetProfileReq.ConnectorId==0)
  12800. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12801. else
  12802. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12803. }
  12804. else
  12805. {
  12806. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12807. }
  12808. infile = fopen (filename, "r");
  12809. outfile = fopen (tempfile, "w");
  12810. chkChar = fgetc(infile);
  12811. rewind(infile);
  12812. if(chkChar == EOF)
  12813. {
  12814. // Profile is empty
  12815. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12816. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12817. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12818. fclose(infile);
  12819. fclose(outfile);
  12820. sprintf(rmFileCmd,"rm -f %s",filename);
  12821. system(rmFileCmd);
  12822. rename(tempfile, filename);
  12823. }
  12824. else
  12825. {
  12826. // Profile is not empty
  12827. int ChargingProfileAdded = FALSE;
  12828. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12829. {
  12830. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12831. json_object *tmpChargingProfile;
  12832. tmpChargingProfile = json_tokener_parse(dataLine);
  12833. if(!is_error(SetChargingProfile))
  12834. {
  12835. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12836. {
  12837. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12838. {
  12839. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12840. }
  12841. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12842. {
  12843. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  12844. }
  12845. }
  12846. }
  12847. json_object_put(tmpChargingProfile);
  12848. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12849. {
  12850. if(ChargingProfileAdded == FALSE)
  12851. {
  12852. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12853. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12854. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12855. ChargingProfileAdded = TRUE;
  12856. }
  12857. }
  12858. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  12859. {
  12860. if(ChargingProfileAdded == FALSE)
  12861. {
  12862. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12863. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12864. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12865. ChargingProfileAdded = TRUE;
  12866. }
  12867. }
  12868. else
  12869. {
  12870. fprintf(outfile,"%s\n",dataLine);
  12871. if(ChargingProfileAdded == FALSE)
  12872. {
  12873. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12874. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12875. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12876. ChargingProfileAdded = TRUE;
  12877. }
  12878. }
  12879. } // end of while loop
  12880. fclose(infile);
  12881. fclose(outfile);
  12882. sprintf(rmFileCmd,"rm -f %s",filename);
  12883. system(rmFileCmd);
  12884. rename(tempfile, filename);
  12885. }
  12886. }
  12887. sleep(1);
  12888. result = TRUE;
  12889. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12890. }
  12891. end:
  12892. json_object_put(SetChargingProfile);
  12893. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12894. {
  12895. if(SetProfileReq.ConnectorId == 0)
  12896. {
  12897. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12898. {
  12899. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  12900. }
  12901. }
  12902. else
  12903. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12904. }
  12905. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12906. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12907. return result;
  12908. }
  12909. int handleTriggerMessageRequest(char *uuid, char *payload)
  12910. {
  12911. mtrace();
  12912. int result = FAIL;
  12913. int connectorIdIsNULL = FALSE;
  12914. int connectorIdInt =0;
  12915. char sstr[40]={0},sstrtemp[100]={ 0 };
  12916. char requestedMessagestr[40]={0};
  12917. char comfirmstr[20]={0};
  12918. int c = 0;
  12919. char *loc;
  12920. DEBUG_INFO("handleTriggerMessageRequest\n");
  12921. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12922. strcpy(sstrtemp, stringtrimspace(payload));
  12923. c = 0;
  12924. loc = strstr(sstrtemp, "requestedMessage");
  12925. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12926. {
  12927. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12928. c++;
  12929. }
  12930. sstr[c] = '\0';
  12931. strcpy(requestedMessagestr, sstr);
  12932. c = 0;
  12933. loc = strstr(sstrtemp, "connectorId");
  12934. if(loc == NULL)
  12935. {
  12936. connectorIdIsNULL = TRUE;
  12937. }
  12938. else
  12939. {
  12940. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12941. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12942. {
  12943. sstr[c] = loc[strlen("connectorId")+2+c];
  12944. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12945. c++;
  12946. }
  12947. sstr[c] = '\0';
  12948. connectorIdInt = atoi(sstr);
  12949. }
  12950. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12951. {
  12952. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12953. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12954. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12955. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12956. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12957. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12958. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12959. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12960. {
  12961. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12962. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12963. return TRUE;
  12964. }
  12965. else
  12966. {
  12967. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12968. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12969. }
  12970. }
  12971. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12972. {
  12973. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12974. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12975. return TRUE;
  12976. }
  12977. //==========================
  12978. // Trigger message
  12979. //==========================
  12980. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12981. {
  12982. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  12983. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12984. {
  12985. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12986. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12987. }
  12988. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12989. }
  12990. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12991. {
  12992. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  12993. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12994. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12995. }
  12996. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12997. {
  12998. //sendBootNotificationRequest();
  12999. server_sign = FALSE;
  13000. }
  13001. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  13002. {
  13003. refreshStartTimer(&clientTime.Heartbeat);
  13004. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13005. }
  13006. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  13007. {
  13008. if(connectorIdIsNULL == FALSE)
  13009. {
  13010. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13011. {
  13012. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  13013. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  13014. }
  13015. }
  13016. else
  13017. {
  13018. for(int idx=0;idx< gunTotalNumber;idx++)
  13019. {
  13020. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13021. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13022. }
  13023. }
  13024. }
  13025. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  13026. {
  13027. if(connectorIdIsNULL == FALSE)
  13028. {
  13029. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13030. {
  13031. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  13032. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  13033. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13034. }
  13035. }
  13036. else
  13037. {
  13038. for(int idx=0;idx< gunTotalNumber;idx++)
  13039. {
  13040. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  13041. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13042. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13043. }
  13044. }
  13045. }
  13046. return result;
  13047. }
  13048. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13049. {
  13050. mtrace();
  13051. int result = FAIL;
  13052. int connectorIdInt =0;
  13053. char comfirmstr[20]={0};
  13054. int tempIndex = 0;
  13055. json_object *UnlockConnector;
  13056. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13057. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13058. UnlockConnector = json_tokener_parse(payload);
  13059. if(!is_error(UnlockConnector))
  13060. {
  13061. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13062. {
  13063. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13064. }
  13065. }
  13066. json_object_put(UnlockConnector);
  13067. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13068. if(gunTotalNumber == 0)
  13069. {
  13070. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13071. goto end;
  13072. }
  13073. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13074. {
  13075. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13076. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13077. goto end;
  13078. }
  13079. else
  13080. {
  13081. //check Transaction active
  13082. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13083. {
  13084. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13085. {
  13086. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13087. }
  13088. else
  13089. {
  13090. tempIndex = connectorIdInt -1;
  13091. }
  13092. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13093. {
  13094. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13095. {
  13096. //stop Transaction
  13097. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13098. }
  13099. }
  13100. }
  13101. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13102. {
  13103. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13104. {
  13105. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13106. }
  13107. else
  13108. {
  13109. tempIndex = connectorIdInt -1;
  13110. }
  13111. for (int index = 0; index < CCS_QUANTITY; index++)
  13112. {
  13113. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13114. {
  13115. //stop Transaction
  13116. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13117. }
  13118. }
  13119. }
  13120. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13121. {
  13122. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13123. {
  13124. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13125. }
  13126. else
  13127. {
  13128. tempIndex = connectorIdInt -1;
  13129. }
  13130. for (int index = 0; index < GB_QUANTITY; index++)
  13131. {
  13132. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13133. {
  13134. //stop Transaction
  13135. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13136. }
  13137. }
  13138. }
  13139. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13140. {
  13141. tempIndex = connectorIdInt -1;
  13142. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13143. {
  13144. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13145. {
  13146. //stop Transaction
  13147. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13148. }
  13149. }
  13150. }
  13151. else
  13152. {
  13153. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13154. {
  13155. tempIndex = 2;
  13156. }
  13157. else
  13158. {
  13159. tempIndex = connectorIdInt-1;
  13160. }
  13161. for (int index = 0; index < AC_QUANTITY; index++)
  13162. {
  13163. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  13164. {
  13165. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13166. }
  13167. }
  13168. }
  13169. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  13170. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  13171. result = TRUE;
  13172. return result;
  13173. }
  13174. end:
  13175. //json_object_put(obj); --- remove temporally
  13176. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  13177. return result;
  13178. }
  13179. static char UpdateFirmwarepayloadData[300]={0};
  13180. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13181. {
  13182. mtrace();
  13183. int result = FAIL;
  13184. pthread_t t;
  13185. sendUpdateFirmwareConfirmation(uuid);
  13186. memset(UpdateFirmwarepayloadData, 0, 300);
  13187. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  13188. if(!interLock.isUpdateFirmwareGoing)
  13189. {
  13190. interLock.isUpdateFirmwareGoing = 1;
  13191. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  13192. sleep(1);
  13193. }
  13194. else
  13195. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13196. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  13197. return result;
  13198. }
  13199. void *UpdateFirmwareProcess(void *data)
  13200. {
  13201. pthread_detach(pthread_self());
  13202. mtrace();
  13203. int retriesInt =0, retryIntervalInt=0;
  13204. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  13205. int port=0;
  13206. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  13207. int isSuccess = 0;
  13208. char ftpbuf[1024];
  13209. char temp[1024];
  13210. char * pch;
  13211. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13212. json_object *UpdateFirmware;
  13213. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  13214. if(!is_error(UpdateFirmware))
  13215. {
  13216. // Required data
  13217. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13218. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13219. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13220. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13221. // Optional data
  13222. if(json_object_object_get(UpdateFirmware, "retries"))
  13223. {
  13224. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13225. }
  13226. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13227. {
  13228. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13229. }
  13230. }
  13231. json_object_put(UpdateFirmware);
  13232. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13233. memset(path, 0, ARRAY_SIZE(path));
  13234. // Wait retrieveData
  13235. if(strlen(retrieveDatestr) > 10)
  13236. {
  13237. do
  13238. {
  13239. sleep(1);
  13240. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13241. }
  13242. // Ready to download
  13243. system("rm -f /mnt/*");
  13244. if(strncmp(locationstr,"http", 4) == 0)
  13245. {
  13246. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13247. sprintf(ftppath,"/%s", path);
  13248. DEBUG_INFO("locationstr: %s\n", locationstr);
  13249. DEBUG_INFO("protocol: %s\n",protocol);
  13250. DEBUG_INFO("host: %s\n",host);
  13251. DEBUG_INFO("path: %s\n",path);
  13252. DEBUG_INFO("ftppath: %s\n",ftppath);
  13253. int ftppathlen=strlen(ftppath);
  13254. int i=1;
  13255. char filenametemp[50];
  13256. while(i < ftppathlen)
  13257. {
  13258. int len=ftppathlen-i;
  13259. if(ftppath[len]== 47) // '/' ascll code: 47
  13260. {
  13261. DEBUG_INFO("compare '/' all right\n");
  13262. break;
  13263. }
  13264. i=i+1;
  13265. }
  13266. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13267. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13268. filenametemp[i+1] = 0;
  13269. do
  13270. {
  13271. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13272. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13273. sleep(1);
  13274. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13275. if(!isSuccess)
  13276. {
  13277. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13278. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13279. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13280. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13281. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13282. }
  13283. else
  13284. {
  13285. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13286. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13287. }
  13288. retriesInt--;
  13289. }while((isSuccess == 0)&&(retriesInt >= 0));
  13290. }
  13291. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13292. {
  13293. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13294. memset(temp, 0, ARRAY_SIZE(temp));
  13295. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13296. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13297. int ftppathlen=strlen(ftpbuf);
  13298. int i=1;
  13299. char filenametemp[50];
  13300. while(i < ftppathlen)
  13301. {
  13302. int len=ftppathlen-i;
  13303. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13304. {
  13305. DEBUG_INFO(" compare '/' all right\n");
  13306. break;
  13307. }
  13308. i=i+1;
  13309. }
  13310. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13311. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13312. filenametemp[i+1] = 0;
  13313. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13314. pch=strchr(temp,'@');
  13315. if(pch==NULL)
  13316. {
  13317. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13318. protocol, host, &port, path);
  13319. strcpy(user,"anonymous");
  13320. strcpy(password,"");
  13321. }
  13322. else
  13323. {
  13324. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13325. protocol, user, password, host, &port, path);
  13326. }
  13327. sscanf(host,"%[^/]%s",host1, path1);
  13328. sprintf(ftppath,"%s", path1);
  13329. //DEBUG_INFO("protocol =%s\n",protocol);
  13330. //DEBUG_INFO("user =%s\n",user);
  13331. //DEBUG_INFO("password =%s\n",password);
  13332. //DEBUG_INFO("host1 =%s\n",host1);
  13333. //DEBUG_INFO("port =%d\n",port);
  13334. //DEBUG_INFO("path1 =%s\n",path1);
  13335. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13336. //ftpFile(host, user, password, port, ftppath, fname);
  13337. //download firmware pthred
  13338. if(port == 0)
  13339. {
  13340. port = 21;
  13341. }
  13342. do
  13343. {
  13344. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13345. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13346. sleep(1);
  13347. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13348. if(!isSuccess)
  13349. {
  13350. //BulldogUtil.sleepMs(interval*1000);
  13351. DEBUG_INFO("Update firmware request and download file fail.\n");
  13352. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13353. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13354. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13355. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13356. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13357. }
  13358. else
  13359. {
  13360. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13361. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13362. }
  13363. retriesInt--;
  13364. }while((!isSuccess)&&(retriesInt >= 0));
  13365. }
  13366. else
  13367. {
  13368. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13369. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13370. sleep(1);
  13371. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13372. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13373. }
  13374. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13375. interLock.isUpdateFirmwareGoing = 0;
  13376. pthread_exit(NULL);
  13377. }
  13378. int handleCertificateSignedRequest(char *uuid, char *payload)
  13379. {
  13380. mtrace();
  13381. int result = PASS;
  13382. json_object *CertificateSigned;
  13383. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13384. CertificateSigned = json_tokener_parse(payload);
  13385. if(!is_error(CertificateSigned))
  13386. {
  13387. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13388. }
  13389. json_object_put(CertificateSigned);
  13390. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  13391. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  13392. fclose(fp);
  13393. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13394. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  13395. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  13396. sendCertificateSignedConfirmation(uuid);
  13397. return result;
  13398. }
  13399. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13400. {
  13401. mtrace();
  13402. int result = PASS;
  13403. json_object *DeleteCertificate;
  13404. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13405. DeleteCertificate = json_tokener_parse(payload);
  13406. if(!is_error(DeleteCertificate))
  13407. {
  13408. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13409. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13410. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13411. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13412. }
  13413. json_object_put(DeleteCertificate);
  13414. /*
  13415. * TODO: Delete certificateSigned process
  13416. */
  13417. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  13418. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  13419. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  13420. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  13421. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  13422. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  13423. sendDeleteCertificateConfirmation(uuid);
  13424. return result;
  13425. }
  13426. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13427. {
  13428. mtrace();
  13429. int result = PASS;
  13430. json_object *ExtendedTriggerMessage;
  13431. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13432. ExtendedTriggerMessage = json_tokener_parse(payload);
  13433. if(!is_error(ExtendedTriggerMessage))
  13434. {
  13435. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13436. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13437. {
  13438. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13439. }
  13440. else
  13441. {
  13442. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  13443. }
  13444. }
  13445. json_object_put(ExtendedTriggerMessage);
  13446. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  13447. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  13448. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13449. {
  13450. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13451. }
  13452. else
  13453. {
  13454. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13455. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13456. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13457. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13458. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13459. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13460. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13461. {
  13462. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13463. }
  13464. else
  13465. {
  13466. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13467. }
  13468. }
  13469. sendExtendedTriggerMessageConfirmation(uuid);
  13470. //==========================
  13471. // Trigger message
  13472. //==========================
  13473. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13474. {
  13475. //sendBootNotificationRequest();
  13476. server_sign = FALSE;
  13477. }
  13478. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13479. {
  13480. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13481. }
  13482. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13483. {
  13484. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13485. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13486. {
  13487. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13488. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13489. }
  13490. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13491. }
  13492. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13493. {
  13494. refreshStartTimer(&clientTime.Heartbeat);
  13495. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13496. }
  13497. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13498. {
  13499. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13500. {
  13501. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13502. }
  13503. else
  13504. {
  13505. for(int idx=0;idx< gunTotalNumber;idx++)
  13506. {
  13507. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13508. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13509. }
  13510. }
  13511. }
  13512. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13513. {
  13514. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  13515. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  13516. {
  13517. 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\" &");
  13518. }
  13519. }
  13520. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13521. {
  13522. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13523. {
  13524. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13525. }
  13526. else
  13527. {
  13528. for(int idx=0;idx< gunTotalNumber;idx++)
  13529. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13530. }
  13531. }
  13532. return result;
  13533. }
  13534. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13535. {
  13536. mtrace();
  13537. int result = PASS;
  13538. json_object *GetInstalledCertificateIds;
  13539. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13540. GetInstalledCertificateIds = json_tokener_parse(payload);
  13541. if(!is_error(GetInstalledCertificateIds))
  13542. {
  13543. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13544. }
  13545. json_object_put(GetInstalledCertificateIds);
  13546. /*
  13547. * TODO: Return installed certificate process
  13548. */
  13549. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13550. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  13551. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13552. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13553. sendGetInstalledCertificateIdsConfirmation(uuid);
  13554. return result;
  13555. }
  13556. int handleGetLogRequest(char *uuid, char *payload)
  13557. {
  13558. mtrace();
  13559. int result = PASS;
  13560. json_object *GetLog;
  13561. DEBUG_INFO("handleGetLogRequest...\n");
  13562. GetLog = json_tokener_parse(payload);
  13563. if(!is_error(GetLog))
  13564. {
  13565. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13566. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13567. if(json_object_object_get(GetLog, "retries") != NULL)
  13568. {
  13569. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13570. }
  13571. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13572. {
  13573. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13574. }
  13575. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13576. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13577. {
  13578. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13579. }
  13580. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13581. {
  13582. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13583. }
  13584. }
  13585. json_object_put(GetLog);
  13586. /*
  13587. * TODO: Upload log process
  13588. */
  13589. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  13590. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  13591. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  13592. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  13593. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  13594. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  13595. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  13596. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  13597. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  13598. sendGetLogConfirmation(uuid);
  13599. return result;
  13600. }
  13601. int handleInstallCertificateRequest(char *uuid, char *payload)
  13602. {
  13603. mtrace();
  13604. int result = PASS;
  13605. json_object *InstallCertificate;
  13606. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13607. InstallCertificate = json_tokener_parse(payload);
  13608. if(!is_error(InstallCertificate))
  13609. {
  13610. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13611. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13612. /*
  13613. * TODO: Install certificate process
  13614. */
  13615. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  13616. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  13617. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  13618. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  13619. sendInstallCertificateConfirmation(uuid);
  13620. }
  13621. json_object_put(InstallCertificate);
  13622. return result;
  13623. }
  13624. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13625. {
  13626. mtrace();
  13627. int result = PASS;
  13628. json_object *SignedUpdateFirmware;
  13629. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13630. SignedUpdateFirmware = json_tokener_parse(payload);
  13631. if(!is_error(SignedUpdateFirmware))
  13632. {
  13633. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13634. {
  13635. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13636. }
  13637. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13638. {
  13639. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13640. }
  13641. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13642. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13643. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13644. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13645. {
  13646. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13647. }
  13648. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13649. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13650. }
  13651. json_object_put(SignedUpdateFirmware);
  13652. /*
  13653. * TODO: Upgrade firmware process
  13654. */
  13655. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13656. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  13657. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  13658. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  13659. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  13660. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  13661. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  13662. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  13663. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  13664. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  13665. sendInstallCertificateConfirmation(uuid);
  13666. return result;
  13667. }
  13668. int handleUnknownRequest(char *uuid, char *payload)
  13669. {
  13670. mtrace();
  13671. int result = PASS;
  13672. DEBUG_INFO("handleUnknownRequest...\n");
  13673. sendUnknownConfirmation(uuid);
  13674. result = PASS;
  13675. return result;
  13676. }
  13677. //==========================================
  13678. // Handle server response routine
  13679. //==========================================
  13680. void handleAuthorizeResponse(char *payload, int gun_index)
  13681. {
  13682. mtrace();
  13683. char expiryDatestr[30]={0};
  13684. char parentIdTagstr[20]={0};
  13685. char statusstr[20]={0};
  13686. int expiryDateISNULL=FALSE;
  13687. int parentIdTagISNULL=FALSE;
  13688. DEBUG_INFO("handleAuthorizeResponse...\n");
  13689. json_object *Authorize;
  13690. Authorize = json_tokener_parse(payload);
  13691. if(!is_error(Authorize))
  13692. {
  13693. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13694. {
  13695. // Required data
  13696. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13697. // Optional data
  13698. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13699. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13700. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13701. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13702. }
  13703. }
  13704. json_object_put(Authorize);
  13705. if(expiryDateISNULL == FALSE)
  13706. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13707. if(parentIdTagISNULL == FALSE)
  13708. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13709. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  13710. //Update idTag information to authorization cache if supproted
  13711. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13712. {
  13713. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13714. }
  13715. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  13716. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13717. authorizeRetryTimes = 0;
  13718. }
  13719. void handleBootNotificationResponse(char *payload, int gun_index)
  13720. {
  13721. mtrace();
  13722. char statusStr[12]={0};
  13723. char currentTimeStr[30]={0};
  13724. int intervalInt = 0;
  13725. DEBUG_INFO("handleBootNotificationResponse...\n");
  13726. json_object *BootNotification;
  13727. BootNotification = json_tokener_parse(payload);
  13728. if(!is_error(BootNotification))
  13729. {
  13730. // Required data
  13731. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13732. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13733. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13734. }
  13735. json_object_put(BootNotification);
  13736. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13737. BootNotificationInterval = intervalInt;
  13738. //write back to ShmOCPP16Data->BootNotification
  13739. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  13740. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13741. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  13742. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13743. {
  13744. BootNotificationInterval = 0;
  13745. if((intervalInt == 0) || (intervalInt >= 10))
  13746. {
  13747. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13748. HeartBeatWaitTime = intervalInt;
  13749. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13750. }
  13751. server_sign = TRUE;
  13752. server_pending =FALSE;
  13753. }
  13754. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13755. {
  13756. server_pending = TRUE;
  13757. }
  13758. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  13759. srand(time(NULL));
  13760. refreshStartTimer(&clientTime.Heartbeat);
  13761. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13762. SetOcppConnStatus(TRUE);
  13763. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  13764. }
  13765. void handleDataTransferResponse(char *payload, int gun_index)
  13766. {
  13767. json_object *DataTransfer = json_tokener_parse(payload);
  13768. if(!is_error(DataTransfer))
  13769. {
  13770. // Required data
  13771. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13772. // Optional data
  13773. if(json_object_object_get(DataTransfer, "data") != NULL)
  13774. {
  13775. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13776. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13777. if(!is_error(Data))
  13778. {
  13779. if(json_object_object_get(Data, "msgId") != NULL)
  13780. {
  13781. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13782. {
  13783. 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")));
  13784. }
  13785. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_ReaderStatus") != NULL)
  13786. {
  13787. if(json_object_object_get(Data, "ConnectorId") != NULL)
  13788. ShmOCPP16Data->TcciCustomData.ReaderStatus[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].ReportReaderStatusReq = 0;
  13789. }
  13790. }
  13791. }
  13792. json_object_put(Data);
  13793. }
  13794. }
  13795. json_object_put(DataTransfer);
  13796. }
  13797. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13798. {
  13799. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13800. //struct json_object *obj;
  13801. // obj = json_tokener_parse(payload);
  13802. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13803. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13804. //No fields are defined.
  13805. }
  13806. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13807. {
  13808. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13809. //struct json_object *obj;
  13810. // obj = json_tokener_parse(payload);
  13811. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13812. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13813. //No fields are defined.
  13814. }
  13815. void handleHeartbeatResponse(char *payload, int gun_index)
  13816. {
  13817. mtrace();
  13818. DEBUG_INFO("handleHeartbeatResponse...\n");
  13819. json_object *Heartbeat;
  13820. Heartbeat = json_tokener_parse(payload);
  13821. if(!is_error(Heartbeat))
  13822. {
  13823. // Required data
  13824. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13825. }
  13826. json_object_put(Heartbeat);
  13827. if(FirstHeartBeat == 0)
  13828. {
  13829. FirstHeartBeat = 1;
  13830. DEBUG_INFO("FirstHeartBeat \n");
  13831. }
  13832. HeartBeatWithNOResponse = 0;
  13833. refreshStartTimer(&clientTime.Heartbeat);
  13834. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  13835. }
  13836. void handleMeterValuesResponse(char *payload, int gun_index)
  13837. {
  13838. mtrace();
  13839. DEBUG_INFO("handleMeterValuesResponse...\n");
  13840. isQueueSendable = 1;
  13841. }
  13842. void handleStartTransactionResponse(char *payload, int gun_index)
  13843. {
  13844. mtrace();
  13845. //int transactionIdInt = 0;
  13846. FILE *outfile;
  13847. char data[100]={0};
  13848. DEBUG_INFO("handleStartTransactionResponse...\n");
  13849. json_object *StartTransaction;
  13850. StartTransaction = json_tokener_parse(payload);
  13851. if(!is_error(StartTransaction))
  13852. {
  13853. // Required data
  13854. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13855. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13856. // Optional data
  13857. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13858. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13859. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13860. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13861. }
  13862. json_object_put(StartTransaction);
  13863. isQueueSendable = 1;
  13864. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13865. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13866. //-----------Start : write to the Queue TransactionId file -----------------//
  13867. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  13868. {}
  13869. else
  13870. {
  13871. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  13872. if(log == NULL)
  13873. {
  13874. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13875. return ;
  13876. }
  13877. else
  13878. {
  13879. fclose(log);
  13880. }
  13881. }
  13882. // open file for writing
  13883. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13884. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  13885. {
  13886. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  13887. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13888. fputs(data, outfile);
  13889. fclose (outfile);
  13890. }
  13891. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13892. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13893. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13894. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  13895. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13896. }
  13897. void handleStatusNotificationResponse(char *payload, int gun_index)
  13898. {
  13899. mtrace();
  13900. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13901. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13902. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13903. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13904. }
  13905. void handleStopTransactionnResponse(char *payload, int gun_index)
  13906. {
  13907. mtrace();
  13908. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13909. json_object *StopTransaction;
  13910. StopTransaction = json_tokener_parse(payload);
  13911. if(!is_error(StopTransaction))
  13912. {
  13913. // Optional data
  13914. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13915. {
  13916. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13917. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13918. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13919. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13920. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13921. }
  13922. }
  13923. json_object_put(StopTransaction);
  13924. isQueueSendable = 1;
  13925. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13926. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13927. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13928. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13929. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13930. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13931. }
  13932. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13933. {
  13934. mtrace();
  13935. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13936. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  13937. }
  13938. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13939. {
  13940. mtrace();
  13941. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13942. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  13943. }
  13944. void handleSignCertificateResponse(char *payload, int gun_index)
  13945. {
  13946. mtrace();
  13947. DEBUG_INFO("handleSignCertificateResponse...\n");
  13948. json_object *SignCertificate;
  13949. SignCertificate = json_tokener_parse(payload);
  13950. if(!is_error(SignCertificate))
  13951. {
  13952. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13953. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  13954. }
  13955. json_object_put(SignCertificate);
  13956. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  13957. }
  13958. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13959. {
  13960. mtrace();
  13961. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13962. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13963. }
  13964. //==========================================
  13965. // Handle Error routine
  13966. //==========================================
  13967. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13968. {
  13969. mtrace();
  13970. #ifdef SystemLogMessage
  13971. DEBUG_INFO("errorCode: %s\n", errorCode);
  13972. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13973. DEBUG_INFO("errorDetails: %s\n", payload);
  13974. #endif
  13975. }
  13976. //===============================================
  13977. // Common routine
  13978. //===============================================
  13979. int initialConfigurationTable(void)
  13980. {
  13981. //clock_t start_t, end_t, total_t;
  13982. FILE *fp;
  13983. FILE *outfile;
  13984. char str[512]={0};
  13985. char sstr[256]={0};
  13986. int c = 0;
  13987. char *loc;
  13988. int confVersion = 14;
  13989. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13990. //start_t = clock();
  13991. //printf("Starting of the program, start_t = %ld\n", start_t);
  13992. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13993. // Check configuration file size is correct
  13994. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  13995. {
  13996. struct stat st;
  13997. stat("/Storage/OCPP/OCPPConfiguration", &st);
  13998. if(st.st_size < 3100)
  13999. {
  14000. system("rm -f /Storage/OCPP/OCPPConfiguration");
  14001. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  14002. }
  14003. }
  14004. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  14005. {
  14006. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14007. if(outfile == NULL)
  14008. {
  14009. DEBUG_INFO("Error opening file\n");
  14010. return FALSE;
  14011. }
  14012. /*Core Profile*/
  14013. //AllowOfflineTxForUnknownId
  14014. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14015. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14016. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  14017. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14018. //AuthorizationCacheEnabled
  14019. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14022. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14023. //AuthorizeRemoteTxRequests
  14024. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14025. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14026. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  14027. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14028. //BlinkRepeat
  14029. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14030. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14031. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14032. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14033. //ClockAlignedDataInterval
  14034. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14036. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14037. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14038. //ConnectionTimeOut
  14039. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14040. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14042. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14043. //GetConfigurationMaxKeys
  14044. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14045. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14046. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  14047. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14048. // HeartbeatInterval
  14049. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  14052. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14053. // LightIntensity
  14054. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14057. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14058. // LocalAuthorizeOffline
  14059. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  14060. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14062. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14063. // LocalPreAuthorize
  14064. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  14065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14066. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14067. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14068. // MaxEnergyOnInvalidId
  14069. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14071. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14072. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14073. // MeterValuesAlignedData
  14074. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14076. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14077. 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" );
  14078. else
  14079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14080. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14081. // MeterValuesAlignedDataMaxLength
  14082. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14084. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  14086. else
  14087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  14088. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14089. // MeterValuesSampledData
  14090. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14092. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14093. 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" );
  14094. else
  14095. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14096. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14097. // MeterValuesSampledDataMaxLength
  14098. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14100. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  14102. else
  14103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  14104. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14105. // MeterValueSampleInterval
  14106. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  14109. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14110. // MinimumStatusDuration
  14111. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  14114. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  14115. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14116. // NumberOfConnectors
  14117. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14119. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14120. {
  14121. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14122. }
  14123. else
  14124. {
  14125. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14126. }
  14127. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14128. // ResetRetries
  14129. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14130. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14132. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14133. // ConnectorPhaseRotation
  14134. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14135. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14137. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14138. // ConnectorPhaseRotationMaxLength
  14139. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14143. // StopTransactionOnEVSideDisconnect
  14144. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14145. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14147. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14148. // StopTransactionOnInvalidId
  14149. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  14150. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14151. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14152. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14153. // StopTxnAlignedData
  14154. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  14155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  14157. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14158. // StopTxnAlignedDataMaxLength
  14159. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14162. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14163. // StopTxnSampledData
  14164. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14165. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14166. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  14168. else
  14169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  14170. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14171. // StopTxnSampledDataMaxLength
  14172. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14173. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14174. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14175. {
  14176. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  14177. }
  14178. else
  14179. {
  14180. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  14181. }
  14182. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14183. // SupportedFeatureProfiles
  14184. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14186. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14187. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14188. // SupportedFeatureProfilesMaxLength
  14189. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14192. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14193. // TransactionMessageAttempts
  14194. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14197. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14198. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14199. // TransactionMessageRetryInterval
  14200. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14201. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14202. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14203. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14204. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14205. // UnlockConnectorOnEVSideDisconnect
  14206. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14207. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14208. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14209. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14210. // WebSocketPingInterval
  14211. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14212. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14214. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14215. // QueueOffLineMeterValues
  14216. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  14217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  14219. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14220. // AuthorizationKey
  14221. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14222. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14224. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14225. // SecurityProfile
  14226. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14227. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14228. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14229. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14230. // DefaultPrice
  14231. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14232. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14234. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14235. // CustomDisplayCostAndPrice
  14236. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14239. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14240. // CustomIdleFeeAfterStop
  14241. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14243. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14244. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14245. // TimeOffset
  14246. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  14249. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14250. // NextTimeOffsetTransitionDateTime
  14251. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  14254. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14255. // TimeOffsetNextTransition
  14256. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14257. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14258. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  14259. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14260. // SystemUptimeSec
  14261. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14262. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14263. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14264. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14265. // FreeVend
  14266. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14267. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14269. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14270. // FreeVendIdtag
  14271. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14274. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14275. // OcppServer
  14276. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14277. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14278. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14279. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14280. // MaintainServer
  14281. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14283. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  14284. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14285. // StatusNotificationPeriodically
  14286. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  14287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14289. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14290. // StatusNotificationInterval
  14291. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14292. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14294. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14295. // PreAuthAmount
  14296. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  14297. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  14298. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "888" );
  14299. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  14300. // Configuration Version
  14301. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  14302. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14303. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  14304. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14305. //* Local Auth List Management Profile*/
  14306. #if 0
  14307. //For OCTT Test Case
  14308. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14309. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  14310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14311. #endif
  14312. #if 1
  14313. //LocalAuthListEnabled
  14314. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14317. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14318. #endif
  14319. //LocalAuthListMaxLength
  14320. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  14323. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14324. //SendLocalListMaxLength
  14325. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14326. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14327. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14328. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14329. //ReserveConnectorZeroSupported
  14330. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14331. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14332. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14333. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14334. //* Smart Charging Profile */
  14335. //ChargeProfileMaxStackLevel
  14336. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14337. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14338. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14339. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14340. // ChargingScheduleAllowedChargingRateUnit
  14341. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  14344. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14345. // ChargingScheduleMaxPeriods
  14346. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14347. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14349. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14350. // ConnectorSwitch3to1PhaseSupported
  14351. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  14354. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14355. // MaxChargingProfilesInstalled
  14356. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14359. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14360. fclose(outfile);
  14361. }
  14362. else
  14363. {
  14364. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  14365. char keystr[60]={0};
  14366. char readonlystr[10]={0};
  14367. char valuestr[256]={0};
  14368. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  14369. if(fp == NULL) {
  14370. DEBUG_INFO("Error opening file");
  14371. return FALSE;
  14372. }
  14373. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  14374. {
  14375. //DEBUG_INFO("Get Configuration \n");
  14376. if(strlen(str) > 0)
  14377. {
  14378. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14379. //*************************key*********************************/
  14380. if(strstr(str, "key") != NULL)
  14381. {
  14382. loc = strstr(str, "key");
  14383. c = 0;
  14384. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14385. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14386. {
  14387. sstr[c] = loc[strlen("key")+3+c];
  14388. c++;
  14389. }
  14390. sstr[c] = '\0';
  14391. strcpy(keystr,sstr);
  14392. }
  14393. //*************************readonly*********************************/
  14394. if(strstr(str, "readonly") != NULL)
  14395. {
  14396. loc = strstr(str, "readonly");
  14397. c = 0;
  14398. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14399. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  14400. {
  14401. sstr[c] = loc[strlen("readonly")+2+c];
  14402. c++;
  14403. }
  14404. sstr[c] = '\0';
  14405. strcpy(readonlystr,sstr);
  14406. }
  14407. //*************************value*********************************/
  14408. if(strstr(str, "value") != NULL)
  14409. {
  14410. loc = strstr(str, "value");
  14411. c = 0;
  14412. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14413. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14414. {
  14415. sstr[c] = loc[strlen("value")+3+c];
  14416. c++;
  14417. }
  14418. sstr[c] = '\0';
  14419. strcpy(valuestr,sstr);
  14420. }
  14421. // DEBUG_INFO("keystr=%s\n",keystr);
  14422. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  14423. // DEBUG_INFO("valuestr=%s\n",valuestr);
  14424. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  14425. {
  14426. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14427. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14428. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14429. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14430. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14431. }
  14432. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14433. {
  14434. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14435. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14436. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14437. }
  14438. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14439. {
  14440. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14441. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14442. }
  14443. if(strcmp(keystr, "BlinkRepeat") == 0)
  14444. {
  14445. //Charger.BlinkRepeat = Integer.parseInt(value);
  14446. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14447. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14448. }
  14449. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14450. {
  14451. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14452. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14453. }
  14454. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14455. {
  14456. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14457. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14458. }
  14459. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14460. {
  14461. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14462. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14463. }
  14464. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14465. {
  14466. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14467. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14468. HeartBeatWaitTime = atoi(valuestr);
  14469. }
  14470. if(strcmp(keystr, "LightIntensity") == 0)
  14471. {
  14472. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14473. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14474. }
  14475. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14476. {
  14477. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14478. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14479. }
  14480. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14481. {
  14482. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14483. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14484. }
  14485. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14486. {
  14487. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14488. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14489. }
  14490. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14491. {
  14492. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14493. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14494. }
  14495. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14496. {
  14497. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14498. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14499. }
  14500. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14501. {
  14502. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14503. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14504. }
  14505. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14506. {
  14507. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14508. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14509. }
  14510. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14511. {
  14512. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14513. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14514. }
  14515. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14516. {
  14517. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14518. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14519. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14520. }
  14521. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14522. {
  14523. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14524. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14525. }
  14526. if(strcmp(keystr, "ResetRetries") == 0)
  14527. {
  14528. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14529. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14530. }
  14531. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14532. {
  14533. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14534. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14535. }
  14536. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14537. {
  14538. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14539. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14540. }
  14541. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14542. {
  14543. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14544. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14545. }
  14546. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14547. {
  14548. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14549. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14550. }
  14551. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14552. {
  14553. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14554. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14555. }
  14556. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14557. {
  14558. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14559. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14560. }
  14561. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14562. {
  14563. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14564. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14565. }
  14566. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14567. {
  14568. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14569. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14570. }
  14571. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14572. {
  14573. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14574. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14575. }
  14576. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14577. {
  14578. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14579. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14580. }
  14581. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14582. {
  14583. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14584. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14585. TransactionMessageAttemptsValue = atoi(valuestr);
  14586. }
  14587. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14588. {
  14589. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14590. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14591. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14592. }
  14593. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14594. {
  14595. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14596. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14597. }
  14598. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14599. {
  14600. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14601. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14602. }
  14603. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14604. {
  14605. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14606. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14607. }
  14608. if(strcmp(keystr, "AuthorizationKey") == 0)
  14609. {
  14610. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14611. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14612. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14613. }
  14614. if(strcmp(keystr, "SecurityProfile") == 0)
  14615. {
  14616. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14617. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14618. }
  14619. if(strcmp(keystr, "DefaultPrice") == 0)
  14620. {
  14621. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14622. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14623. }
  14624. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14625. {
  14626. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14627. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14628. }
  14629. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14630. {
  14631. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14632. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14633. }
  14634. if(strcmp(keystr, "TimeOffset") == 0)
  14635. {
  14636. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14637. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  14638. }
  14639. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  14640. {
  14641. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14642. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  14643. }
  14644. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  14645. {
  14646. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14647. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  14648. }
  14649. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14650. {
  14651. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14652. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  14653. }
  14654. if(strcmp(keystr, "FreeVend") == 0)
  14655. {
  14656. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14657. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14658. }
  14659. if(strcmp(keystr, "FreeVendIdtag") == 0)
  14660. {
  14661. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14662. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  14663. }
  14664. if(strcmp(keystr, "OcppServer") == 0)
  14665. {
  14666. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14667. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14668. }
  14669. if(strcmp(keystr, "MaintainServer") == 0)
  14670. {
  14671. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14672. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14673. }
  14674. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14675. {
  14676. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14677. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14678. }
  14679. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14680. {
  14681. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14682. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14683. }
  14684. if(strcmp(keystr, "PreAuthAmount") == 0)
  14685. {
  14686. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14687. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(valuestr));
  14688. }
  14689. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14690. {
  14691. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14692. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14693. }
  14694. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14695. {
  14696. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14697. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14698. }
  14699. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14700. {
  14701. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14702. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14703. }
  14704. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14705. {
  14706. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14707. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14708. }
  14709. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14710. {
  14711. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14712. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14713. }
  14714. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14715. {
  14716. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14717. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14718. }
  14719. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14720. {
  14721. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14722. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14723. }
  14724. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14725. {
  14726. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14727. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14728. }
  14729. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14730. {
  14731. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14732. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14733. }
  14734. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14735. {
  14736. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14737. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14738. }
  14739. }
  14740. }
  14741. fclose(fp);
  14742. }
  14743. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14744. {
  14745. return PASS;
  14746. }
  14747. else
  14748. {
  14749. return FAIL;
  14750. }
  14751. }
  14752. void StoreConfigurationTable(void)
  14753. {
  14754. FILE *outfile;
  14755. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14756. if(outfile == NULL)
  14757. {
  14758. DEBUG_INFO("Error opening file");
  14759. return ;
  14760. }
  14761. /*Core Profile*/
  14762. //AllowOfflineTxForUnknownId
  14763. /*
  14764. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14765. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14768. */
  14769. //DEBUG_INFO("data=%s\n",data);
  14770. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14771. //AuthorizationCacheEnabled
  14772. /*
  14773. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14776. */
  14777. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14778. //AuthorizeRemoteTxRequests
  14779. /*
  14780. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14783. */
  14784. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14785. //BlinkRepeat
  14786. /*
  14787. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14790. */
  14791. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14792. //ClockAlignedDataInterval
  14793. /*
  14794. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14797. */
  14798. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14799. //ConnectionTimeOut
  14800. /*
  14801. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14804. */
  14805. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14806. //GetConfigurationMaxKeys
  14807. /*
  14808. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14811. */
  14812. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14813. // HeartbeatInterval
  14814. /*
  14815. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14818. */
  14819. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14820. // LightIntensity
  14821. /*
  14822. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14825. */
  14826. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14827. // LocalAuthorizeOffline
  14828. /*
  14829. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14832. */
  14833. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14834. // LocalPreAuthorize
  14835. /*
  14836. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14839. */
  14840. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14841. // MaxEnergyOnInvalidId
  14842. /*
  14843. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14846. */
  14847. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14848. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14849. // MeterValuesAlignedData
  14850. /*
  14851. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14854. */
  14855. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14856. // MeterValuesAlignedDataMaxLength
  14857. /*
  14858. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14861. */
  14862. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14863. // MeterValuesSampledData
  14864. /*
  14865. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14868. */
  14869. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14870. // MeterValuesSampledDataMaxLength
  14871. /*
  14872. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14875. */
  14876. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14877. // MeterValueSampleInterval
  14878. /*
  14879. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14881. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14882. */
  14883. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14884. // MinimumStatusDuration
  14885. /*
  14886. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14889. */
  14890. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14891. // NumberOfConnectors
  14892. /*
  14893. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14895. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14896. {
  14897. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14898. }
  14899. else
  14900. {
  14901. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14902. }
  14903. */
  14904. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14905. // ResetRetries
  14906. /*
  14907. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14909. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14910. */
  14911. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14912. // ConnectorPhaseRotation
  14913. /*
  14914. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14916. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14917. */
  14918. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14919. // ConnectorPhaseRotationMaxLength
  14920. /*
  14921. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14923. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14924. */
  14925. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14926. // StopTransactionOnEVSideDisconnect
  14927. /*
  14928. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14931. */
  14932. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14933. // StopTransactionOnInvalidId
  14934. /*
  14935. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14938. */
  14939. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14940. // StopTxnAlignedData
  14941. /*
  14942. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14945. */
  14946. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14947. // StopTxnAlignedDataMaxLength
  14948. /*
  14949. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14952. */
  14953. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14954. // StopTxnSampledData
  14955. /*
  14956. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14959. */
  14960. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14961. // StopTxnSampledDataMaxLength
  14962. /*
  14963. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14964. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14966. */
  14967. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14968. // SupportedFeatureProfiles
  14969. /*
  14970. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14973. */
  14974. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14975. // SupportedFeatureProfilesMaxLength
  14976. /*
  14977. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14979. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14980. */
  14981. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14982. // TransactionMessageAttempts
  14983. /*
  14984. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14987. */
  14988. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14989. // TransactionMessageRetryInterval
  14990. /*
  14991. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14994. */
  14995. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14996. // UnlockConnectorOnEVSideDisconnect
  14997. /*
  14998. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  15000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  15001. */
  15002. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15003. // WebSocketPingInterval
  15004. /*
  15005. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15008. */
  15009. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15010. // QueueOffLineMeterValues
  15011. /*
  15012. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  15013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  15015. */
  15016. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15017. // AuthorizationKey
  15018. /*
  15019. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  15022. */
  15023. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15024. // SecurityProfile
  15025. /*
  15026. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  15029. */
  15030. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15031. // DefaultPrice
  15032. /*
  15033. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15036. */
  15037. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15038. // CustomDisplayCostAndPrice
  15039. /*
  15040. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15043. */
  15044. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15045. // CustomIdleFeeAfterStop
  15046. /*
  15047. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15050. */
  15051. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15052. // TimeOffset
  15053. /*
  15054. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  15055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  15056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  15057. */
  15058. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  15059. // NextTimeOffsetTransitionDateTime
  15060. /*
  15061. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  15062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  15063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  15064. */
  15065. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  15066. // TimeOffsetNextTransition
  15067. /*
  15068. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  15069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  15070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  15071. */
  15072. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  15073. // SystemUptimeSec
  15074. /*
  15075. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15078. */
  15079. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15080. // FreeVend
  15081. /*
  15082. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  15085. */
  15086. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15087. // FreeVendIdtag
  15088. /*
  15089. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15092. */
  15093. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15094. // OcppServer
  15095. /*
  15096. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  15099. */
  15100. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15101. // MaintainServer
  15102. /*
  15103. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  15106. */
  15107. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15108. // StatusNotificationPeriodically
  15109. /*
  15110. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  15111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15113. */
  15114. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15115. // StatusNotificationInterval
  15116. /*
  15117. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15120. */
  15121. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15122. // PreAuthAmount
  15123. /*
  15124. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  15125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  15126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "120" );
  15127. */
  15128. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  15129. // ConfigurationVersion
  15130. /*
  15131. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  15132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  15134. */
  15135. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15136. //* Local Auth List Management Profile*/
  15137. //LocalAuthListEnabled
  15138. /*
  15139. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15142. */
  15143. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15144. //LocalAuthListMaxLength
  15145. /*
  15146. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  15149. */
  15150. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15151. //SendLocalListMaxLength
  15152. /*
  15153. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  15156. */
  15157. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15158. //ReserveConnectorZeroSupported
  15159. /*
  15160. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15163. */
  15164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15165. //* Smart Charging Profile */
  15166. //ChargeProfileMaxStackLevel
  15167. /*
  15168. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  15169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  15170. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  15171. */
  15172. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15173. // ChargingScheduleAllowedChargingRateUnit
  15174. /*
  15175. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  15176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  15177. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  15178. */
  15179. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15180. // ChargingScheduleMaxPeriods
  15181. /*
  15182. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  15183. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  15184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  15185. */
  15186. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15187. // ConnectorSwitch3to1PhaseSupported
  15188. /*
  15189. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  15190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  15191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  15192. */
  15193. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15194. // MaxChargingProfilesInstalled
  15195. /*
  15196. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  15197. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  15198. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  15199. */
  15200. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15201. fclose(outfile);
  15202. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15203. }
  15204. void getKeyValue(char *keyReq)
  15205. {
  15206. int isEmpty = FALSE;
  15207. int isKnowKey = FALSE;
  15208. DEBUG_INFO("keyReq = %s\n", keyReq);
  15209. if((keyReq == NULL) || (strlen(keyReq) == 0))
  15210. isEmpty = TRUE;
  15211. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  15212. {
  15213. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  15214. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  15215. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15216. {
  15217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  15218. }
  15219. else
  15220. {
  15221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  15222. }
  15223. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  15224. isKnowKey = TRUE;
  15225. }
  15226. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  15227. {
  15228. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  15229. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  15230. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15231. {
  15232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  15233. }
  15234. else
  15235. {
  15236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  15237. }
  15238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  15239. isKnowKey = TRUE;
  15240. }
  15241. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  15242. {
  15243. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  15244. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  15245. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15246. {
  15247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  15248. }
  15249. else
  15250. {
  15251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  15252. }
  15253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  15254. isKnowKey = TRUE;
  15255. }
  15256. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  15257. {
  15258. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  15259. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  15260. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15261. {
  15262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  15263. }
  15264. else
  15265. {
  15266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  15267. }
  15268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  15269. isKnowKey = TRUE;
  15270. }
  15271. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  15272. {
  15273. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  15274. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  15275. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15276. {
  15277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  15278. }
  15279. else
  15280. {
  15281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  15282. }
  15283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  15284. isKnowKey = TRUE;
  15285. }
  15286. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  15287. {
  15288. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  15289. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  15290. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15291. {
  15292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  15293. }
  15294. else
  15295. {
  15296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  15297. }
  15298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  15299. isKnowKey = TRUE;
  15300. }
  15301. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  15302. {
  15303. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  15304. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  15305. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15306. {
  15307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  15308. }
  15309. else
  15310. {
  15311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  15312. }
  15313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  15314. isKnowKey = TRUE;
  15315. }
  15316. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  15317. {
  15318. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  15319. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  15320. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15321. {
  15322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  15323. }
  15324. else
  15325. {
  15326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  15327. }
  15328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  15329. isKnowKey = TRUE;
  15330. }
  15331. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  15332. {
  15333. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  15334. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  15335. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15336. {
  15337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  15338. }
  15339. else
  15340. {
  15341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  15342. }
  15343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  15344. isKnowKey = TRUE;
  15345. }
  15346. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  15347. {
  15348. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  15349. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  15350. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15351. {
  15352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  15353. }
  15354. else
  15355. {
  15356. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  15357. }
  15358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  15359. isKnowKey = TRUE;
  15360. }
  15361. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  15362. {
  15363. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  15364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  15365. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15366. {
  15367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  15368. }
  15369. else
  15370. {
  15371. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  15372. }
  15373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  15374. isKnowKey = TRUE;
  15375. }
  15376. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  15377. {
  15378. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  15379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  15380. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15381. {
  15382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15383. }
  15384. else
  15385. {
  15386. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15387. }
  15388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  15389. isKnowKey = TRUE;
  15390. }
  15391. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  15392. {
  15393. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  15394. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  15395. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15396. {
  15397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15398. }
  15399. else
  15400. {
  15401. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15402. }
  15403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  15404. isKnowKey = TRUE;
  15405. }
  15406. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  15407. {
  15408. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  15409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  15410. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15411. {
  15412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15413. }
  15414. else
  15415. {
  15416. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15417. }
  15418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  15419. isKnowKey = TRUE;
  15420. }
  15421. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  15422. {
  15423. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  15424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  15425. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15426. {
  15427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  15428. }
  15429. else
  15430. {
  15431. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  15432. }
  15433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  15434. isKnowKey = TRUE;
  15435. }
  15436. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  15437. {
  15438. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  15439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  15440. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15441. {
  15442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15443. }
  15444. else
  15445. {
  15446. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15447. }
  15448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  15449. isKnowKey = TRUE;
  15450. }
  15451. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  15452. {
  15453. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  15454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  15455. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15456. {
  15457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  15458. }
  15459. else
  15460. {
  15461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  15462. }
  15463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  15464. isKnowKey = TRUE;
  15465. }
  15466. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  15467. {
  15468. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  15469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  15470. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15471. {
  15472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  15473. }
  15474. else
  15475. {
  15476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  15477. }
  15478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  15479. isKnowKey = TRUE;
  15480. }
  15481. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  15482. {
  15483. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  15484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  15485. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15486. {
  15487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  15488. }
  15489. else
  15490. {
  15491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15492. }
  15493. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15495. isKnowKey = TRUE;
  15496. }
  15497. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15498. {
  15499. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15501. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15502. {
  15503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15504. }
  15505. else
  15506. {
  15507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15508. }
  15509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15510. isKnowKey = TRUE;
  15511. }
  15512. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15513. {
  15514. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15516. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15517. {
  15518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15519. }
  15520. else
  15521. {
  15522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15523. }
  15524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15525. isKnowKey = TRUE;
  15526. }
  15527. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15528. {
  15529. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15531. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15532. {
  15533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15534. }
  15535. else
  15536. {
  15537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15538. }
  15539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15540. isKnowKey = TRUE;
  15541. }
  15542. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15543. {
  15544. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15546. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15547. {
  15548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15549. }
  15550. else
  15551. {
  15552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15553. }
  15554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15555. isKnowKey = TRUE;
  15556. }
  15557. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15558. {
  15559. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15561. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15562. {
  15563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15564. }
  15565. else
  15566. {
  15567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15568. }
  15569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15570. isKnowKey = TRUE;
  15571. }
  15572. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15573. {
  15574. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15575. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15576. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15577. {
  15578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15579. }
  15580. else
  15581. {
  15582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15583. }
  15584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15585. isKnowKey = TRUE;
  15586. }
  15587. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15588. {
  15589. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15591. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15592. {
  15593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15594. }
  15595. else
  15596. {
  15597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15598. }
  15599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15600. isKnowKey = TRUE;
  15601. }
  15602. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15603. {
  15604. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15605. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15606. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15607. {
  15608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15609. }
  15610. else
  15611. {
  15612. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15613. }
  15614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15615. isKnowKey = TRUE;
  15616. }
  15617. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15618. {
  15619. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15620. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15621. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15622. {
  15623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15624. }
  15625. else
  15626. {
  15627. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15628. }
  15629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15630. isKnowKey = TRUE;
  15631. }
  15632. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15633. {
  15634. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15635. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15636. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15637. {
  15638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15639. }
  15640. else
  15641. {
  15642. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15643. }
  15644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15645. isKnowKey = TRUE;
  15646. }
  15647. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15648. {
  15649. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15650. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15651. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15652. {
  15653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15654. }
  15655. else
  15656. {
  15657. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15658. }
  15659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15660. isKnowKey = TRUE;
  15661. }
  15662. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15663. {
  15664. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15665. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15666. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15667. {
  15668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15669. }
  15670. else
  15671. {
  15672. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15673. }
  15674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15675. isKnowKey = TRUE;
  15676. }
  15677. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15678. {
  15679. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15681. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15682. {
  15683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15684. }
  15685. else
  15686. {
  15687. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15688. }
  15689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15690. isKnowKey = TRUE;
  15691. }
  15692. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15693. {
  15694. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15696. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15697. {
  15698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15699. }
  15700. else
  15701. {
  15702. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15703. }
  15704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15705. isKnowKey = TRUE;
  15706. }
  15707. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15708. {
  15709. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15711. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15712. {
  15713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15714. }
  15715. else
  15716. {
  15717. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15718. }
  15719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15720. isKnowKey = TRUE;
  15721. }
  15722. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15723. {
  15724. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15726. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15727. {
  15728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15729. }
  15730. else
  15731. {
  15732. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15733. }
  15734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15735. isKnowKey = TRUE;
  15736. }
  15737. /*
  15738. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15739. {
  15740. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15741. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15742. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15743. {
  15744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15745. }
  15746. else
  15747. {
  15748. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15749. }
  15750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15751. isKnowKey = TRUE;
  15752. }*/
  15753. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15754. {
  15755. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15757. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15758. {
  15759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15760. }
  15761. else
  15762. {
  15763. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15764. }
  15765. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15766. isKnowKey = TRUE;
  15767. }
  15768. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15769. {
  15770. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15772. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15773. {
  15774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15775. }
  15776. else
  15777. {
  15778. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15779. }
  15780. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15781. isKnowKey = TRUE;
  15782. }
  15783. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15784. {
  15785. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15787. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15788. {
  15789. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15790. }
  15791. else
  15792. {
  15793. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15794. }
  15795. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15796. isKnowKey = TRUE;
  15797. }
  15798. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15799. {
  15800. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15802. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15803. {
  15804. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15805. }
  15806. else
  15807. {
  15808. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15809. }
  15810. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15811. isKnowKey = TRUE;
  15812. }
  15813. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  15814. {
  15815. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  15816. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  15817. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15818. {
  15819. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  15820. }
  15821. else
  15822. {
  15823. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  15824. }
  15825. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  15826. isKnowKey = TRUE;
  15827. }
  15828. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  15829. {
  15830. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  15831. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  15832. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15833. {
  15834. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  15835. }
  15836. else
  15837. {
  15838. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  15839. }
  15840. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  15841. isKnowKey = TRUE;
  15842. }
  15843. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  15844. {
  15845. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  15846. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  15847. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15848. {
  15849. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  15850. }
  15851. else
  15852. {
  15853. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  15854. }
  15855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  15856. isKnowKey = TRUE;
  15857. }
  15858. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15859. {
  15860. struct sysinfo s_info;
  15861. int error = sysinfo(&s_info);
  15862. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15864. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15865. {
  15866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15867. }
  15868. else
  15869. {
  15870. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15871. }
  15872. if(error != 0)
  15873. {
  15874. DEBUG_WARN("System uptime get error: %d\n", error);
  15875. }
  15876. else
  15877. {
  15878. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15879. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15880. }
  15881. isKnowKey = TRUE;
  15882. }
  15883. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15884. {
  15885. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15886. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15887. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15888. {
  15889. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15890. }
  15891. else
  15892. {
  15893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15894. }
  15895. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  15896. isKnowKey = TRUE;
  15897. }
  15898. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  15899. {
  15900. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  15901. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  15902. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  15903. {
  15904. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  15905. }
  15906. else
  15907. {
  15908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  15909. }
  15910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15911. isKnowKey = TRUE;
  15912. }
  15913. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15914. {
  15915. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15916. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15917. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15918. {
  15919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15920. }
  15921. else
  15922. {
  15923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15924. }
  15925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15926. isKnowKey = TRUE;
  15927. }
  15928. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15929. {
  15930. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15932. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15933. {
  15934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15935. }
  15936. else
  15937. {
  15938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15939. }
  15940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15941. isKnowKey = TRUE;
  15942. }
  15943. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15944. {
  15945. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15946. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15947. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15948. {
  15949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15950. }
  15951. else
  15952. {
  15953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15954. }
  15955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15956. isKnowKey = TRUE;
  15957. }
  15958. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15959. {
  15960. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15962. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15963. {
  15964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15965. }
  15966. else
  15967. {
  15968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15969. }
  15970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15971. isKnowKey = TRUE;
  15972. }
  15973. if(isEmpty || strcmp(keyReq, "PreAuthAmount") == 0 )
  15974. {
  15975. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PreAuthAmount].Item, "PreAuthAmount");
  15976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Key, "PreAuthAmount");
  15977. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  15978. {
  15979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "0"/*"FALSE"*/);
  15980. }
  15981. else
  15982. {
  15983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "1"/*"TRUE"*/);
  15984. }
  15985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData );
  15986. isKnowKey = TRUE;
  15987. }
  15988. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15989. {
  15990. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15992. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15993. {
  15994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15995. }
  15996. else
  15997. {
  15998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15999. }
  16000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  16001. isKnowKey = TRUE;
  16002. }
  16003. #if 1
  16004. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  16005. {
  16006. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  16007. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  16008. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16009. {
  16010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  16011. }
  16012. else
  16013. {
  16014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  16015. }
  16016. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  16017. isKnowKey = TRUE;
  16018. }
  16019. #endif
  16020. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  16021. {
  16022. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  16023. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  16024. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16025. {
  16026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16027. }
  16028. else
  16029. {
  16030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16031. }
  16032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  16033. isKnowKey = TRUE;
  16034. }
  16035. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  16036. {
  16037. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  16038. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  16039. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16040. {
  16041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16042. }
  16043. else
  16044. {
  16045. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16046. }
  16047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  16048. isKnowKey = TRUE;
  16049. }
  16050. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  16051. {
  16052. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  16053. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  16054. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16055. {
  16056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  16057. }
  16058. else
  16059. {
  16060. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  16061. }
  16062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16063. isKnowKey = TRUE;
  16064. }
  16065. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  16066. {
  16067. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  16068. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  16069. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16070. {
  16071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  16072. }
  16073. else
  16074. {
  16075. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  16076. }
  16077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16078. isKnowKey = TRUE;
  16079. }
  16080. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  16081. {
  16082. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  16083. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  16084. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16085. {
  16086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  16087. }
  16088. else
  16089. {
  16090. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  16091. }
  16092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16093. isKnowKey = TRUE;
  16094. }
  16095. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  16096. {
  16097. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  16098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  16099. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16100. {
  16101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  16102. }
  16103. else
  16104. {
  16105. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  16106. }
  16107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16108. isKnowKey = TRUE;
  16109. }
  16110. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  16111. {
  16112. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  16113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  16114. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16115. {
  16116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  16117. }
  16118. else
  16119. {
  16120. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  16121. }
  16122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16123. isKnowKey = TRUE;
  16124. }
  16125. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  16126. {
  16127. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  16128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  16129. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16130. {
  16131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  16132. }
  16133. else
  16134. {
  16135. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  16136. }
  16137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16138. isKnowKey = TRUE;
  16139. }
  16140. //=========================================================
  16141. if(!isEmpty && !isKnowKey)
  16142. {
  16143. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  16144. strcpy(unknownkey[UnknownKeynum], keyReq);
  16145. UnknownKeynum = UnknownKeynum + 1;
  16146. }
  16147. }
  16148. void processUnkownKey(void)
  16149. {
  16150. DEBUG_INFO("processUnkownKey...\n");
  16151. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  16152. for(int index=0; index < UnknownKeynum; index++)
  16153. {
  16154. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  16155. {
  16156. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  16157. }
  16158. }
  16159. }
  16160. int setKeyValue(char *key, char *value)
  16161. {
  16162. int isSuccess = NotSupported;
  16163. int check_ascii=0;
  16164. char str[501]={0};
  16165. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  16166. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  16167. {
  16168. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  16169. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16170. {
  16171. strcpy(str, (const char*)value);
  16172. for(int i = 0; str[i]; i++){
  16173. str[i] = tolower(str[i]);
  16174. }
  16175. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16176. isSuccess = ConfigurationStatus_Accepted;
  16177. }
  16178. else
  16179. {
  16180. isSuccess = ConfigurationStatus_Rejected;
  16181. }
  16182. }
  16183. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  16184. {
  16185. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  16186. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16187. {
  16188. strcpy(str, (const char*)value);
  16189. for(int i = 0; str[i]; i++){
  16190. str[i] = tolower(str[i]);
  16191. }
  16192. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16193. isSuccess = ConfigurationStatus_Accepted;
  16194. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  16195. }
  16196. else
  16197. {
  16198. isSuccess = ConfigurationStatus_Rejected;
  16199. }
  16200. }
  16201. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  16202. {
  16203. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16204. {
  16205. strcpy(str, (const char*)value);
  16206. for(int i = 0; str[i]; i++)
  16207. {
  16208. str[i] = tolower(str[i]);
  16209. }
  16210. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  16211. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16212. isSuccess = ConfigurationStatus_Accepted;
  16213. }
  16214. else
  16215. {
  16216. isSuccess = ConfigurationStatus_Rejected;
  16217. }
  16218. }
  16219. if(strcmp(key, "BlinkRepeat") == 0)
  16220. {
  16221. //Charger.BlinkRepeat = Integer.parseInt(value);
  16222. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16223. {
  16224. check_ascii = value[0];
  16225. if( (check_ascii < 48) || (check_ascii > 57) )
  16226. {
  16227. isSuccess = ConfigurationStatus_Rejected;
  16228. }
  16229. else
  16230. {
  16231. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  16232. isSuccess = ConfigurationStatus_Accepted;
  16233. }
  16234. }
  16235. else
  16236. {
  16237. isSuccess = ConfigurationStatus_Rejected;
  16238. }
  16239. }
  16240. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  16241. {
  16242. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16243. {
  16244. check_ascii = value[0];
  16245. if( (check_ascii < 48) || (check_ascii > 57) )
  16246. {
  16247. isSuccess = ConfigurationStatus_Rejected;
  16248. }
  16249. else
  16250. {
  16251. if((atoi(value) == 0) || (atoi(value) >= 5))
  16252. {
  16253. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  16254. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  16255. isSuccess = ConfigurationStatus_Accepted;
  16256. }
  16257. else
  16258. isSuccess = ConfigurationStatus_Rejected;
  16259. }
  16260. }
  16261. else
  16262. {
  16263. isSuccess = ConfigurationStatus_Rejected;
  16264. }
  16265. }
  16266. if(strcmp(key, "ConnectionTimeOut") == 0 )
  16267. {
  16268. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  16269. {
  16270. check_ascii = value[0];
  16271. if( (check_ascii < 48) || (check_ascii > 57) )
  16272. {
  16273. isSuccess = ConfigurationStatus_Rejected;
  16274. }
  16275. else
  16276. {
  16277. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  16278. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  16279. isSuccess = ConfigurationStatus_Accepted;
  16280. }
  16281. }
  16282. else
  16283. {
  16284. isSuccess = ConfigurationStatus_Rejected;
  16285. }
  16286. }
  16287. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  16288. {
  16289. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  16290. {
  16291. check_ascii = value[0];
  16292. if( (check_ascii < 48) || (check_ascii > 57) )
  16293. {
  16294. isSuccess = ConfigurationStatus_Rejected;
  16295. }
  16296. else
  16297. {
  16298. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16299. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  16300. isSuccess = ConfigurationStatus_Accepted;
  16301. }
  16302. }
  16303. else
  16304. {
  16305. isSuccess = ConfigurationStatus_Rejected;
  16306. }
  16307. }
  16308. if(strcmp(key, "HeartbeatInterval") == 0)
  16309. {
  16310. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  16311. {
  16312. check_ascii = value[0];
  16313. if( (check_ascii < 48) || (check_ascii > 57) )
  16314. {
  16315. isSuccess = ConfigurationStatus_Rejected;
  16316. }
  16317. else
  16318. {
  16319. if((atoi(value) == 0) || (atoi(value) >= 10))
  16320. {
  16321. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16322. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  16323. HeartBeatWaitTime = atoi(value);
  16324. isSuccess = ConfigurationStatus_Accepted;
  16325. }
  16326. else
  16327. {
  16328. isSuccess = ConfigurationStatus_Rejected;
  16329. }
  16330. }
  16331. }
  16332. else
  16333. {
  16334. isSuccess = ConfigurationStatus_Rejected;
  16335. }
  16336. }
  16337. if(strcmp(key, "LightIntensity") == 0)
  16338. {
  16339. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16340. {
  16341. check_ascii = value[0];
  16342. if( (check_ascii < 48) || (check_ascii > 57) )
  16343. {
  16344. isSuccess = ConfigurationStatus_Rejected;
  16345. }
  16346. else
  16347. {
  16348. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  16349. isSuccess = ConfigurationStatus_Accepted;
  16350. }
  16351. }
  16352. else
  16353. {
  16354. isSuccess = ConfigurationStatus_Rejected;
  16355. }
  16356. }
  16357. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  16358. {
  16359. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  16360. {
  16361. strcpy(str, (const char*)value);
  16362. for(int i = 0; str[i]; i++)
  16363. {
  16364. str[i] = tolower(str[i]);
  16365. }
  16366. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16367. isSuccess = ConfigurationStatus_Accepted;
  16368. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16369. }
  16370. else
  16371. {
  16372. isSuccess = ConfigurationStatus_Rejected;
  16373. }
  16374. }
  16375. if(strcmp(key, "LocalPreAuthorize") == 0)
  16376. {
  16377. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16378. {
  16379. strcpy(str, (const char*)value);
  16380. for(int i = 0; str[i]; i++)
  16381. {
  16382. str[i] = tolower(str[i]);
  16383. }
  16384. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16385. isSuccess = ConfigurationStatus_Accepted;
  16386. }
  16387. else
  16388. {
  16389. isSuccess = ConfigurationStatus_Rejected;
  16390. }
  16391. }
  16392. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  16393. {
  16394. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  16395. {
  16396. check_ascii = value[0];
  16397. if( (check_ascii < 48) || (check_ascii > 57) )
  16398. {
  16399. isSuccess = ConfigurationStatus_Rejected;
  16400. }
  16401. else
  16402. {
  16403. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  16404. isSuccess = ConfigurationStatus_Accepted;
  16405. }
  16406. }
  16407. else
  16408. {
  16409. isSuccess = ConfigurationStatus_Rejected;
  16410. }
  16411. }
  16412. if(strcmp(key, "MeterValuesAlignedData") == 0)
  16413. {
  16414. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  16415. {
  16416. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  16417. isSuccess = ConfigurationStatus_Accepted;
  16418. }
  16419. else
  16420. {
  16421. isSuccess = ConfigurationStatus_Rejected;
  16422. }
  16423. }
  16424. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  16425. {
  16426. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  16427. {
  16428. check_ascii = value[0];
  16429. if( (check_ascii < 48) || (check_ascii > 57) )
  16430. {
  16431. isSuccess = ConfigurationStatus_Rejected;
  16432. }
  16433. else
  16434. {
  16435. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16436. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  16437. isSuccess = ConfigurationStatus_Accepted;
  16438. }
  16439. }
  16440. else
  16441. {
  16442. isSuccess = ConfigurationStatus_Rejected;
  16443. }
  16444. }
  16445. if(strcmp(key, "MeterValuesSampledData") == 0 )
  16446. {
  16447. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  16448. {
  16449. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  16450. isSuccess = ConfigurationStatus_Accepted;
  16451. }
  16452. else
  16453. {
  16454. isSuccess = ConfigurationStatus_Rejected;
  16455. }
  16456. }
  16457. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  16458. {
  16459. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16460. {
  16461. check_ascii = value[0];
  16462. if( (check_ascii < 48) || (check_ascii > 57) )
  16463. {
  16464. isSuccess = ConfigurationStatus_Rejected;
  16465. }
  16466. else
  16467. {
  16468. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16469. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  16470. isSuccess = ConfigurationStatus_Accepted;
  16471. }
  16472. }
  16473. else
  16474. {
  16475. isSuccess = ConfigurationStatus_Rejected;
  16476. }
  16477. }
  16478. if(strcmp(key, "MeterValueSampleInterval") == 0)
  16479. {
  16480. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16481. {
  16482. check_ascii = value[0];
  16483. if( (check_ascii < 48) || (check_ascii > 57) )
  16484. {
  16485. isSuccess = ConfigurationStatus_Rejected;
  16486. }
  16487. else
  16488. {
  16489. if((atoi(value) == 0) || (atoi(value) >= 3))
  16490. {
  16491. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16492. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  16493. isSuccess = ConfigurationStatus_Accepted;
  16494. }
  16495. else
  16496. {
  16497. isSuccess = ConfigurationStatus_Rejected;
  16498. }
  16499. }
  16500. }
  16501. else
  16502. {
  16503. isSuccess = ConfigurationStatus_Rejected;
  16504. }
  16505. }
  16506. if(strcmp(key, "MinimumStatusDuration") == 0)
  16507. {
  16508. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16509. {
  16510. check_ascii = value[0];
  16511. if( (check_ascii < 48) || (check_ascii > 57) )
  16512. {
  16513. isSuccess = ConfigurationStatus_Rejected;
  16514. }
  16515. else
  16516. {
  16517. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  16518. {
  16519. isSuccess = ConfigurationStatus_Rejected;
  16520. }
  16521. else
  16522. {
  16523. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16524. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16525. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16526. isSuccess = ConfigurationStatus_Accepted;
  16527. }
  16528. }
  16529. }
  16530. else
  16531. {
  16532. isSuccess = ConfigurationStatus_Rejected;
  16533. }
  16534. }
  16535. if(strcmp(key, "NumberOfConnectors") == 0)
  16536. {
  16537. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16538. {
  16539. check_ascii = value[0];
  16540. if( (check_ascii < 48) || (check_ascii > 57) )
  16541. {
  16542. isSuccess = ConfigurationStatus_Rejected;
  16543. }
  16544. else
  16545. {
  16546. //Charger.ResetRetries = Integer.parseInt(value);
  16547. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16548. isSuccess = ConfigurationStatus_Accepted;
  16549. }
  16550. }
  16551. else
  16552. {
  16553. isSuccess = ConfigurationStatus_Rejected;
  16554. }
  16555. }
  16556. if(strcmp(key, "ResetRetries") == 0)
  16557. {
  16558. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16559. {
  16560. check_ascii = value[0];
  16561. if( (check_ascii < 48) || (check_ascii > 57) )
  16562. {
  16563. isSuccess = ConfigurationStatus_Rejected;
  16564. }
  16565. else
  16566. {
  16567. //Charger.ResetRetries = Integer.parseInt(value);
  16568. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16569. isSuccess = ConfigurationStatus_Accepted;
  16570. }
  16571. }
  16572. else
  16573. {
  16574. isSuccess = ConfigurationStatus_Rejected;
  16575. }
  16576. }
  16577. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16578. {
  16579. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16580. {
  16581. strcpy(str, (const char*)value);
  16582. for(int i = 0; str[i]; i++)
  16583. {
  16584. str[i] = tolower(str[i]);
  16585. }
  16586. if(strcmp(str, "notapplicable")== 0)
  16587. {
  16588. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16589. isSuccess = ConfigurationStatus_Accepted;
  16590. }
  16591. else if(strcmp(str, "unknown")== 0)
  16592. {
  16593. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16594. isSuccess = ConfigurationStatus_Accepted;
  16595. }
  16596. else if(strcmp(str, "rst")== 0)
  16597. {
  16598. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16599. isSuccess = ConfigurationStatus_Accepted;
  16600. }
  16601. else if(strcmp(str, "rts")== 0)
  16602. {
  16603. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16604. isSuccess = ConfigurationStatus_Accepted;
  16605. }
  16606. else if(strcmp(str, "srt")== 0)
  16607. {
  16608. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16609. isSuccess = ConfigurationStatus_Accepted;
  16610. }
  16611. else if(strcmp(str, "str")== 0)
  16612. {
  16613. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16614. isSuccess = ConfigurationStatus_Accepted;
  16615. }
  16616. else if(strcmp(str, "trs")== 0)
  16617. {
  16618. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16619. isSuccess = ConfigurationStatus_Accepted;
  16620. }
  16621. else if(strcmp(str, "tsr")== 0)
  16622. {
  16623. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16624. isSuccess = ConfigurationStatus_Accepted;
  16625. }
  16626. else
  16627. {
  16628. isSuccess = ConfigurationStatus_Rejected;
  16629. }
  16630. }
  16631. else
  16632. {
  16633. isSuccess = ConfigurationStatus_Rejected;
  16634. }
  16635. }
  16636. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16637. {
  16638. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16639. {
  16640. check_ascii = value[0];
  16641. if( (check_ascii < 48) || (check_ascii > 57) )
  16642. {
  16643. isSuccess = ConfigurationStatus_Rejected;
  16644. }
  16645. else
  16646. {
  16647. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16648. isSuccess = ConfigurationStatus_Accepted;
  16649. }
  16650. }
  16651. else
  16652. {
  16653. isSuccess = ConfigurationStatus_Rejected;
  16654. }
  16655. }
  16656. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16657. {
  16658. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16659. {
  16660. strcpy(str, (const char*)value);
  16661. for(int i = 0; str[i]; i++)
  16662. {
  16663. str[i] = tolower(str[i]);
  16664. }
  16665. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16666. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16667. isSuccess = ConfigurationStatus_Accepted;
  16668. }
  16669. else
  16670. {
  16671. isSuccess = ConfigurationStatus_Rejected;
  16672. }
  16673. }
  16674. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16675. {
  16676. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16677. {
  16678. strcpy(str, (const char*)value);
  16679. for(int i = 0; str[i]; i++)
  16680. {
  16681. str[i] = tolower(str[i]);
  16682. }
  16683. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16684. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16685. isSuccess = ConfigurationStatus_Accepted;
  16686. }
  16687. else
  16688. {
  16689. isSuccess = ConfigurationStatus_Rejected;
  16690. }
  16691. }
  16692. if(strcmp(key, "StopTxnAlignedData") == 0)
  16693. {
  16694. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16695. {
  16696. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16697. isSuccess = ConfigurationStatus_Accepted;
  16698. }
  16699. else
  16700. {
  16701. isSuccess = ConfigurationStatus_Rejected;
  16702. }
  16703. }
  16704. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16705. {
  16706. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16707. {
  16708. check_ascii = value[0];
  16709. if( (check_ascii < 48) || (check_ascii > 57) )
  16710. {
  16711. isSuccess = ConfigurationStatus_Rejected;
  16712. }
  16713. else
  16714. {
  16715. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16716. isSuccess = ConfigurationStatus_Accepted;
  16717. }
  16718. }
  16719. else
  16720. {
  16721. isSuccess = ConfigurationStatus_Rejected;
  16722. }
  16723. }
  16724. if(strcmp(key, "StopTxnSampledData") == 0)
  16725. {
  16726. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16727. {
  16728. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16729. isSuccess = ConfigurationStatus_Accepted;
  16730. }
  16731. else
  16732. {
  16733. isSuccess = ConfigurationStatus_Rejected;
  16734. }
  16735. }
  16736. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16737. {
  16738. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16739. {
  16740. check_ascii = value[0];
  16741. if( (check_ascii < 48) || (check_ascii > 57) )
  16742. {
  16743. isSuccess = ConfigurationStatus_Rejected;
  16744. }
  16745. else
  16746. {
  16747. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16748. isSuccess = ConfigurationStatus_Accepted;
  16749. }
  16750. }
  16751. else
  16752. {
  16753. isSuccess = ConfigurationStatus_Rejected;
  16754. }
  16755. }
  16756. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16757. {
  16758. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16759. {
  16760. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16761. isSuccess = ConfigurationStatus_Accepted;
  16762. }
  16763. else
  16764. {
  16765. isSuccess = ConfigurationStatus_Rejected;
  16766. }
  16767. }
  16768. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16769. {
  16770. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16771. {
  16772. check_ascii = value[0];
  16773. if( (check_ascii < 48) || (check_ascii > 57) )
  16774. {
  16775. isSuccess = ConfigurationStatus_Rejected;
  16776. }
  16777. else
  16778. {
  16779. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16780. isSuccess = ConfigurationStatus_Accepted;
  16781. }
  16782. }
  16783. else
  16784. {
  16785. isSuccess = ConfigurationStatus_Rejected;
  16786. }
  16787. }
  16788. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16789. {
  16790. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16791. {
  16792. check_ascii = value[0];
  16793. if( (check_ascii < 48) || (check_ascii > 57) )
  16794. {
  16795. isSuccess = ConfigurationStatus_Rejected;
  16796. }
  16797. else
  16798. {
  16799. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16800. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16801. TransactionMessageAttemptsValue = atoi(value);
  16802. isSuccess = ConfigurationStatus_Accepted;
  16803. }
  16804. }
  16805. else
  16806. {
  16807. isSuccess = ConfigurationStatus_Rejected;
  16808. }
  16809. }
  16810. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16811. {
  16812. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16813. {
  16814. check_ascii = value[0];
  16815. if( (check_ascii < 48) || (check_ascii > 57) )
  16816. {
  16817. isSuccess = ConfigurationStatus_Rejected;
  16818. }
  16819. else
  16820. {
  16821. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16822. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16823. TransactionMessageRetryIntervalValue = atoi(value);
  16824. isSuccess = ConfigurationStatus_Accepted;
  16825. }
  16826. }
  16827. else
  16828. {
  16829. isSuccess = ConfigurationStatus_Rejected;
  16830. }
  16831. }
  16832. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16833. {
  16834. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16835. {
  16836. strcpy(str, (const char*)value);
  16837. for(int i = 0; str[i]; i++)
  16838. {
  16839. str[i] = tolower(str[i]);
  16840. }
  16841. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16842. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16843. isSuccess = ConfigurationStatus_Accepted;
  16844. }
  16845. else
  16846. {
  16847. isSuccess = ConfigurationStatus_Rejected;
  16848. }
  16849. }
  16850. if(strcmp(key, "WebSocketPingInterval") == 0)
  16851. {
  16852. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16853. {
  16854. check_ascii = value[0];
  16855. if( (check_ascii < 48) || (check_ascii > 57) )
  16856. {
  16857. isSuccess = ConfigurationStatus_Rejected;
  16858. }
  16859. else
  16860. {
  16861. if((atoi(value) == 0) || (atoi(value) >= 10))
  16862. {
  16863. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16864. isSuccess = ConfigurationStatus_Accepted;
  16865. }
  16866. else
  16867. isSuccess = ConfigurationStatus_Rejected;
  16868. }
  16869. }
  16870. else
  16871. {
  16872. isSuccess = ConfigurationStatus_Rejected;
  16873. }
  16874. }
  16875. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16876. {
  16877. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16878. {
  16879. strcpy(str, (const char*)value);
  16880. for(int i = 0; str[i]; i++)
  16881. {
  16882. str[i] = tolower(str[i]);
  16883. }
  16884. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16885. isSuccess = ConfigurationStatus_Accepted;
  16886. }
  16887. else
  16888. {
  16889. isSuccess = ConfigurationStatus_Rejected;
  16890. }
  16891. }
  16892. if(strcmp(key, "AuthorizationKey") == 0)
  16893. {
  16894. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16895. {
  16896. strcpy(str, (const char*)value);
  16897. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16898. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16899. isSuccess = ConfigurationStatus_Accepted;
  16900. }
  16901. else
  16902. {
  16903. isSuccess = ConfigurationStatus_Rejected;
  16904. }
  16905. }
  16906. if(strcmp(key, "SecurityProfile") == 0)
  16907. {
  16908. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16909. {
  16910. check_ascii = value[0];
  16911. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16912. {
  16913. isSuccess = ConfigurationStatus_Rejected;
  16914. }
  16915. else if(check_ascii == 0x33)
  16916. {
  16917. isSuccess = NotSupported;
  16918. }
  16919. else
  16920. {
  16921. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16922. {
  16923. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16924. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  16925. isSuccess = ConfigurationStatus_Accepted;
  16926. }
  16927. else
  16928. isSuccess = ConfigurationStatus_Rejected;
  16929. }
  16930. }
  16931. else
  16932. {
  16933. isSuccess = ConfigurationStatus_Rejected;
  16934. }
  16935. }
  16936. if(strcmp(key, "DefaultPrice") == 0)
  16937. {
  16938. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16939. {
  16940. strcpy(str, (const char*)value);
  16941. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16942. isSuccess = ConfigurationStatus_Accepted;
  16943. }
  16944. else
  16945. {
  16946. isSuccess = ConfigurationStatus_Rejected;
  16947. }
  16948. }
  16949. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16950. {
  16951. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16952. {
  16953. strcpy(str, (const char*)value);
  16954. for(int i = 0; str[i]; i++)
  16955. {
  16956. str[i] = tolower(str[i]);
  16957. }
  16958. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16959. isSuccess = ConfigurationStatus_Accepted;
  16960. }
  16961. else
  16962. {
  16963. isSuccess = ConfigurationStatus_Rejected;
  16964. }
  16965. }
  16966. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16967. {
  16968. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16969. {
  16970. strcpy(str, (const char*)value);
  16971. for(int i = 0; str[i]; i++)
  16972. {
  16973. str[i] = tolower(str[i]);
  16974. }
  16975. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16976. isSuccess = ConfigurationStatus_Accepted;
  16977. }
  16978. else
  16979. {
  16980. isSuccess = ConfigurationStatus_Rejected;
  16981. }
  16982. }
  16983. if(strcmp(key, "TimeOffset") == 0)
  16984. {
  16985. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  16986. {
  16987. strcpy(str, (const char*)value);
  16988. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  16989. isSuccess = ConfigurationStatus_Accepted;
  16990. }
  16991. else
  16992. {
  16993. isSuccess = ConfigurationStatus_Rejected;
  16994. }
  16995. }
  16996. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  16997. {
  16998. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  16999. {
  17000. strcpy(str, (const char*)value);
  17001. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  17002. isSuccess = ConfigurationStatus_Accepted;
  17003. }
  17004. else
  17005. {
  17006. isSuccess = ConfigurationStatus_Rejected;
  17007. }
  17008. }
  17009. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  17010. {
  17011. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  17012. {
  17013. strcpy(str, (const char*)value);
  17014. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  17015. isSuccess = ConfigurationStatus_Accepted;
  17016. }
  17017. else
  17018. {
  17019. isSuccess = ConfigurationStatus_Rejected;
  17020. }
  17021. }
  17022. if(strcmp(key, "SystemUptimeSec") == 0)
  17023. {
  17024. isSuccess = NotSupported;
  17025. }
  17026. if(strcmp(key, "FreeVend") == 0)
  17027. {
  17028. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17029. {
  17030. strcpy(str, (const char*)value);
  17031. for(int i = 0; str[i]; i++)
  17032. {
  17033. str[i] = tolower(str[i]);
  17034. }
  17035. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  17036. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17037. isSuccess = ConfigurationStatus_Accepted;
  17038. }
  17039. else
  17040. {
  17041. isSuccess = ConfigurationStatus_Rejected;
  17042. }
  17043. }
  17044. if(strcmp(key, "FreeVendIdtag") == 0)
  17045. {
  17046. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17047. {
  17048. strcpy(str, (const char*)value);
  17049. if(strlen(str) <= 20)
  17050. {
  17051. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  17052. isSuccess = ConfigurationStatus_Accepted;
  17053. }
  17054. else
  17055. {
  17056. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  17057. isSuccess = ConfigurationStatus_Rejected;
  17058. }
  17059. }
  17060. else
  17061. {
  17062. isSuccess = ConfigurationStatus_Rejected;
  17063. }
  17064. }
  17065. if(strcmp(key, "OcppServer") == 0)
  17066. {
  17067. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17068. {
  17069. strcpy(str, (const char*)value);
  17070. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  17071. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  17072. isSuccess = ConfigurationStatus_Accepted;
  17073. }
  17074. else
  17075. {
  17076. isSuccess = ConfigurationStatus_Rejected;
  17077. }
  17078. }
  17079. if(strcmp(key, "MaintainServer") == 0)
  17080. {
  17081. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17082. {
  17083. strcpy(str, (const char*)value);
  17084. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  17085. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  17086. isSuccess = ConfigurationStatus_Accepted;
  17087. }
  17088. else
  17089. {
  17090. isSuccess = ConfigurationStatus_Rejected;
  17091. }
  17092. }
  17093. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  17094. {
  17095. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17096. {
  17097. strcpy(str, (const char*)value);
  17098. for(int i = 0; str[i]; i++)
  17099. {
  17100. str[i] = tolower(str[i]);
  17101. }
  17102. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  17103. isSuccess = ConfigurationStatus_Accepted;
  17104. }
  17105. else
  17106. {
  17107. isSuccess = ConfigurationStatus_Rejected;
  17108. }
  17109. }
  17110. if(strcmp(key, "StatusNotificationInterval") == 0)
  17111. {
  17112. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17113. {
  17114. check_ascii = value[0];
  17115. if( (check_ascii < 48) || (check_ascii > 57) )
  17116. {
  17117. isSuccess = ConfigurationStatus_Rejected;
  17118. }
  17119. else
  17120. {
  17121. if((atoi(value) == 0) || (atoi(value) >= 10))
  17122. {
  17123. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  17124. isSuccess = ConfigurationStatus_Accepted;
  17125. }
  17126. else
  17127. isSuccess = ConfigurationStatus_Rejected;
  17128. }
  17129. }
  17130. else
  17131. {
  17132. isSuccess = ConfigurationStatus_Rejected;
  17133. }
  17134. }
  17135. if(strcmp(key, "PreAuthAmount") == 0)
  17136. {
  17137. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  17138. {
  17139. check_ascii = value[0];
  17140. if( (check_ascii < 48) || (check_ascii > 57) )
  17141. {
  17142. isSuccess = ConfigurationStatus_Rejected;
  17143. }
  17144. else
  17145. {
  17146. if(atof(value) >= 0)
  17147. {
  17148. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(value) );
  17149. isSuccess = ConfigurationStatus_Accepted;
  17150. }
  17151. else
  17152. isSuccess = ConfigurationStatus_Rejected;
  17153. }
  17154. }
  17155. else
  17156. {
  17157. isSuccess = ConfigurationStatus_Rejected;
  17158. }
  17159. }
  17160. #if 0
  17161. //For OCPP Test Case
  17162. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  17163. {
  17164. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17165. {
  17166. strcpy(str, (const char*)value);
  17167. for(int i = 0; str[i]; i++)
  17168. {
  17169. str[i] = tolower(str[i]);
  17170. }
  17171. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17172. isSuccess = ConfigurationStatus_Accepted;
  17173. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17174. }
  17175. else
  17176. {
  17177. isSuccess = ConfigurationStatus_Rejected;
  17178. }
  17179. }
  17180. #endif
  17181. #if 1
  17182. if(strcmp(key, "LocalAuthListEnabled") == 0)
  17183. {
  17184. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17185. {
  17186. strcpy(str, (const char*)value);
  17187. for(int i = 0; str[i]; i++)
  17188. {
  17189. str[i] = tolower(str[i]);
  17190. }
  17191. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17192. isSuccess = ConfigurationStatus_Accepted;
  17193. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17194. }
  17195. else
  17196. {
  17197. isSuccess = ConfigurationStatus_Rejected;
  17198. }
  17199. }
  17200. #endif
  17201. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  17202. {
  17203. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  17204. {
  17205. check_ascii = value[0];
  17206. if( (check_ascii < 48) || (check_ascii > 57) )
  17207. {
  17208. isSuccess = ConfigurationStatus_Rejected;
  17209. }
  17210. else
  17211. {
  17212. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  17213. isSuccess = ConfigurationStatus_Accepted;
  17214. }
  17215. }
  17216. else
  17217. {
  17218. isSuccess = ConfigurationStatus_Rejected;
  17219. }
  17220. }
  17221. if(strcmp(key, "SendLocalListMaxLength") == 0)
  17222. {
  17223. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17224. {
  17225. check_ascii = value[0];
  17226. if( (check_ascii < 48) || (check_ascii > 57) )
  17227. {
  17228. isSuccess = ConfigurationStatus_Rejected;
  17229. }
  17230. else
  17231. {
  17232. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  17233. isSuccess = ConfigurationStatus_Accepted;
  17234. }
  17235. }
  17236. else
  17237. {
  17238. isSuccess = ConfigurationStatus_Rejected;
  17239. }
  17240. }
  17241. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  17242. {
  17243. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17244. {
  17245. strcpy(str, (const char*)value);
  17246. for(int i = 0; str[i]; i++)
  17247. {
  17248. str[i] = tolower(str[i]);
  17249. }
  17250. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17251. isSuccess = ConfigurationStatus_Accepted;
  17252. }
  17253. else
  17254. {
  17255. isSuccess = ConfigurationStatus_Rejected;
  17256. }
  17257. }
  17258. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  17259. {
  17260. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17261. {
  17262. check_ascii = value[0];
  17263. if( (check_ascii < 48) || (check_ascii > 57) )
  17264. {
  17265. isSuccess = ConfigurationStatus_Rejected;
  17266. }
  17267. else
  17268. {
  17269. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  17270. isSuccess = ConfigurationStatus_Accepted;
  17271. }
  17272. }
  17273. else
  17274. {
  17275. isSuccess = ConfigurationStatus_Rejected;
  17276. }
  17277. }
  17278. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  17279. {
  17280. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17281. {
  17282. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  17283. isSuccess = ConfigurationStatus_Accepted;
  17284. }
  17285. else
  17286. {
  17287. isSuccess = ConfigurationStatus_Rejected;
  17288. }
  17289. }
  17290. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  17291. {
  17292. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17293. {
  17294. check_ascii = value[0];
  17295. if( (check_ascii < 48) || (check_ascii > 57) )
  17296. {
  17297. isSuccess = ConfigurationStatus_Rejected;
  17298. }
  17299. else
  17300. {
  17301. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  17302. isSuccess = ConfigurationStatus_Accepted;
  17303. }
  17304. }
  17305. else
  17306. {
  17307. isSuccess = ConfigurationStatus_Rejected;
  17308. }
  17309. }
  17310. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  17311. {
  17312. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17313. {
  17314. strcpy(str, (const char*)value);
  17315. for(int i = 0; str[i]; i++)
  17316. {
  17317. str[i] = tolower(str[i]);
  17318. }
  17319. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17320. isSuccess = ConfigurationStatus_Accepted;
  17321. }
  17322. else
  17323. {
  17324. isSuccess = ConfigurationStatus_Rejected;
  17325. }
  17326. }
  17327. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  17328. {
  17329. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  17330. {
  17331. check_ascii = value[0];
  17332. if( (check_ascii < 48) || (check_ascii > 57) )
  17333. {
  17334. isSuccess = ConfigurationStatus_Rejected;
  17335. }
  17336. else
  17337. {
  17338. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  17339. isSuccess = ConfigurationStatus_Accepted;
  17340. }
  17341. }
  17342. else
  17343. {
  17344. isSuccess = ConfigurationStatus_Rejected;
  17345. }
  17346. }
  17347. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17348. return isSuccess;
  17349. }
  17350. int TransactionMessageAttemptsGet(void)
  17351. {
  17352. return TransactionMessageAttemptsValue;
  17353. }
  17354. int FirstHeartBeatResponse(void)
  17355. {
  17356. return FirstHeartBeat;
  17357. }
  17358. int TransactionMessageRetryIntervalGet(void)
  17359. {
  17360. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17361. }
  17362. int ReadHttpStatus(int sock)
  17363. {
  17364. //char c;
  17365. char buff[1024]="",*ptr=buff+1;
  17366. int bytes_received, status;
  17367. DEBUG_INFO("Begin Response ..\n");
  17368. while((bytes_received = recv(sock, ptr, 1, 0))){
  17369. if(bytes_received==-1){
  17370. perror("ReadHttpStatus");
  17371. exit(1);
  17372. }
  17373. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  17374. ptr++;
  17375. }
  17376. *ptr=0;
  17377. ptr=buff+1;
  17378. sscanf(ptr,"%*s %d ", &status);
  17379. DEBUG_INFO("%s\n",ptr);
  17380. DEBUG_INFO("status=%d\n",status);
  17381. DEBUG_INFO("End Response ..\n");
  17382. return (bytes_received>0)?status:0;
  17383. }
  17384. //the only filed that it parsed is 'Content-Length'
  17385. int ParseHeader(int sock)
  17386. {
  17387. //char c;
  17388. char buff[1024]="",*ptr=buff+4;
  17389. int bytes_received;
  17390. DEBUG_INFO("Begin HEADER ..\n");
  17391. while((bytes_received = recv(sock, ptr, 1, 0))){
  17392. if(bytes_received==-1){
  17393. perror("Parse Header");
  17394. exit(1);
  17395. }
  17396. if(
  17397. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  17398. (ptr[-1]=='\r') && (*ptr=='\n' )
  17399. ) break;
  17400. ptr++;
  17401. }
  17402. *ptr=0;
  17403. ptr=buff+4;
  17404. //printf("%s",ptr);
  17405. if(bytes_received){
  17406. ptr=strstr(ptr,"Content-Length:");
  17407. if(ptr){
  17408. sscanf(ptr,"%*s %d",&bytes_received);
  17409. }else
  17410. bytes_received=-1; //unknown size
  17411. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  17412. }
  17413. DEBUG_INFO("End HEADER ..\n");
  17414. return bytes_received ;
  17415. }
  17416. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  17417. {
  17418. int result = TRUE;
  17419. char rmFileCmd[100]={0};
  17420. char FilePath[100]={0};
  17421. char ftpbuf[200];
  17422. int systemresult;
  17423. sprintf(FilePath,"/mnt/%s",filename);
  17424. system("ping 8.8.8.8 &");
  17425. if((access(FilePath,F_OK))!=-1)
  17426. {
  17427. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17428. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17429. system(rmFileCmd);
  17430. }
  17431. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17432. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  17433. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17434. systemresult = system(ftpbuf);
  17435. if(systemresult != 0)
  17436. {
  17437. DEBUG_INFO("http DownLoad error!\n");
  17438. result = FALSE;
  17439. }
  17440. system("pkill ping");
  17441. return result;
  17442. }
  17443. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  17444. {
  17445. int result = TRUE;
  17446. char rmFileCmd[100]={0};
  17447. char FilePath[100]={0};
  17448. char ftpbuf[200];
  17449. int systemresult;
  17450. sprintf(FilePath,"/mnt/%s",filename);
  17451. system("ping 8.8.8.8 &");
  17452. if((access(FilePath,F_OK))!=-1)
  17453. {
  17454. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17455. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17456. system(rmFileCmd);
  17457. }
  17458. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17459. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  17460. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17461. systemresult = system(ftpbuf);
  17462. if(systemresult != 0)
  17463. {
  17464. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  17465. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17466. systemresult = system(ftpbuf);
  17467. if(systemresult != 0)
  17468. {
  17469. DEBUG_WARN("wget error!\n");
  17470. result = FALSE;
  17471. }
  17472. }
  17473. system("pkill ping");
  17474. return result;
  17475. }
  17476. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17477. {
  17478. char rmFileCmd[100]={0};
  17479. char FilePath[100]={0};
  17480. char buf[512];
  17481. int systemresult = 0;
  17482. //DEBUG_INFO("filename=%s\n",filename);
  17483. //DEBUG_INFO("url=%s\n",url);
  17484. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17485. if((access(FilePath,F_OK))!=-1)
  17486. {
  17487. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17488. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17489. system(rmFileCmd);
  17490. }
  17491. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17492. if(fp == NULL)
  17493. {
  17494. DEBUG_INFO("log is NULL\n");
  17495. return FALSE;
  17496. }
  17497. else
  17498. {
  17499. fprintf(fp, "%s\n", url);
  17500. fprintf(fp, "%s\n", filename);
  17501. fclose(fp);
  17502. }
  17503. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  17504. if(phpFP == NULL)
  17505. {
  17506. DEBUG_INFO("PHP upload fail.\n");
  17507. return FALSE;
  17508. }
  17509. else
  17510. {
  17511. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17512. {
  17513. if(strstr(buf, "result") != NULL)
  17514. {
  17515. sscanf(buf, "result: %d", &systemresult);
  17516. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17517. }
  17518. }
  17519. pclose(phpFP);
  17520. }
  17521. if(systemresult != 1)
  17522. {
  17523. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  17524. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  17525. if(phpFP == NULL)
  17526. {
  17527. DEBUG_WARN("PHP PUT upload fail.\n");
  17528. return FALSE;
  17529. }
  17530. else
  17531. {
  17532. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17533. {
  17534. if(strstr(buf, "result") != NULL)
  17535. {
  17536. sscanf(buf, "result: %d", &systemresult);
  17537. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  17538. }
  17539. }
  17540. pclose(phpFP);
  17541. }
  17542. }
  17543. return TRUE;
  17544. }
  17545. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17546. {
  17547. int result = FALSE;
  17548. char ftpbuf[200];
  17549. int systemresult;
  17550. /*
  17551. // Domaind name transfer to IP address
  17552. struct hostent* server;
  17553. char *IPbuffer;
  17554. server = gethostbyname(location);
  17555. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17556. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17557. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17558. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  17559. systemresult = system(ftpbuf);
  17560. if(systemresult != 0)
  17561. {
  17562. DEBUG_INFO("ftpput error!\n");
  17563. }
  17564. else
  17565. {
  17566. result = TRUE;
  17567. DEBUG_INFO("ftpput OK!\n");
  17568. }
  17569. return result;
  17570. }
  17571. int GetOcppServerURL()
  17572. {
  17573. int result = FALSE;
  17574. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  17575. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  17576. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  17577. struct yuarel url;
  17578. char urlStr[512];
  17579. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  17580. {
  17581. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  17582. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17583. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17584. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  17585. if(yuarel_parse(&url, urlStr) != -1)
  17586. {
  17587. sprintf(OcppProtocol, "%s", url.scheme);
  17588. sprintf(OcppHost, "%s", url.host);
  17589. if(url.path == NULL)
  17590. OcppTempPath[0] = '\0';
  17591. else
  17592. {
  17593. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  17594. {
  17595. sprintf(OcppTempPath, "%s/", url.path);
  17596. }
  17597. else
  17598. {
  17599. sprintf(OcppTempPath, "%s", url.path);
  17600. }
  17601. }
  17602. if(url.port == 0)
  17603. {
  17604. if(strcmp(OcppProtocol, "wss") == 0)
  17605. OcppPort = 443;
  17606. else
  17607. OcppPort = 80;
  17608. }
  17609. else
  17610. OcppPort = url.port;
  17611. result = TRUE;
  17612. }
  17613. }
  17614. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  17615. {
  17616. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  17617. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17618. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17619. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  17620. if(yuarel_parse(&url, urlStr) != -1)
  17621. {
  17622. sprintf(OcppProtocol, "%s", url.scheme);
  17623. sprintf(OcppHost, "%s", url.host);
  17624. if(url.path == NULL)
  17625. OcppTempPath[0] = '\0';
  17626. else
  17627. sprintf(OcppTempPath, "%s", url.path);
  17628. if(url.port == 0)
  17629. {
  17630. if(strcmp(OcppProtocol, "wss") == 0)
  17631. OcppPort = 443;
  17632. else
  17633. OcppPort = 80;
  17634. }
  17635. else
  17636. OcppPort = url.port;
  17637. result = TRUE;
  17638. }
  17639. }
  17640. else
  17641. {
  17642. strcpy(OcppHost,"");
  17643. }
  17644. return result;
  17645. }
  17646. int GetOcppPath()
  17647. {
  17648. int result = FALSE;
  17649. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  17650. {
  17651. if(OcppTempPath == NULL)
  17652. {
  17653. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17654. }
  17655. else
  17656. {
  17657. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17658. }
  17659. result = TRUE;
  17660. goto End;
  17661. }
  17662. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  17663. {
  17664. if(OcppTempPath == NULL)
  17665. {
  17666. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  17667. }
  17668. else
  17669. {
  17670. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  17671. }
  17672. result = TRUE;
  17673. goto End;
  17674. }
  17675. else
  17676. {
  17677. strcpy(OcppPath,"");
  17678. }
  17679. End:
  17680. return result;
  17681. }
  17682. int GetOcppPort()
  17683. {
  17684. return OcppPort;
  17685. }
  17686. int GetOcppConnStatus(void)
  17687. {
  17688. return ShmOCPP16Data->OcppConnStatus;
  17689. }
  17690. void SetOcppConnStatus(uint8_t status)
  17691. {
  17692. ShmOCPP16Data->OcppConnStatus = status;
  17693. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  17694. }
  17695. int GetHeartBeatWithNOResponse(void)
  17696. {
  17697. return HeartBeatWithNOResponse;
  17698. }
  17699. void SetHeartBeatWithNOResponse(void)
  17700. {
  17701. HeartBeatWithNOResponse = 0;
  17702. }
  17703. void GetStartTransactionIdTag(int gun_index)
  17704. {
  17705. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17706. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17707. }
  17708. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17709. {
  17710. char ch;
  17711. FILE *fptr1;
  17712. int temptransactionId;
  17713. char str[100]={0};
  17714. temptransactionId = 0;
  17715. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17716. {
  17717. DEBUG_INFO("IdTag is empty.\n");
  17718. return temptransactionId;
  17719. }
  17720. /*------ Read the file ----------------*/
  17721. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  17722. if (!fptr1)
  17723. {
  17724. DEBUG_INFO("QueueTransactionId file open error.\n");
  17725. //printf(" File not found or unable to open the input file!!\n");
  17726. return temptransactionId;
  17727. }
  17728. ch=fgetc(fptr1);
  17729. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  17730. rewind(fptr1);
  17731. if(ch!=EOF)
  17732. {
  17733. // printf("%c",ch);
  17734. while (fgets(str, 100, fptr1) != NULL)
  17735. {
  17736. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17737. if(str[0]=='\0')
  17738. {
  17739. break;
  17740. }
  17741. char *revbuf[8] = {0}; // Variable store string split
  17742. int num = 0;// Quantity after string split
  17743. DEBUG_INFO("Transaction queue data= %s\n", str);
  17744. splitstring(str,",",revbuf,&num); // String split
  17745. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17746. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17747. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17748. DEBUG_INFO("------------------------------\n");
  17749. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17750. {
  17751. if(isStopTransaction)
  17752. {
  17753. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17754. {
  17755. temptransactionId = atoi(revbuf[2]);
  17756. //break;
  17757. }
  17758. }
  17759. else
  17760. {
  17761. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17762. {
  17763. temptransactionId = atoi(revbuf[2]);
  17764. //break;
  17765. }
  17766. }
  17767. }
  17768. }
  17769. }
  17770. else
  17771. DEBUG_INFO("EOF\n");
  17772. fclose(fptr1);
  17773. /*------- End of reading ---------------*/
  17774. return temptransactionId;
  17775. }
  17776. void SetTransactionIdZero(int transactionId)
  17777. {
  17778. char ch;
  17779. FILE *fptr1, *fptr2;
  17780. int temptransactionId = 0;
  17781. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  17782. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  17783. if (!fptr1)
  17784. {
  17785. //printf(" File not found or unable to open the input file!!\n");
  17786. return ;
  17787. }
  17788. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17789. if (!fptr2)
  17790. {
  17791. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17792. fclose(fptr1);
  17793. return ;
  17794. }
  17795. ch=fgetc(fptr1);
  17796. rewind(fptr1);
  17797. if(ch!=EOF)
  17798. {
  17799. // copy all contents to the temporary file except the specific line
  17800. while (fgets(str, 100, fptr1) != NULL)
  17801. {
  17802. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17803. if(str[0]=='\0')
  17804. {
  17805. break;
  17806. }
  17807. char *revbuf[8] = {0};
  17808. int num = 0;
  17809. strcpy(strtemp, str);
  17810. splitstring(str,",",revbuf,&num);
  17811. if(revbuf[2][0] != '\0')
  17812. {
  17813. temptransactionId = atoi(revbuf[2]);
  17814. if(transactionId != temptransactionId)
  17815. {
  17816. fprintf(fptr2, "%s\n", strtemp);
  17817. }
  17818. }
  17819. }
  17820. }
  17821. fclose(fptr1);
  17822. fclose(fptr2);
  17823. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  17824. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  17825. /*------ Read the file ----------------*/
  17826. }
  17827. int InternetDisconnect(void)
  17828. {
  17829. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  17830. }
  17831. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17832. void storeTempStopTransaction(int gun_index)
  17833. {
  17834. char guid[37]={0};
  17835. int tempIndex = 0;
  17836. char TempStopTransaction[256];
  17837. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  17838. DEBUG_INFO("storeTempStopTransaction...\n");
  17839. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  17840. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  17841. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  17842. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17843. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17844. {
  17845. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17846. {
  17847. tempIndex = ((gun_index==2) ? 1: 0);
  17848. }
  17849. else
  17850. {
  17851. tempIndex = gun_index;
  17852. }
  17853. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17854. {
  17855. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17856. {
  17857. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  17858. }
  17859. }// END OF CHAdeMO_QUANTITY
  17860. }
  17861. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17862. {
  17863. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17864. {
  17865. tempIndex = ((gun_index==2) ? 1: 0);
  17866. }
  17867. else
  17868. {
  17869. tempIndex = gun_index;
  17870. }
  17871. for (int index = 0; index < CCS_QUANTITY; index++)
  17872. {
  17873. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17874. {
  17875. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  17876. }
  17877. }// END OF CCS_QUANTITY
  17878. }
  17879. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17880. {
  17881. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17882. {
  17883. tempIndex = ((gun_index==2) ? 1: 0);
  17884. }
  17885. else
  17886. {
  17887. tempIndex = gun_index;
  17888. }
  17889. for (int index = 0; index < GB_QUANTITY; index++)
  17890. {
  17891. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17892. {
  17893. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17894. }
  17895. }// END OF GB_QUANTITY
  17896. }
  17897. else if(gunType[gun_index] == GUN_TYPE_DO)
  17898. {
  17899. tempIndex = gun_index;
  17900. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17901. {
  17902. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17903. {
  17904. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17905. }
  17906. }
  17907. }
  17908. else
  17909. {
  17910. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17911. {
  17912. tempIndex = 2;
  17913. }
  17914. else
  17915. {
  17916. tempIndex = gun_index;
  17917. }
  17918. for (int index = 0; index < AC_QUANTITY; index++)
  17919. {
  17920. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17921. {
  17922. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17923. }
  17924. }// END OF AC_QUANTITY
  17925. }
  17926. //Stop Transaction Time
  17927. struct timeval tmnow;
  17928. struct tm *tm;
  17929. char buf[28];//, usec_buf[6];
  17930. gettimeofday(&tmnow, NULL);
  17931. time_t t;
  17932. t = time(NULL);
  17933. /*UTC time and date*/
  17934. tm = gmtime(&t);
  17935. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17936. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  17937. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  17938. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17939. random_uuid(guid);
  17940. /***********************************transactionData******************************************************/
  17941. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17942. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17943. //=================================
  17944. //1. Transaction_Begin
  17945. //=================================
  17946. //============================== Energy.Active.Import.Interval ===========================================
  17947. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17948. {
  17949. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  17950. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17951. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  17952. 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*/]);
  17953. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17954. 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))
  17955. {
  17956. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  17957. }
  17958. else
  17959. {
  17960. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  17961. }
  17962. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  17963. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17964. }
  17965. //=================================
  17966. //2. Transaction_End
  17967. //=================================
  17968. //2.1====================================== Current.Import L1 ==============================================
  17969. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17970. {
  17971. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17972. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17973. {
  17974. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17975. {
  17976. tempIndex = ((gun_index==2) ? 1: 0);
  17977. }
  17978. else
  17979. {
  17980. tempIndex = gun_index;
  17981. }
  17982. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17983. {
  17984. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17985. {
  17986. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17987. }
  17988. }// End of for CHAdeMO_QUANTITY
  17989. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17990. }
  17991. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17992. {
  17993. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17994. {
  17995. tempIndex = ((gun_index==2) ? 1: 0);
  17996. }
  17997. else
  17998. {
  17999. tempIndex = gun_index;
  18000. }
  18001. for (int index = 0; index < CCS_QUANTITY; index++)
  18002. {
  18003. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18004. {
  18005. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18006. }
  18007. }// End of for CCS_QUANTITY
  18008. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18009. }
  18010. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18011. {
  18012. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18013. {
  18014. tempIndex = ((gun_index==2) ? 1: 0);
  18015. }
  18016. else
  18017. {
  18018. tempIndex = gun_index;
  18019. }
  18020. for (int index = 0; index < GB_QUANTITY; index++)
  18021. {
  18022. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18023. {
  18024. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18025. }
  18026. }// End of for GB_QUANTITY
  18027. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18028. }
  18029. else if(gunType[gun_index] == GUN_TYPE_DO)
  18030. {
  18031. tempIndex = gun_index;
  18032. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18033. {
  18034. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18035. {
  18036. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18037. }
  18038. }
  18039. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18040. }
  18041. else
  18042. {
  18043. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18044. {
  18045. tempIndex = 2;
  18046. }
  18047. else
  18048. {
  18049. tempIndex = gun_index;
  18050. }
  18051. for (int index = 0; index < AC_QUANTITY; index++)
  18052. {
  18053. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18054. {
  18055. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  18056. }
  18057. }// End of for AC_QUANTITY
  18058. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18059. }
  18060. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18061. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  18062. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  18063. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18064. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  18065. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18066. }
  18067. //2.2===================================== Energy.Active.Import.Interval ==========================================
  18068. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  18069. {
  18070. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18071. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18072. {
  18073. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18074. {
  18075. tempIndex = ((gun_index==2) ? 1: 0);
  18076. }
  18077. else
  18078. {
  18079. tempIndex = gun_index;
  18080. }
  18081. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18082. {
  18083. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18084. {
  18085. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  18086. }
  18087. }// END OF CHAdeMO_QUANTITY
  18088. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18089. }
  18090. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18091. {
  18092. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18093. {
  18094. tempIndex = ((gun_index==2) ? 1: 0);
  18095. }
  18096. else
  18097. {
  18098. tempIndex = gun_index;
  18099. }
  18100. for (int index = 0; index < CCS_QUANTITY; index++)
  18101. {
  18102. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18103. {
  18104. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  18105. }
  18106. }// END OF CCS_QUANTITY
  18107. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18108. }
  18109. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18110. {
  18111. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18112. {
  18113. tempIndex = ((gun_index==2) ? 1: 0);
  18114. }
  18115. else
  18116. {
  18117. tempIndex = gun_index;
  18118. }
  18119. for (int index = 0; index < GB_QUANTITY; index++)
  18120. {
  18121. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18122. {
  18123. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  18124. }
  18125. }// END OF GB_QUANTITY
  18126. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18127. }
  18128. else if(gunType[gun_index] == GUN_TYPE_DO)
  18129. {
  18130. tempIndex = gun_index;
  18131. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18132. {
  18133. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18134. {
  18135. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  18136. }
  18137. }
  18138. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18139. }
  18140. else
  18141. {
  18142. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18143. {
  18144. tempIndex = 2;
  18145. }
  18146. else
  18147. {
  18148. tempIndex = gun_index;
  18149. }
  18150. for (int index = 0; index < AC_QUANTITY; index++)
  18151. {
  18152. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18153. {
  18154. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  18155. }
  18156. }// END OF AC_QUANTITY
  18157. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18158. }
  18159. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18160. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  18161. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  18162. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18163. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  18164. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  18165. }
  18166. //2.3====================================== Power.Active.Import =========================================
  18167. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  18168. {
  18169. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18170. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18171. {
  18172. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18173. {
  18174. tempIndex = ((gun_index==2) ? 1: 0);
  18175. }
  18176. else
  18177. {
  18178. tempIndex = gun_index;
  18179. }
  18180. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18181. {
  18182. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18183. {
  18184. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18185. }
  18186. } // End for CHAdeMO_QUANTITY
  18187. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18188. }
  18189. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18190. {
  18191. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18192. {
  18193. tempIndex = ((gun_index==2) ? 1: 0);
  18194. }
  18195. else
  18196. {
  18197. tempIndex = gun_index;
  18198. }
  18199. for (int index = 0; index < CCS_QUANTITY; index++)
  18200. {
  18201. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18202. {
  18203. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18204. }
  18205. } // END for CCS_QUANTITY
  18206. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18207. }
  18208. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18209. {
  18210. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18211. {
  18212. tempIndex = ((gun_index==2) ? 1: 0);
  18213. }
  18214. else
  18215. {
  18216. tempIndex = gun_index;
  18217. }
  18218. for (int index = 0; index < GB_QUANTITY; index++)
  18219. {
  18220. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18221. {
  18222. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18223. }
  18224. }// END for GB_QUANTITY
  18225. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18226. }
  18227. else if(gunType[gun_index] == GUN_TYPE_DO)
  18228. {
  18229. tempIndex = gun_index;
  18230. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18231. {
  18232. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18233. {
  18234. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18235. }
  18236. }
  18237. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18238. }
  18239. else
  18240. {
  18241. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18242. {
  18243. tempIndex = 2;
  18244. }
  18245. else
  18246. {
  18247. tempIndex = gun_index;
  18248. }
  18249. for (int index = 0; index < AC_QUANTITY; index++)
  18250. {
  18251. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18252. {
  18253. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18254. }
  18255. } // END for AC_QUANTITY
  18256. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18257. }
  18258. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18259. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  18260. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  18261. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18262. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  18263. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  18264. }
  18265. //2.4====================================== Voltage L1 ====================================================
  18266. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18267. {
  18268. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18269. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18270. {
  18271. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18272. {
  18273. tempIndex = ((gun_index==2) ? 1: 0);
  18274. }
  18275. else
  18276. {
  18277. tempIndex = gun_index;
  18278. }
  18279. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18280. {
  18281. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18282. {
  18283. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18284. }
  18285. } // END OF FOR CHAdeMO_QUANTITY
  18286. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18287. }
  18288. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18289. {
  18290. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18291. {
  18292. tempIndex = ((gun_index==2) ? 1: 0);
  18293. }
  18294. else
  18295. {
  18296. tempIndex = gun_index;
  18297. }
  18298. for (int index = 0; index < CCS_QUANTITY; index++)
  18299. {
  18300. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18301. {
  18302. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18303. }
  18304. } // END OF FOR CCS_QUANTITY
  18305. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18306. }
  18307. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18308. {
  18309. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18310. {
  18311. tempIndex = ((gun_index==2) ? 1: 0);
  18312. }
  18313. else
  18314. {
  18315. tempIndex = gun_index;
  18316. }
  18317. for (int index = 0; index < GB_QUANTITY; index++)
  18318. {
  18319. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18320. {
  18321. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18322. }
  18323. } // END OF FOR GB_QUANTITY
  18324. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18325. }
  18326. else if(gunType[gun_index] == GUN_TYPE_DO)
  18327. {
  18328. tempIndex = gun_index;
  18329. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18330. {
  18331. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18332. {
  18333. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18334. }
  18335. }
  18336. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18337. }
  18338. else
  18339. {
  18340. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18341. {
  18342. tempIndex = 2;
  18343. }
  18344. else
  18345. {
  18346. tempIndex = gun_index;
  18347. }
  18348. for (int index = 0; index < AC_QUANTITY; index++)
  18349. {
  18350. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18351. {
  18352. 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
  18353. }
  18354. } // END OF FOR AC_QUANTITY
  18355. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18356. }
  18357. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18358. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  18359. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  18360. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18361. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  18362. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18363. }
  18364. //2.5============================================== End SoC =========================================================
  18365. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18366. {
  18367. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18368. 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))
  18369. {
  18370. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18371. {
  18372. tempIndex = ((gun_index==2) ? 1: 0);
  18373. }
  18374. else
  18375. {
  18376. tempIndex = gun_index;
  18377. }
  18378. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18379. {
  18380. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18381. {
  18382. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18383. {
  18384. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  18385. }
  18386. }
  18387. }
  18388. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18389. {
  18390. for (int index = 0; index < CCS_QUANTITY; index++)
  18391. {
  18392. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18393. {
  18394. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  18395. }
  18396. }
  18397. }
  18398. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18399. {
  18400. for (int index = 0; index < GB_QUANTITY; index++)
  18401. {
  18402. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18403. {
  18404. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  18405. }
  18406. }
  18407. }
  18408. else if(gunType[gun_index] == GUN_TYPE_DO)
  18409. {
  18410. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18411. {
  18412. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18413. {
  18414. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  18415. }
  18416. }
  18417. }
  18418. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18419. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  18420. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18421. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  18422. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  18423. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18424. } // END FOR DC CASE
  18425. }
  18426. //2.6====================================== Current.Import L2 ==============================================
  18427. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18428. {
  18429. // AC 3 phase L2 current
  18430. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18431. {
  18432. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18433. {
  18434. tempIndex = 2;
  18435. }
  18436. else
  18437. {
  18438. tempIndex = gun_index;
  18439. }
  18440. for (int index = 0; index < AC_QUANTITY; index++)
  18441. {
  18442. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18443. {
  18444. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  18445. }
  18446. }// End of for AC_QUANTITY
  18447. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  18448. }
  18449. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18450. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  18451. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  18452. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  18453. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18454. }
  18455. //2.7====================================== Current.Import L3 ==============================================
  18456. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18457. {
  18458. // AC 3 phase L3 current
  18459. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18460. {
  18461. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18462. {
  18463. tempIndex = 2;
  18464. }
  18465. else
  18466. {
  18467. tempIndex = gun_index;
  18468. }
  18469. for (int index = 0; index < AC_QUANTITY; index++)
  18470. {
  18471. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18472. {
  18473. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  18474. }
  18475. }// End of for AC_QUANTITY
  18476. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  18477. }
  18478. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18479. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  18480. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  18481. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  18482. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18483. }
  18484. //2.9====================================== Voltage L2 ====================================================
  18485. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18486. {
  18487. // AC 3 phase L2 volatge
  18488. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18489. {
  18490. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18491. {
  18492. tempIndex = 2;
  18493. }
  18494. else
  18495. {
  18496. tempIndex = gun_index;
  18497. }
  18498. for (int index = 0; index < AC_QUANTITY; index++)
  18499. {
  18500. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18501. {
  18502. 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
  18503. }
  18504. } // END OF FOR AC_QUANTITY
  18505. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  18506. }
  18507. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18508. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  18509. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  18510. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  18511. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18512. }
  18513. //2.10====================================== Voltage L3 ====================================================
  18514. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18515. {
  18516. // AC 3 phase L3 volatge
  18517. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18518. {
  18519. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18520. {
  18521. tempIndex = 2;
  18522. }
  18523. else
  18524. {
  18525. tempIndex = gun_index;
  18526. }
  18527. for (int index = 0; index < AC_QUANTITY; index++)
  18528. {
  18529. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18530. {
  18531. 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
  18532. }
  18533. } // END OF FOR AC_QUANTITY
  18534. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  18535. }
  18536. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18537. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  18538. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  18539. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  18540. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18541. }
  18542. //====================== Start SoC ================================
  18543. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18544. {
  18545. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18546. 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))
  18547. {
  18548. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18549. {
  18550. tempIndex = ((gun_index==2) ? 1: 0);
  18551. }
  18552. else
  18553. {
  18554. tempIndex = gun_index;
  18555. }
  18556. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18557. {
  18558. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18559. {
  18560. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18561. {
  18562. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  18563. }
  18564. }
  18565. }
  18566. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18567. {
  18568. for (int index = 0; index < CCS_QUANTITY; index++)
  18569. {
  18570. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18571. {
  18572. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  18573. }
  18574. }
  18575. }
  18576. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18577. {
  18578. for (int index = 0; index < GB_QUANTITY; index++)
  18579. {
  18580. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18581. {
  18582. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  18583. }
  18584. }
  18585. }
  18586. else if(gunType[gun_index] == GUN_TYPE_DO)
  18587. {
  18588. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18589. {
  18590. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18591. {
  18592. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  18593. }
  18594. }
  18595. }
  18596. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18597. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  18598. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18599. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  18600. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  18601. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18602. } // END FOR DC CASE
  18603. }
  18604. //======================================== Message create ==============================================
  18605. json_object *StopTransaction = json_object_new_object();
  18606. json_object *transactionDatas = json_object_new_array();
  18607. json_object *sampledValues = json_object_new_array();
  18608. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  18609. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  18610. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  18611. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  18612. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  18613. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  18614. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  18615. {
  18616. json_object *transactionData = json_object_new_object();
  18617. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  18618. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  18619. {
  18620. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  18621. {
  18622. json_object *sampledValue = json_object_new_object();
  18623. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  18624. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  18625. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  18626. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  18627. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  18628. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  18629. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  18630. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  18631. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  18632. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  18633. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  18634. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  18635. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  18636. json_object_array_add(sampledValues, sampledValue);
  18637. }
  18638. }
  18639. json_object_object_add(transactionData, "sampledValue", sampledValues);
  18640. json_object_array_add(transactionDatas, transactionData);
  18641. }
  18642. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  18643. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  18644. ,MESSAGE_TYPE_CALL
  18645. ,guid
  18646. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  18647. json_object_put(StopTransaction);
  18648. // Check File "TempStopTransaction" Exist
  18649. if((access(TempStopTransaction,F_OK))!=-1)
  18650. {
  18651. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  18652. fclose(fopen(TempStopTransaction, "w"));
  18653. }
  18654. else
  18655. {
  18656. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  18657. FILE *log = fopen(TempStopTransaction, "w+");
  18658. if(log == NULL)
  18659. {
  18660. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  18661. return ;
  18662. }
  18663. else
  18664. {
  18665. fclose(log);
  18666. }
  18667. }
  18668. //Add TempStopTransaction | Update TempStopTransaction
  18669. // open file for writing
  18670. FILE *outfile;
  18671. outfile = fopen (TempStopTransaction, "a");
  18672. //DEBUG_INFO("data = %s\n", queuedata);
  18673. fputs(queuedata, outfile);
  18674. fputs("\n", outfile);
  18675. fclose (outfile);
  18676. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18677. OCPP_updatePeriodEnergy(gun_index);
  18678. }
  18679. void checkTempStopTransaction(int gun_index)
  18680. {
  18681. FILE *fptr1;
  18682. char ch;
  18683. char str[QUEUE_MESSAGE_LENGTH]={0};
  18684. char guid[37]={0};
  18685. char tempdata[65]={0};
  18686. char connectorStr[2]={0};
  18687. char TempStopTransaction[256];
  18688. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  18689. fptr1 = fopen(TempStopTransaction, "r");
  18690. //TempStopTransaction格式: 槍號,StopTransaction封包
  18691. if (!fptr1)
  18692. {
  18693. //printf(" File not found or unable to open the input file!!\n");
  18694. return ;
  18695. }
  18696. ch=fgetc(fptr1);
  18697. //printf(" Now the content of the file %s is : \n",fname);
  18698. rewind(fptr1);
  18699. if(ch!=EOF)
  18700. {
  18701. // copy all contents to the temporary file except the specific line
  18702. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18703. {
  18704. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18705. if(str[0]=='\0')
  18706. {
  18707. break;
  18708. }
  18709. //TempStopTransaction格式: 槍號,StopTransaction封包
  18710. strncpy(connectorStr, str, 1);
  18711. if(atoi(connectorStr) != (gun_index+1))
  18712. {
  18713. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18714. fclose(fptr1);
  18715. return ;
  18716. }
  18717. //random_uuid(guid);
  18718. strncpy(guid, str+6, 36); //copy guid
  18719. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18720. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18721. {
  18722. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18723. }
  18724. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18725. OCPP_insert_transaction_msg(NO, str);
  18726. memset(str,0,ARRAY_SIZE(str));
  18727. }
  18728. }
  18729. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18730. fclose(fptr1);
  18731. remove(TempStopTransaction); // remove the original file
  18732. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18733. }
  18734. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18735. {
  18736. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18737. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18738. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18739. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18740. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18741. }
  18742. int GetWebSocketPingInterval(void)
  18743. {
  18744. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18745. }
  18746. int GetServerSign(void)
  18747. {
  18748. return server_sign;
  18749. }
  18750. uint8_t GetOcppSecurityProfile()
  18751. {
  18752. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18753. }
  18754. void GetOcppChargerBoxId(uint8_t *data)
  18755. {
  18756. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18757. }
  18758. void GetOcppSecurityPassword(uint8_t *data)
  18759. {
  18760. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18761. }
  18762. void SetOcppVersion(uint8_t *version)
  18763. {
  18764. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18765. DEBUG_INFO("ocpp version: %s\n", version);
  18766. if(strstr((char*)version, "ocpp1.6") != NULL)
  18767. {
  18768. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18769. }
  18770. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18771. {
  18772. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18773. system("pkill OcppBackend");
  18774. }
  18775. }
  18776. void SetServerSign(int value)
  18777. {
  18778. server_sign = value;
  18779. }
  18780. int GetBootNotificationInterval(void)
  18781. {
  18782. return BootNotificationInterval;
  18783. }
  18784. int GetInternetConn(void)
  18785. {
  18786. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18787. }
  18788. int GetBackendConnectionTimeout(void)
  18789. {
  18790. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18791. }
  18792. int isConnectorInitMode(int gun_index)
  18793. {
  18794. int tempIndex = 0;
  18795. int result = TRUE;
  18796. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18797. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18798. {
  18799. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18800. {
  18801. tempIndex = ((gun_index==2) ? 1: 0);
  18802. }
  18803. else
  18804. {
  18805. tempIndex = gun_index;
  18806. }
  18807. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18808. {
  18809. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18810. {
  18811. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18812. } //end of the same index
  18813. }//end of for CHAdeMO_QUANTITY
  18814. }
  18815. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18816. {
  18817. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18818. {
  18819. tempIndex = ((gun_index==2) ? 1: 0);
  18820. }
  18821. else
  18822. {
  18823. tempIndex = gun_index;
  18824. }
  18825. for (int index = 0; index < CCS_QUANTITY; index++)
  18826. {
  18827. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18828. {
  18829. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18830. } //end of the same index
  18831. } // end of for CCS_QUANTITY
  18832. }
  18833. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18834. {
  18835. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18836. {
  18837. tempIndex = ((gun_index==2) ? 1: 0);
  18838. }
  18839. else
  18840. {
  18841. tempIndex = gun_index;
  18842. }
  18843. for (int index = 0; index < GB_QUANTITY; index++)
  18844. {
  18845. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18846. {
  18847. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18848. } //end of the same index
  18849. } // end of for GB_QUANTITY
  18850. }
  18851. else if(gunType[gun_index] == GUN_TYPE_DO)
  18852. {
  18853. tempIndex = gun_index;
  18854. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18855. {
  18856. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18857. {
  18858. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18859. } //end of the same index
  18860. }
  18861. }
  18862. else
  18863. {
  18864. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18865. {
  18866. tempIndex = 2;
  18867. }
  18868. else
  18869. {
  18870. tempIndex = gun_index;
  18871. }
  18872. for (int index = 0; index < AC_QUANTITY; index++)
  18873. {
  18874. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18875. {
  18876. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18877. }//end of the same index
  18878. }//end of for AC_QUANTITY
  18879. }
  18880. return result;
  18881. }
  18882. void refreshProcDogTimer()
  18883. {
  18884. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  18885. }
  18886. void InitialSystemValue(void)
  18887. {
  18888. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  18889. locallistVersion=0;
  18890. BootNotificationInterval = 0;
  18891. authorizeRetryTimes = 0;
  18892. GunStatusInterval = 10;
  18893. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18894. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18895. //Hear Beat
  18896. HeartBeatWithNOResponse = 0;
  18897. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18898. FirstHeartBeat = 0;
  18899. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18900. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18901. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18902. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18903. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18904. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18905. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18906. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18907. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18908. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18909. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18910. //Status && ConnectorPlugIn Setting
  18911. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18912. {
  18913. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18914. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18915. }
  18916. for (int index = 0; index < CCS_QUANTITY; index++)
  18917. {
  18918. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18919. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18920. }
  18921. for (int index = 0; index < GB_QUANTITY; index++)
  18922. {
  18923. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18924. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18925. }
  18926. for (int index = 0; index < AC_QUANTITY; index++)
  18927. {
  18928. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18929. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18930. }
  18931. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18932. {
  18933. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18934. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18935. }
  18936. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18937. {
  18938. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18939. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18940. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18941. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18942. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18943. }
  18944. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18945. refreshStartTimer(&clientTime.Heartbeat);
  18946. sleep(1);
  18947. }
  18948. void LWS_Send(char *str)
  18949. {
  18950. //=====================================================
  18951. // Check InternetConn 0: disconnected, 1: connected
  18952. //====================================================
  18953. if(GetOcppConnStatus() == 0)
  18954. {
  18955. DEBUG_INFO("offline now !!!\n");
  18956. return;
  18957. }
  18958. // Only disable isWebsocketSendable operation initiated by charger
  18959. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18960. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18961. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18962. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18963. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18964. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18965. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18966. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18967. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18968. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18969. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18970. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18971. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18972. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18973. {
  18974. isWebsocketSendable = 0;
  18975. }
  18976. pthread_mutex_lock(&lock_send);
  18977. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18978. sprintf((char *)SendBuffer, "%s", str);
  18979. SendBufLen = strlen(str);
  18980. pthread_mutex_unlock(&lock_send);
  18981. lws_callback_on_writable(wsi_client);
  18982. //lws_service(context, 0);
  18983. //sleep(1);
  18984. }
  18985. void LWS_SendNow(char *str)
  18986. {
  18987. //=====================================================
  18988. // Check InternetConn 0: disconnected, 1: connected
  18989. //====================================================
  18990. if(GetOcppConnStatus() == 0)
  18991. {
  18992. DEBUG_INFO("offline now !!!\n");
  18993. return;
  18994. }
  18995. // Only disable isWebsocketSendable operation initiated by charger
  18996. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18997. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18998. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18999. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  19000. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19001. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19002. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19003. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  19004. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19005. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  19006. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19007. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19008. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19009. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  19010. {
  19011. isWebsocketSendable = 0;
  19012. }
  19013. pthread_mutex_lock(&lock_send);
  19014. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19015. sprintf((char *)SendBuffer, "%s", str);
  19016. SendBufLen = strlen(str);
  19017. pthread_mutex_unlock(&lock_send);
  19018. lws_callback_on_writable(wsi_client);
  19019. lws_service(context, 0);
  19020. //sleep(1);
  19021. }