MessageHandler.c 947 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759
  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. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  3927. //offline MeterValue Interval
  3928. TempMeterValueInterval = 0;
  3929. return result;
  3930. }
  3931. int ProcessShareMemory()
  3932. {
  3933. int result = PASS;
  3934. if(InitShareMemory() == FAIL)
  3935. {
  3936. DEBUG_ERROR("InitShareMemory NG\n");
  3937. if(ShmStatusCodeData!=NULL)
  3938. {
  3939. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3940. }
  3941. result = FAIL;
  3942. }
  3943. // Model name parsing
  3944. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3945. {
  3946. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3947. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3948. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3949. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3950. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3951. ) // 'D' means DC
  3952. {
  3953. // DO series
  3954. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3955. {
  3956. SystemInitial += 1;
  3957. gunTotalNumber += 1;
  3958. gunType[gun_index] = GUN_TYPE_DO;
  3959. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3960. {
  3961. case Gun_Type_Chademo:
  3962. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3963. break;
  3964. case Gun_Type_CCS_2:
  3965. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3966. break;
  3967. case Gun_Type_GB:
  3968. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3969. break;
  3970. case Gun_Type_AC:
  3971. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3972. break;
  3973. default:
  3974. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3975. break;
  3976. }
  3977. }
  3978. }
  3979. else
  3980. {
  3981. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3982. {
  3983. SystemInitial += 1;
  3984. gunTotalNumber += 1;
  3985. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3986. {
  3987. case Gun_Type_Chademo:
  3988. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3989. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3990. break;
  3991. case Gun_Type_CCS_2:
  3992. gunType[gun_index] = GUN_TYPE_CCS;
  3993. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3994. break;
  3995. case Gun_Type_GB:
  3996. gunType[gun_index] = GUN_TYPE_GBT;
  3997. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3998. break;
  3999. case Gun_Type_AC:
  4000. gunType[gun_index] = GUN_TYPE_AC;
  4001. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  4002. break;
  4003. default:
  4004. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  4005. break;
  4006. }
  4007. }
  4008. }
  4009. }
  4010. else
  4011. {
  4012. DEBUG_ERROR("Model name parsing fail.\n");
  4013. result = FAIL;
  4014. }
  4015. if(result != PASS)sleep(5);
  4016. return result;
  4017. }
  4018. void checkRemoteStart(uint8_t connectorIdInt)
  4019. {
  4020. uint8_t tempIndex;
  4021. int result = PASS;
  4022. char cmdBuf[512];
  4023. //check Transaction active
  4024. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  4025. {
  4026. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4027. {
  4028. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4029. }
  4030. else
  4031. {
  4032. tempIndex = connectorIdInt -1;
  4033. }
  4034. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4035. {
  4036. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4037. {
  4038. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4039. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4040. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4041. {
  4042. //Reserved
  4043. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  4044. }
  4045. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4046. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4047. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4048. {
  4049. //Reserved
  4050. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  4051. result = FAIL;
  4052. goto end;
  4053. }
  4054. else
  4055. {
  4056. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4057. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  4058. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  4059. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  4060. {
  4061. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  4062. result = FAIL;
  4063. goto end;
  4064. }
  4065. }//END FOR ELSE
  4066. }
  4067. }// END FOR CHAdeMO_QUANTITY
  4068. }
  4069. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  4070. {
  4071. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4072. {
  4073. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4074. }
  4075. else
  4076. {
  4077. tempIndex = connectorIdInt -1;
  4078. }
  4079. for (int index = 0; index < CCS_QUANTITY; index++)
  4080. {
  4081. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4082. {
  4083. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4084. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4085. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4086. {
  4087. //Reserved
  4088. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  4089. }
  4090. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4091. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4092. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4093. {
  4094. //Reserved
  4095. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  4096. result = FAIL;
  4097. goto end;
  4098. }
  4099. else
  4100. {
  4101. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4102. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4103. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4104. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4105. {
  4106. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  4107. result = FAIL;
  4108. goto end;
  4109. }
  4110. }// END FOR ELSE
  4111. }
  4112. }// END FOR CCS_QUANTITY
  4113. }
  4114. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  4115. {
  4116. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4117. {
  4118. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4119. }
  4120. else
  4121. {
  4122. tempIndex = connectorIdInt -1;
  4123. }
  4124. for (int index = 0; index < GB_QUANTITY; index++)
  4125. {
  4126. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  4127. {
  4128. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4129. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4130. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4131. {
  4132. //Reserved
  4133. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  4134. }
  4135. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4136. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4137. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4138. {
  4139. //Reserved
  4140. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  4141. result = FAIL;
  4142. goto end;
  4143. }
  4144. else
  4145. {
  4146. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4147. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4148. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4149. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4150. {
  4151. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  4152. result = FAIL;
  4153. goto end;
  4154. }
  4155. }// END FOR ELSE
  4156. }
  4157. } // END FOR GB_QUANTITY
  4158. }
  4159. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  4160. {
  4161. tempIndex = connectorIdInt -1;
  4162. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4163. {
  4164. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  4165. {
  4166. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4167. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4168. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4169. {
  4170. //Reserved
  4171. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  4172. }
  4173. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4174. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4175. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4176. {
  4177. //Reserved
  4178. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  4179. result = FAIL;
  4180. goto end;
  4181. }
  4182. else
  4183. {
  4184. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4185. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4186. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4187. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4188. {
  4189. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  4190. result = FAIL;
  4191. goto end;
  4192. }
  4193. }// END FOR ELSE
  4194. }
  4195. } // END FOR GB_QUANTITY
  4196. }
  4197. else
  4198. {
  4199. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  4200. {
  4201. tempIndex = 2;
  4202. }
  4203. else
  4204. {
  4205. tempIndex = connectorIdInt -1;
  4206. }
  4207. for (int index = 0; index < AC_QUANTITY; index++)
  4208. {
  4209. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  4210. {
  4211. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4212. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4213. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4214. {
  4215. //Reserved
  4216. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  4217. }
  4218. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4219. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4220. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4221. {
  4222. //Reserved
  4223. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  4224. result = FAIL;
  4225. goto end;
  4226. }
  4227. else
  4228. {
  4229. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4230. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4231. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4232. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4233. {
  4234. DEBUG_WARN("AC connector not allow start cause busy.\n");
  4235. result = FAIL;
  4236. goto end;
  4237. }
  4238. }//END FOR ELSE
  4239. }
  4240. }// END FOR AC_QUANTITY
  4241. }
  4242. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  4243. {
  4244. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  4245. {
  4246. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  4247. {
  4248. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4249. system(cmdBuf);
  4250. }
  4251. }
  4252. else
  4253. {
  4254. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  4255. result = FAIL;
  4256. }
  4257. }
  4258. end:
  4259. if(result == PASS)
  4260. {
  4261. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  4262. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  4263. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4264. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  4265. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4266. }
  4267. }
  4268. void CheckSystemValue(void)
  4269. {
  4270. char filenmae[100]={0};
  4271. char str[100]={0};
  4272. int tempIndex = 0;
  4273. //===============================
  4274. // send Heartbeat
  4275. //===============================
  4276. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  4277. {
  4278. //parameter for test
  4279. sendHeartbeatRequest(0);
  4280. //===========================
  4281. // Reset Waiting Time
  4282. //===========================
  4283. HeartBeatWithNOResponse += 1;
  4284. }
  4285. //===============================
  4286. // Credit deduct report
  4287. //===============================
  4288. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  4289. {
  4290. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo,
  4291. ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice,
  4292. ShmOCPP16Data->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.vemData,
  4293. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.RRN,
  4294. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.storeId);
  4295. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  4296. }
  4297. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  4298. {
  4299. OCPP_query_deduct_info();
  4300. refreshStartTimer(&clientTime.TcciQueryDeduct);
  4301. }
  4302. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4303. {
  4304. // ClockAlign MeterValue
  4305. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  4306. {
  4307. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4308. {
  4309. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4310. {
  4311. tempIndex = ((gun_index==2) ? 1: 0);
  4312. }
  4313. else
  4314. {
  4315. tempIndex = gun_index;
  4316. }
  4317. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4318. {
  4319. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4320. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4321. {
  4322. reqClockAlignMeter[gun_index] = 1;
  4323. }
  4324. }// End for CHAdeMO
  4325. }
  4326. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4327. {
  4328. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4329. {
  4330. tempIndex = ((gun_index==2) ? 1: 0);
  4331. }
  4332. else
  4333. {
  4334. tempIndex = gun_index;
  4335. }
  4336. for (int index = 0; index < CCS_QUANTITY; index++)
  4337. {
  4338. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4339. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4340. {
  4341. reqClockAlignMeter[gun_index] = 1;
  4342. }
  4343. } // End for CCS
  4344. }
  4345. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4346. {
  4347. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4348. {
  4349. tempIndex = ((gun_index==2) ? 1: 0);
  4350. }
  4351. else
  4352. {
  4353. tempIndex = gun_index;
  4354. }
  4355. for (int index = 0; index < GB_QUANTITY; index++)
  4356. {
  4357. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4358. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4359. {
  4360. reqClockAlignMeter[gun_index] = 1;
  4361. }
  4362. }// End for GB
  4363. }
  4364. else if(gunType[gun_index] == GUN_TYPE_DO)
  4365. {
  4366. tempIndex = gun_index;
  4367. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4368. {
  4369. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4370. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4371. {
  4372. reqClockAlignMeter[gun_index] = 1;
  4373. }
  4374. }
  4375. }
  4376. else
  4377. {
  4378. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4379. {
  4380. tempIndex = 2;
  4381. }
  4382. else
  4383. {
  4384. tempIndex = gun_index;
  4385. }
  4386. for (int index = 0; index < AC_QUANTITY; index++)
  4387. {
  4388. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4389. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4390. {
  4391. reqClockAlignMeter[gun_index] = 1;
  4392. }
  4393. }//End for AC
  4394. }
  4395. }
  4396. }
  4397. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4398. {
  4399. //==========================================
  4400. // Check remote start without connector id
  4401. //==========================================
  4402. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4403. {
  4404. int connectorIdInt = -1;
  4405. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4406. {
  4407. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4408. {
  4409. connectorIdInt = (gun_index+1);
  4410. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4411. checkRemoteStart(connectorIdInt);
  4412. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4413. break;
  4414. }
  4415. }
  4416. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4417. {
  4418. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4419. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4420. }
  4421. }
  4422. //==========================================
  4423. // csu trigger DataTransferReq
  4424. //==========================================
  4425. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4426. {
  4427. sendDataTransferRequest(gun_index);
  4428. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  4429. }
  4430. //==========================================
  4431. // CSU Trigger Authorize Request
  4432. //==========================================
  4433. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4434. {
  4435. sendAuthorizeRequest(0);
  4436. authorizeRetryTimes = authorizeRetryTimes + 1;
  4437. if(authorizeRetryTimes < 3)
  4438. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4439. }
  4440. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4441. {
  4442. authorizeRetryTimes = 0;
  4443. SetOcppConnStatus(FALSE);
  4444. server_sign = FALSE;
  4445. }
  4446. 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))
  4447. {
  4448. sendAuthorizeRequest(0);
  4449. }
  4450. //==========================================
  4451. // Charger start transaction
  4452. //==========================================
  4453. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4454. {
  4455. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4456. sendStartTransactionRequest(gun_index);
  4457. refreshStartTimer(&clientTime.StartTransaction);
  4458. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4459. storeTempStopTransaction(gun_index);
  4460. }
  4461. //==========================================
  4462. // Charger stop transaction
  4463. //==========================================
  4464. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4465. {
  4466. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4467. sendStopTransactionRequest(gun_index);
  4468. OCPP_updatePeriodEnergy(gun_index);
  4469. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  4470. refreshStartTimer(&clientTime.StopTransaction);
  4471. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4472. }
  4473. //==========================================
  4474. // Charger status report
  4475. //==========================================
  4476. //--- Check Mode Change ---//
  4477. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4478. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4479. {
  4480. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4481. {
  4482. tempIndex = ((gun_index==2) ? 1: 0);
  4483. }
  4484. else
  4485. {
  4486. tempIndex = gun_index;
  4487. }
  4488. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4489. {
  4490. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4491. {
  4492. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4493. {
  4494. // Sent unplug message for California pricing logic
  4495. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  4496. {
  4497. uint8_t ts[20];
  4498. getNowDatetime(ts);
  4499. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4500. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4501. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4502. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4503. }
  4504. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4505. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4506. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4507. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4508. {
  4509. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4510. if((access(filenmae,F_OK))!=-1)
  4511. {
  4512. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4513. sprintf(str,"rm -f %s",filenmae);
  4514. system(str);
  4515. }
  4516. }
  4517. }
  4518. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4519. #if 1 // for TempStopTransaction
  4520. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4521. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4522. {
  4523. checkTempStopTransaction(gun_index);
  4524. }
  4525. #endif
  4526. }
  4527. }
  4528. }
  4529. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4530. {
  4531. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4532. {
  4533. tempIndex = ((gun_index==2) ? 1: 0);
  4534. }
  4535. else
  4536. {
  4537. tempIndex = gun_index;
  4538. }
  4539. for (int index = 0; index < CCS_QUANTITY; index++)
  4540. {
  4541. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4542. {
  4543. 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]*/ )
  4544. {
  4545. // Sent unplug message for California pricing logic
  4546. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  4547. {
  4548. uint8_t ts[20];
  4549. getNowDatetime(ts);
  4550. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4551. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4552. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4553. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4554. }
  4555. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4556. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4557. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4558. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4559. {
  4560. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4561. if((access(filenmae,F_OK))!=-1)
  4562. {
  4563. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4564. sprintf(str,"rm -f %s",filenmae);
  4565. system(str);
  4566. }
  4567. }
  4568. }
  4569. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4570. #if 1 // for TempStopTransaction
  4571. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4572. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4573. {
  4574. checkTempStopTransaction(gun_index);
  4575. }
  4576. #endif
  4577. }
  4578. }
  4579. }
  4580. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4581. {
  4582. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4583. {
  4584. tempIndex = ((gun_index==2) ? 1: 0);
  4585. }
  4586. else
  4587. {
  4588. tempIndex = gun_index;
  4589. }
  4590. for (int index = 0; index < GB_QUANTITY; index++)
  4591. {
  4592. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4593. {
  4594. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4595. {
  4596. // Sent unplug message for California pricing logic
  4597. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  4598. {
  4599. uint8_t ts[20];
  4600. getNowDatetime(ts);
  4601. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4602. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4603. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4604. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4605. }
  4606. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4607. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4608. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4609. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4610. {
  4611. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4612. if((access(filenmae,F_OK))!=-1)
  4613. {
  4614. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4615. sprintf(str,"rm -f %s",filenmae);
  4616. system(str);
  4617. }
  4618. }
  4619. }
  4620. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4621. #if 1 // for TempStopTransaction
  4622. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4623. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4624. {
  4625. checkTempStopTransaction(gun_index);
  4626. }
  4627. #endif
  4628. }
  4629. }
  4630. }
  4631. else if(gunType[gun_index] == GUN_TYPE_DO)
  4632. {
  4633. tempIndex = gun_index;
  4634. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4635. {
  4636. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4637. {
  4638. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4639. {
  4640. // Sent unplug message for California pricing logic
  4641. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  4642. {
  4643. uint8_t ts[20];
  4644. getNowDatetime(ts);
  4645. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4646. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4647. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4648. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4649. }
  4650. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4651. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4652. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4653. 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
  4654. {
  4655. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4656. if((access(filenmae,F_OK))!=-1)
  4657. {
  4658. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4659. sprintf(str,"rm -f %s",filenmae);
  4660. system(str);
  4661. }
  4662. }
  4663. }
  4664. 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);
  4665. #if 1 // for TempStopTransaction
  4666. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4667. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4668. {
  4669. checkTempStopTransaction(gun_index);
  4670. }
  4671. #endif
  4672. }
  4673. }
  4674. }
  4675. else
  4676. {
  4677. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4678. {
  4679. tempIndex = 2;
  4680. }
  4681. else
  4682. {
  4683. tempIndex = gun_index;
  4684. }
  4685. for (int index = 0; index < AC_QUANTITY; index++)
  4686. {
  4687. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4688. {
  4689. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4690. {
  4691. // Sent unplug message for California pricing logic
  4692. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  4693. {
  4694. uint8_t ts[20];
  4695. getNowDatetime(ts);
  4696. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4697. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4698. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4699. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4700. }
  4701. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4702. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4703. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4704. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4705. {
  4706. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4707. if((access(filenmae,F_OK))!=-1)
  4708. {
  4709. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4710. sprintf(str,"rm -f %s",filenmae);
  4711. system(str);
  4712. }
  4713. }
  4714. }
  4715. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4716. #if 1 // for TempStopTransaction
  4717. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4718. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4719. {
  4720. checkTempStopTransaction(gun_index);
  4721. }
  4722. #endif
  4723. }
  4724. }// END
  4725. }
  4726. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) &&
  4727. (
  4728. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4729. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4730. )
  4731. )
  4732. {
  4733. if(SystemInitial > 0)
  4734. SystemInitial -= 1;
  4735. sendStatusNotificationRequest(gun_index);
  4736. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4737. }
  4738. //==============================================
  4739. // TCCI reader status report
  4740. //==============================================
  4741. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1))
  4742. {
  4743. reportReaderStatus(gun_index);
  4744. //ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4745. }
  4746. //==============================================
  4747. // CSU Trigger Smart Charging Profile
  4748. //==============================================
  4749. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4750. {
  4751. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  4752. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4753. }
  4754. //==============================================
  4755. // Meter report
  4756. //==============================================
  4757. // Trigger MeterValue
  4758. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4759. {
  4760. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4761. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4762. }
  4763. // Clock-aligned Meter value
  4764. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4765. {
  4766. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4767. reqClockAlignMeter[gun_index] = 0;
  4768. }
  4769. // Sample period MeterValue
  4770. 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))))
  4771. {
  4772. //check Transaction active
  4773. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4774. {
  4775. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4776. {
  4777. tempIndex = ((gun_index==2) ? 1: 0);
  4778. }
  4779. else
  4780. {
  4781. tempIndex = gun_index;
  4782. }
  4783. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4784. {
  4785. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4786. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4787. {
  4788. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4789. {
  4790. reqSampleMeter[gun_index] = 1;
  4791. }
  4792. }
  4793. }// End for CHAdeMO
  4794. }
  4795. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4796. {
  4797. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4798. {
  4799. tempIndex = ((gun_index==2) ? 1: 0);
  4800. }
  4801. else
  4802. {
  4803. tempIndex = gun_index;
  4804. }
  4805. for (int index = 0; index < CCS_QUANTITY; index++)
  4806. {
  4807. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4808. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4809. {
  4810. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4811. {
  4812. reqSampleMeter[gun_index] = 1;
  4813. }
  4814. }
  4815. } // End for CCS
  4816. }
  4817. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4818. {
  4819. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4820. {
  4821. tempIndex = ((gun_index==2) ? 1: 0);
  4822. }
  4823. else
  4824. {
  4825. tempIndex = gun_index;
  4826. }
  4827. for (int index = 0; index < GB_QUANTITY; index++)
  4828. {
  4829. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4830. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4831. {
  4832. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4833. {
  4834. reqSampleMeter[gun_index] = 1;
  4835. }
  4836. }
  4837. }// End for GB
  4838. }
  4839. else if(gunType[gun_index] == GUN_TYPE_DO)
  4840. {
  4841. tempIndex = gun_index;
  4842. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4843. {
  4844. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4845. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4846. {
  4847. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4848. {
  4849. reqSampleMeter[gun_index] = 1;
  4850. }
  4851. }
  4852. }
  4853. }
  4854. else
  4855. {
  4856. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4857. {
  4858. tempIndex = 2;
  4859. }
  4860. else
  4861. {
  4862. tempIndex = gun_index;
  4863. }
  4864. for (int index = 0; index < AC_QUANTITY; index++)
  4865. {
  4866. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4867. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4868. {
  4869. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4870. {
  4871. reqSampleMeter[gun_index] = 1;
  4872. }
  4873. }
  4874. }//End for AC
  4875. }
  4876. if(reqSampleMeter[gun_index] == 1)
  4877. {
  4878. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4879. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4880. storeTempStopTransaction(gun_index);
  4881. reqSampleMeter[gun_index] = 0;
  4882. }
  4883. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4884. }
  4885. //==============================================
  4886. // Check Connector reserved
  4887. //==============================================
  4888. //===============================
  4889. // Check if Reserve is expired
  4890. //===============================
  4891. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  4892. {
  4893. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  4894. {
  4895. DEBUG_INFO("reserve expired.\n");
  4896. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  4897. }
  4898. }//END OF Check if Reserve is expired
  4899. //==========================================
  4900. // csu trigger FirmwareStatusNotificationReq
  4901. //==========================================
  4902. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4903. {
  4904. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  4905. }
  4906. //==========================================
  4907. // csu trigger DiagnosticsStatusNotificationReq
  4908. //==========================================
  4909. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4910. {
  4911. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  4912. }
  4913. //==========================================
  4914. // csu trigger CancelReservationConf
  4915. //==========================================
  4916. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4917. {
  4918. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  4919. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4920. }
  4921. //==========================================
  4922. // csu trigger ChangeAvailabilityConf
  4923. //==========================================
  4924. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4925. {
  4926. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  4927. }
  4928. //==========================================
  4929. // csu trigger UnlockConnectorConf
  4930. //==========================================
  4931. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4932. {
  4933. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  4934. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4935. }
  4936. //==========================================
  4937. // csu trigger ReserveNowConf
  4938. //==========================================
  4939. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4940. {
  4941. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  4942. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4943. }
  4944. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  4945. {
  4946. sendSignCertificateRequest();
  4947. }
  4948. }
  4949. }
  4950. //==========================================
  4951. // send request routine
  4952. //==========================================
  4953. int sendAuthorizeRequest(int gun_index)
  4954. {
  4955. mtrace();
  4956. int result = FAIL;
  4957. char message[100]={0};
  4958. char guid[37];
  4959. char tempdata[65]={0};
  4960. DEBUG_INFO("sendAuthorizeRequest...\n");
  4961. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4962. //Local Authorize
  4963. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  4964. {
  4965. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4966. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4967. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4968. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4969. result = PASS;
  4970. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4971. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4972. authorizeRetryTimes = 0;
  4973. return result;
  4974. }
  4975. 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))||
  4976. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4977. {
  4978. // Query from cache
  4979. DEBUG_INFO("Authorize from cache.\n");
  4980. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4981. // Query from list
  4982. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4983. {
  4984. DEBUG_INFO("Authorize from list.\n");
  4985. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4986. }
  4987. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4988. {
  4989. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4990. {
  4991. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4992. }
  4993. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4994. {
  4995. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4996. }
  4997. if(!GetOcppConnStatus())
  4998. {
  4999. DEBUG_INFO("off-line Local Authorization Fail.\n");
  5000. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5001. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5002. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  5003. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5004. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5005. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5006. authorizeRetryTimes = 0;
  5007. return result;
  5008. }
  5009. }
  5010. else
  5011. {
  5012. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  5013. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5014. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5015. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  5016. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  5017. else
  5018. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  5019. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5020. result = PASS;
  5021. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5022. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5023. authorizeRetryTimes = 0;
  5024. return result;
  5025. }
  5026. }
  5027. //initialize struct Authorize
  5028. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  5029. //get data from shared memory
  5030. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5031. random_uuid(guid);
  5032. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  5033. LWS_Send(message);
  5034. sprintf(tempdata, "Authorize,%d", gun_index);
  5035. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5036. {
  5037. result = PASS;
  5038. DEBUG_INFO("Authorize mapItem pass\n");
  5039. }
  5040. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5041. return result;
  5042. }
  5043. int sendBootNotificationRequest(void)
  5044. {
  5045. mtrace();
  5046. int result = FAIL;
  5047. char message[500]={0}, payload[700]={0};
  5048. char guid[37]={0};
  5049. char tempdata[65]={0};
  5050. // Fill BootNotification fields
  5051. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  5052. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  5053. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  5054. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5055. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  5056. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  5057. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  5058. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  5059. ShmOCPP16Data->ChargeBoxId
  5060. ,ShmSysConfigAndInfo->SysConfig.ModelName
  5061. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  5062. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  5063. ,ShmOCPP16Data->BootNotification.CpFwVersion
  5064. ,ShmOCPP16Data->BootNotification.CpIccid
  5065. ,ShmOCPP16Data->BootNotification.CpImsi);
  5066. random_uuid(guid);
  5067. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  5068. LWS_Send(message);
  5069. sprintf(tempdata, "BootNotification,0");
  5070. 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*/)
  5071. {
  5072. result = PASS;
  5073. }
  5074. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5075. strcpy(queuedata,message);
  5076. return result;
  5077. }
  5078. int sendDataTransferRequest(int gun_index)
  5079. {
  5080. mtrace();
  5081. char message[1000]={0};
  5082. char guid[37]={0};
  5083. char tempdata[65]={0};
  5084. int result = FAIL;
  5085. random_uuid(guid);
  5086. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5087. MESSAGE_TYPE_CALL,
  5088. guid,
  5089. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5090. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5091. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5092. LWS_Send(message);
  5093. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5094. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5095. {
  5096. result = PASS;
  5097. DEBUG_INFO("DataTransfer mapItem pass\n");
  5098. }
  5099. return result;
  5100. }
  5101. int sendDiagnosticsStatusNotificationRequest(char *status)
  5102. {
  5103. mtrace();
  5104. int result = FAIL;
  5105. char message[110]={0};
  5106. char guid[37]={0};
  5107. char tempdata[65]={0};
  5108. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  5109. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  5110. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  5111. random_uuid(guid);
  5112. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  5113. LWS_SendNow(message);
  5114. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  5115. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5116. {
  5117. result = PASS;
  5118. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  5119. }
  5120. //#ifdef SystemLogMessage
  5121. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  5122. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5123. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  5124. //#endif
  5125. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  5126. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  5127. //record status
  5128. if(strcmp(status,"Idle")==0)
  5129. {
  5130. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  5131. }
  5132. else if(strcmp(status,"Uploaded")==0)
  5133. {
  5134. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  5135. }
  5136. else if(strcmp(status,"UploadFailed")==0)
  5137. {
  5138. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  5139. }
  5140. else if(strcmp(status,"Uploading")==0)
  5141. {
  5142. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  5143. }
  5144. return result;
  5145. }
  5146. int sendFirmwareStatusNotificationRequest(char *status)
  5147. {
  5148. mtrace();
  5149. int result = FAIL;
  5150. char message[110]={0};
  5151. char guid[37]={0};
  5152. char tempdata[65]={0};
  5153. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  5154. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  5155. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  5156. random_uuid(guid);
  5157. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  5158. LWS_SendNow(message);
  5159. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5160. 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*/)
  5161. {
  5162. result = PASS;
  5163. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  5164. }
  5165. //#ifdef SystemLogMessage
  5166. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  5167. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5168. //#endif
  5169. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  5170. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  5171. //record status
  5172. if(strcmp(status,"Downloaded")==0)
  5173. {
  5174. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  5175. }
  5176. else if(strcmp(status,"DownloadFailed")==0)
  5177. {
  5178. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  5179. }
  5180. else if(strcmp(status,"Downloading")==0)
  5181. {
  5182. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  5183. }
  5184. else if(strcmp(status,"Idle")==0)
  5185. {
  5186. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  5187. }
  5188. else if(strcmp(status,"InstallationFailed")==0)
  5189. {
  5190. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  5191. }
  5192. else if(strcmp(status,"Installing")==0)
  5193. {
  5194. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  5195. }
  5196. else if(strcmp(status,"Installed")==0)
  5197. {
  5198. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  5199. }
  5200. return result;
  5201. }
  5202. int sendHeartbeatRequest(int gun_index)
  5203. {
  5204. mtrace();
  5205. int result = FAIL;
  5206. char message[80]={0};
  5207. char guid[37]={0};
  5208. char tempdata[65]={0};
  5209. random_uuid(guid);
  5210. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  5211. , MESSAGE_TYPE_CALL
  5212. , guid );
  5213. LWS_Send(message);
  5214. sprintf(tempdata, "Heartbeat,%d", 0);
  5215. 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*/)
  5216. {
  5217. result = PASS;
  5218. }
  5219. return result;
  5220. }
  5221. int sendStartTransactionRequest(int gun_index)
  5222. {
  5223. mtrace();
  5224. int result = FAIL;
  5225. char message[250]={0};
  5226. char guid[37]={0};
  5227. struct timeval tmnow;
  5228. struct tm *tm;
  5229. char buf[28];//, usec_buf[6];
  5230. char tempdata[65]={0};
  5231. int tempIndex = 0;
  5232. DEBUG_INFO("sendStartTransactionRequest...\n");
  5233. gettimeofday(&tmnow, NULL);
  5234. time_t t;
  5235. t = time(NULL);
  5236. /*UTC time and date*/
  5237. tm = gmtime(&t);
  5238. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5239. #if 0 // remove temporally
  5240. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5241. strcat(buf,".");
  5242. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5243. strcat(buf,usec_buf);
  5244. #endif
  5245. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  5246. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  5247. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5248. // clear StartTransaction Response
  5249. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  5250. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  5251. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  5252. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  5253. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5254. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5255. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5256. {
  5257. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5258. {
  5259. tempIndex = ((gun_index==2) ? 1: 0);
  5260. }
  5261. else
  5262. {
  5263. tempIndex = gun_index;
  5264. }
  5265. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5266. {
  5267. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5268. {
  5269. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5270. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  5271. }
  5272. }
  5273. }
  5274. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5275. {
  5276. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5277. {
  5278. tempIndex = ((gun_index==2) ? 1: 0);
  5279. }
  5280. else
  5281. {
  5282. tempIndex = gun_index;
  5283. }
  5284. for (int index = 0; index < CCS_QUANTITY; index++)
  5285. {
  5286. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5287. {
  5288. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5289. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  5290. }
  5291. }
  5292. }
  5293. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5294. {
  5295. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5296. {
  5297. tempIndex = ((gun_index==2) ? 1: 0);
  5298. }
  5299. else
  5300. {
  5301. tempIndex = gun_index;
  5302. }
  5303. for (int index = 0; index < GB_QUANTITY; index++)
  5304. {
  5305. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5306. {
  5307. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5308. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  5309. }
  5310. }
  5311. }
  5312. else if(gunType[gun_index] == GUN_TYPE_DO)
  5313. {
  5314. tempIndex = gun_index;
  5315. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5316. {
  5317. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5318. {
  5319. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5320. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5321. }
  5322. }
  5323. }
  5324. else
  5325. {
  5326. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5327. {
  5328. tempIndex = 2;
  5329. }
  5330. else
  5331. {
  5332. tempIndex = gun_index;
  5333. }
  5334. for (int index = 0; index < AC_QUANTITY; index++)
  5335. {
  5336. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5337. {
  5338. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5339. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5340. }
  5341. }
  5342. }
  5343. random_uuid(guid);
  5344. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5345. {
  5346. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5347. , gun_index +1
  5348. , MESSAGE_TYPE_CALL
  5349. , guid
  5350. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5351. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5352. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5353. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5354. }
  5355. else
  5356. {
  5357. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5358. , gun_index +1
  5359. , MESSAGE_TYPE_CALL
  5360. , guid
  5361. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5362. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5363. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5364. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  5365. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5366. }
  5367. #if 1
  5368. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5369. 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*/)
  5370. {
  5371. result = PASS;
  5372. }
  5373. #endif
  5374. strcpy(queuedata, message);
  5375. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5376. OCPP_insert_transaction_msg(YES, queuedata);
  5377. return result;
  5378. }
  5379. int sendStatusNotificationRequest(int gun_index)
  5380. {
  5381. mtrace();
  5382. int result = FAIL;
  5383. char message[600]={0};
  5384. char guid[37];
  5385. int currentStatus = 0;
  5386. struct timeval tmnow;
  5387. struct tm *tm;
  5388. char buf[28];//, usec_buf[6];
  5389. char tempdata[65]={0};
  5390. int tempIndex = 0;
  5391. uint8_t isStateChanged = TRUE;
  5392. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5393. gettimeofday(&tmnow, NULL);
  5394. time_t t;
  5395. t = time(NULL);
  5396. /*UTC time and date*/
  5397. tm = gmtime(&t);
  5398. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5399. #if 0 // remove temporally
  5400. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5401. strcat(buf,".");
  5402. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5403. strcat(buf,usec_buf);
  5404. #endif
  5405. //printf("%s",buf);
  5406. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5407. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5408. // it's option
  5409. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  5410. /*
  5411. enum _SYSTEM_STATUS
  5412. {
  5413. S_BOOTING = 0,
  5414. S_IDLE, = 1
  5415. S_AUTHORIZING, =2
  5416. S_REASSIGN_CHECK, =3
  5417. S_REASSIGN, =4
  5418. S_PRECHARGE, =5
  5419. S_PREPARING_FOR_EV, =6
  5420. S_PREPARING_FOR_EVSE, =7
  5421. S_CHARGING, =8
  5422. S_TERMINATING, =9
  5423. S_COMPLETE, =10
  5424. S_ALARM, =11
  5425. S_FAULT =12
  5426. }
  5427. */
  5428. //check Transaction active
  5429. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5430. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5431. {
  5432. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5433. {
  5434. tempIndex = ((gun_index==2) ? 1: 0);
  5435. }
  5436. else
  5437. {
  5438. tempIndex = gun_index;
  5439. }
  5440. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5441. {
  5442. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5443. {
  5444. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5445. {
  5446. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5447. {
  5448. currentStatus = Preparing; //OCPP Status: Preparing
  5449. }
  5450. else
  5451. {
  5452. currentStatus = Available; //OCPP Status: Available
  5453. }
  5454. }
  5455. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5456. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5457. ) //S_PRECHARGE
  5458. {
  5459. currentStatus = Preparing; //OCPP Status: Preparing
  5460. }
  5461. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5462. {
  5463. currentStatus = Charging; //OCPP Status: Charging
  5464. }
  5465. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5466. {
  5467. currentStatus = Finishing; //OCPP Status: Finishing
  5468. }
  5469. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5470. {
  5471. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5472. }
  5473. 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
  5474. {
  5475. currentStatus = Unavailable; //OCPP Status: Unavailable
  5476. }
  5477. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5478. {
  5479. currentStatus = Faulted; //OCPP Status: Faulted
  5480. }
  5481. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5482. {
  5483. currentStatus = Reserved; //OCPP Status: Reserved
  5484. }
  5485. } //end of the same index
  5486. }//end of for CHAdeMO_QUANTITY
  5487. }
  5488. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5489. {
  5490. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5491. {
  5492. tempIndex = ((gun_index==2) ? 1: 0);
  5493. }
  5494. else
  5495. {
  5496. tempIndex = gun_index;
  5497. }
  5498. for (int index = 0; index < CCS_QUANTITY; index++)
  5499. {
  5500. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5501. {
  5502. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5503. {
  5504. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5505. {
  5506. currentStatus = Preparing; //OCPP Status: Preparing
  5507. }
  5508. else
  5509. {
  5510. currentStatus = Available; //OCPP Status: Available
  5511. }
  5512. }
  5513. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5514. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5515. ) //S_PRECHARGE
  5516. {
  5517. currentStatus = Preparing; //OCPP Status: Preparing
  5518. }
  5519. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5520. {
  5521. currentStatus = Charging; //OCPP Status: Charging
  5522. }
  5523. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5524. {
  5525. currentStatus = Finishing; //OCPP Status: Finishing
  5526. }
  5527. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5528. {
  5529. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5530. }
  5531. 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
  5532. {
  5533. currentStatus = Unavailable; //OCPP Status : Unavailable
  5534. }
  5535. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5536. {
  5537. currentStatus = Faulted; //OCPP Status: Faulted
  5538. }
  5539. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5540. {
  5541. currentStatus = Reserved; //OCPP Status: Reserved
  5542. }
  5543. } //end of the same index
  5544. } // end of for CCS_QUANTITY
  5545. }
  5546. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5547. {
  5548. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5549. {
  5550. tempIndex = ((gun_index==2) ? 1: 0);
  5551. }
  5552. else
  5553. {
  5554. tempIndex = gun_index;
  5555. }
  5556. for (int index = 0; index < GB_QUANTITY; index++)
  5557. {
  5558. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5559. {
  5560. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5561. {
  5562. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5563. {
  5564. currentStatus = Preparing; //OCPP Status: Preparing
  5565. }
  5566. else
  5567. {
  5568. currentStatus = Available; //OCPP Status: Available
  5569. }
  5570. }
  5571. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5572. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5573. ) //S_PRECHARGE
  5574. {
  5575. currentStatus = Preparing; //OCPP Status: Preparing
  5576. }
  5577. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5578. {
  5579. currentStatus = Charging; //OCPP Status: Charging
  5580. }
  5581. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5582. {
  5583. currentStatus = Finishing; //OCPP Status: Finishing
  5584. }
  5585. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5586. {
  5587. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5588. }
  5589. 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
  5590. {
  5591. currentStatus = Unavailable; //OCPP Status: Unavailable
  5592. }
  5593. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5594. {
  5595. currentStatus = Faulted; //OCPP Status: Faulted
  5596. }
  5597. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5598. {
  5599. currentStatus = Reserved; //OCPP Status: Reserved
  5600. }
  5601. } //end of the same index
  5602. } // end of for GB_QUANTITY
  5603. }
  5604. else if(gunType[gun_index] == GUN_TYPE_DO)
  5605. {
  5606. tempIndex = gun_index;
  5607. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5608. {
  5609. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5610. {
  5611. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5612. {
  5613. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5614. {
  5615. currentStatus = Preparing; //OCPP Status: Preparing
  5616. }
  5617. else
  5618. {
  5619. currentStatus = Available; //OCPP Status: Available
  5620. }
  5621. }
  5622. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5623. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5624. ) //S_PRECHARGE
  5625. {
  5626. currentStatus = Preparing; //OCPP Status: Preparing
  5627. }
  5628. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5629. {
  5630. currentStatus = Charging; //OCPP Status: Charging
  5631. }
  5632. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5633. {
  5634. currentStatus = Finishing; //OCPP Status: Finishing
  5635. }
  5636. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5637. {
  5638. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5639. }
  5640. 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
  5641. {
  5642. currentStatus = Unavailable; //OCPP Status: Unavailable
  5643. }
  5644. 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
  5645. {
  5646. currentStatus = Faulted; //OCPP Status: Faulted
  5647. }
  5648. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5649. {
  5650. currentStatus = Reserved; //OCPP Status: Reserved
  5651. }
  5652. } //end of the same index
  5653. }
  5654. }
  5655. else
  5656. {
  5657. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5658. {
  5659. tempIndex = 2;
  5660. }
  5661. else
  5662. {
  5663. tempIndex = gun_index;
  5664. }
  5665. for (int index = 0; index < AC_QUANTITY; index++)
  5666. {
  5667. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5668. {
  5669. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5670. {
  5671. 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))
  5672. {
  5673. currentStatus = Preparing; //OCPP Status: Preparing
  5674. }
  5675. else
  5676. {
  5677. currentStatus = Available; //OCPP Status: Available
  5678. }
  5679. }
  5680. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5681. {
  5682. currentStatus = Preparing; //OCPP Status: Preparing
  5683. }
  5684. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5685. {
  5686. currentStatus = Charging; //OCPP Status: Charging
  5687. }
  5688. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5689. {
  5690. currentStatus = Finishing; //OCPP Status: Finishing
  5691. }
  5692. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5693. {
  5694. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5695. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5696. else
  5697. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5698. }
  5699. 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
  5700. {
  5701. currentStatus = Unavailable; //OCPP Status: Unavailable
  5702. }
  5703. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5704. {
  5705. currentStatus = Faulted; //OCPP Status: Faulted
  5706. }
  5707. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5708. {
  5709. currentStatus = Reserved; //OCPP Status: Reserved
  5710. }
  5711. }//end of the same index
  5712. }//end of for AC_QUANTITY
  5713. }
  5714. //it's option
  5715. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5716. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5717. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5718. {
  5719. isStateChanged = FALSE;
  5720. }
  5721. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5722. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  5723. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5724. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5725. random_uuid(guid);
  5726. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5727. , MESSAGE_TYPE_CALL
  5728. , guid
  5729. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  5730. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  5731. , ShmOCPP16Data->StatusNotification[gun_index].Info
  5732. , ShmOCPP16Data->StatusNotification[gun_index].Status
  5733. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  5734. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  5735. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  5736. if((server_sign == TRUE) && isStateChanged)
  5737. {
  5738. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5739. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5740. LWS_Send(message);
  5741. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5742. 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*/)
  5743. {
  5744. //DEBUG_ERROR("statusNotification mapitem pass");
  5745. result = PASS;
  5746. }
  5747. }
  5748. else
  5749. {
  5750. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5751. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5752. result = PASS;
  5753. }
  5754. return result;
  5755. }
  5756. int sendStopTransactionRequest(int gun_index)
  5757. {
  5758. mtrace();
  5759. int result = FAIL;
  5760. //char message[1500]={0};
  5761. char guid[37]={0};
  5762. char tempdata[65]={0};
  5763. int tempIndex = 0;
  5764. char TempStopTransaction[256];
  5765. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  5766. //int idx_sample=0;
  5767. DEBUG_INFO("sendStopTransactionRequest \n");
  5768. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5769. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  5770. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5771. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5772. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5773. {
  5774. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5775. {
  5776. tempIndex = ((gun_index==2) ? 1: 0);
  5777. }
  5778. else
  5779. {
  5780. tempIndex = gun_index;
  5781. }
  5782. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5783. {
  5784. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5785. {
  5786. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5787. }
  5788. }// END OF CHAdeMO_QUANTITY
  5789. }
  5790. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5791. {
  5792. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5793. {
  5794. tempIndex = ((gun_index==2) ? 1: 0);
  5795. }
  5796. else
  5797. {
  5798. tempIndex = gun_index;
  5799. }
  5800. for (int index = 0; index < CCS_QUANTITY; index++)
  5801. {
  5802. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5803. {
  5804. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5805. }
  5806. }// END OF CCS_QUANTITY
  5807. }
  5808. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5809. {
  5810. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5811. {
  5812. tempIndex = ((gun_index==2) ? 1: 0);
  5813. }
  5814. else
  5815. {
  5816. tempIndex = gun_index;
  5817. }
  5818. for (int index = 0; index < GB_QUANTITY; index++)
  5819. {
  5820. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5821. {
  5822. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5823. }
  5824. }// END OF GB_QUANTITY
  5825. }
  5826. else if(gunType[gun_index] == GUN_TYPE_DO)
  5827. {
  5828. tempIndex = gun_index;
  5829. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5830. {
  5831. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5832. {
  5833. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5834. }
  5835. }// END OF GB_QUANTITY
  5836. }
  5837. else
  5838. {
  5839. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5840. {
  5841. tempIndex = 2;
  5842. }
  5843. else
  5844. {
  5845. tempIndex = gun_index;
  5846. }
  5847. for (int index = 0; index < AC_QUANTITY; index++)
  5848. {
  5849. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5850. {
  5851. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5852. }
  5853. }// END OF AC_QUANTITY
  5854. }
  5855. //====================================== Stop Transaction Time =====================================================
  5856. struct timeval tmnow;
  5857. struct tm *tm;
  5858. char buf[28];//, usec_buf[6];
  5859. gettimeofday(&tmnow, NULL);
  5860. time_t t;
  5861. t = time(NULL);
  5862. /*UTC time and date*/
  5863. tm = gmtime(&t);
  5864. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5865. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  5866. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  5867. random_uuid(guid);
  5868. /***********************************transactionData******************************************************/
  5869. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5870. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5871. //=================================
  5872. // Transaction_Begin
  5873. //=================================
  5874. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5875. {
  5876. //============================================ Energy.Active.Import.Interval ================================
  5877. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5878. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5879. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5880. 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*/]);
  5881. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5882. 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))
  5883. {
  5884. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5885. }
  5886. else
  5887. {
  5888. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5889. }
  5890. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5891. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5892. }
  5893. //=================================
  5894. // Transaction_End
  5895. //=================================
  5896. // ================================= Current.Import L1 ===============================================
  5897. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5898. {
  5899. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5900. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5901. {
  5902. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5903. {
  5904. tempIndex = ((gun_index==2) ? 1: 0);
  5905. }
  5906. else
  5907. {
  5908. tempIndex = gun_index;
  5909. }
  5910. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5911. {
  5912. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5913. {
  5914. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5915. }
  5916. }// End of for CHAdeMO_QUANTITY
  5917. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5918. }
  5919. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5920. {
  5921. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5922. {
  5923. tempIndex = ((gun_index==2) ? 1: 0);
  5924. }
  5925. else
  5926. {
  5927. tempIndex = gun_index;
  5928. }
  5929. for (int index = 0; index < CCS_QUANTITY; index++)
  5930. {
  5931. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5932. {
  5933. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5934. }
  5935. }// End of for CCS_QUANTITY
  5936. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5937. }
  5938. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5939. {
  5940. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5941. {
  5942. tempIndex = ((gun_index==2) ? 1: 0);
  5943. }
  5944. else
  5945. {
  5946. tempIndex = gun_index;
  5947. }
  5948. for (int index = 0; index < GB_QUANTITY; index++)
  5949. {
  5950. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5951. {
  5952. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5953. }
  5954. }// End of for GB_QUANTITY
  5955. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5956. }
  5957. else if(gunType[gun_index] == GUN_TYPE_DO)
  5958. {
  5959. tempIndex = gun_index;
  5960. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5961. {
  5962. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5963. {
  5964. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5965. }
  5966. }
  5967. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5968. }
  5969. else
  5970. {
  5971. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5972. {
  5973. tempIndex = 2;
  5974. }
  5975. else
  5976. {
  5977. tempIndex = gun_index;
  5978. }
  5979. for (int index = 0; index < AC_QUANTITY; index++)
  5980. {
  5981. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5982. {
  5983. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5984. }
  5985. }// End of for AC_QUANTITY
  5986. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5987. }
  5988. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5989. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5990. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5991. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5992. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5993. }
  5994. // ================================= Energy.Active.Import.Interval ==============================================
  5995. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5996. {
  5997. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5998. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5999. {
  6000. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6001. {
  6002. tempIndex = ((gun_index==2) ? 1: 0);
  6003. }
  6004. else
  6005. {
  6006. tempIndex = gun_index;
  6007. }
  6008. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6009. {
  6010. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6011. {
  6012. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  6013. }
  6014. }// END OF CHAdeMO_QUANTITY
  6015. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6016. }
  6017. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6018. {
  6019. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6020. {
  6021. tempIndex = ((gun_index==2) ? 1: 0);
  6022. }
  6023. else
  6024. {
  6025. tempIndex = gun_index;
  6026. }
  6027. for (int index = 0; index < CCS_QUANTITY; index++)
  6028. {
  6029. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6030. {
  6031. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  6032. }
  6033. }// END OF CCS_QUANTITY
  6034. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6035. }
  6036. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6037. {
  6038. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6039. {
  6040. tempIndex = ((gun_index==2) ? 1: 0);
  6041. }
  6042. else
  6043. {
  6044. tempIndex = gun_index;
  6045. }
  6046. for (int index = 0; index < GB_QUANTITY; index++)
  6047. {
  6048. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6049. {
  6050. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  6051. }
  6052. }// END OF GB_QUANTITY
  6053. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6054. }
  6055. else if(gunType[gun_index] == GUN_TYPE_DO)
  6056. {
  6057. tempIndex = gun_index;
  6058. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6059. {
  6060. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6061. {
  6062. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  6063. }
  6064. }
  6065. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6066. }
  6067. else
  6068. {
  6069. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6070. {
  6071. tempIndex = 2;
  6072. }
  6073. else
  6074. {
  6075. tempIndex = gun_index;
  6076. }
  6077. for (int index = 0; index < AC_QUANTITY; index++)
  6078. {
  6079. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6080. {
  6081. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  6082. }
  6083. }// END OF AC_QUANTITY
  6084. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  6085. }
  6086. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6087. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  6088. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  6089. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  6090. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6091. }
  6092. //=================================== Power.Active.Import ==================================================
  6093. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  6094. {
  6095. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6096. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6097. {
  6098. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6099. {
  6100. tempIndex = ((gun_index==2) ? 1: 0);
  6101. }
  6102. else
  6103. {
  6104. tempIndex = gun_index;
  6105. }
  6106. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6107. {
  6108. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6109. {
  6110. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6111. }
  6112. } // End for CHAdeMO_QUANTITY
  6113. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6114. }
  6115. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6116. {
  6117. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6118. {
  6119. tempIndex = ((gun_index==2) ? 1: 0);
  6120. }
  6121. else
  6122. {
  6123. tempIndex = gun_index;
  6124. }
  6125. for (int index = 0; index < CCS_QUANTITY; index++)
  6126. {
  6127. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6128. {
  6129. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6130. }
  6131. } // END for CCS_QUANTITY
  6132. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6133. }
  6134. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6135. {
  6136. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6137. {
  6138. tempIndex = ((gun_index==2) ? 1: 0);
  6139. }
  6140. else
  6141. {
  6142. tempIndex = gun_index;
  6143. }
  6144. for (int index = 0; index < GB_QUANTITY; index++)
  6145. {
  6146. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6147. {
  6148. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6149. }
  6150. }// END for GB_QUANTITY
  6151. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6152. }
  6153. else if(gunType[gun_index] == GUN_TYPE_DO)
  6154. {
  6155. tempIndex = gun_index;
  6156. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6157. {
  6158. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6159. {
  6160. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6161. }
  6162. }
  6163. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6164. }
  6165. else
  6166. {
  6167. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6168. {
  6169. tempIndex = 2;
  6170. }
  6171. else
  6172. {
  6173. tempIndex = gun_index;
  6174. }
  6175. for (int index = 0; index < AC_QUANTITY; index++)
  6176. {
  6177. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6178. {
  6179. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6180. }
  6181. } // END for AC_QUANTITY
  6182. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  6183. }
  6184. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6185. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  6186. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  6187. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  6188. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  6189. }
  6190. //============================ Voltage L1 ====================================
  6191. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6192. {
  6193. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6194. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6195. {
  6196. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6197. {
  6198. tempIndex = ((gun_index==2) ? 1: 0);
  6199. }
  6200. else
  6201. {
  6202. tempIndex = gun_index;
  6203. }
  6204. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6205. {
  6206. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6207. {
  6208. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6209. }
  6210. } // END OF FOR CHAdeMO_QUANTITY
  6211. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6212. }
  6213. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6214. {
  6215. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6216. {
  6217. tempIndex = ((gun_index==2) ? 1: 0);
  6218. }
  6219. else
  6220. {
  6221. tempIndex = gun_index;
  6222. }
  6223. for (int index = 0; index < CCS_QUANTITY; index++)
  6224. {
  6225. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6226. {
  6227. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6228. }
  6229. } // END OF FOR CCS_QUANTITY
  6230. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6231. }
  6232. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6233. {
  6234. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6235. {
  6236. tempIndex = ((gun_index==2) ? 1: 0);
  6237. }
  6238. else
  6239. {
  6240. tempIndex = gun_index;
  6241. }
  6242. for (int index = 0; index < GB_QUANTITY; index++)
  6243. {
  6244. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6245. {
  6246. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6247. }
  6248. } // END OF FOR GB_QUANTITY
  6249. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6250. }
  6251. else if(gunType[gun_index] == GUN_TYPE_DO)
  6252. {
  6253. tempIndex = gun_index;
  6254. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6255. {
  6256. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6257. {
  6258. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6259. }
  6260. }
  6261. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6262. }
  6263. else
  6264. {
  6265. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6266. {
  6267. tempIndex = 2;
  6268. }
  6269. else
  6270. {
  6271. tempIndex = gun_index;
  6272. }
  6273. for (int index = 0; index < AC_QUANTITY; index++)
  6274. {
  6275. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6276. {
  6277. 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
  6278. }
  6279. } // END OF FOR AC_QUANTITY
  6280. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  6281. }
  6282. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6283. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  6284. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  6285. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  6286. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6287. }
  6288. //====================== End SoC ================================
  6289. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6290. {
  6291. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6292. 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))
  6293. {
  6294. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6295. {
  6296. tempIndex = ((gun_index==2) ? 1: 0);
  6297. }
  6298. else
  6299. {
  6300. tempIndex = gun_index;
  6301. }
  6302. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6303. {
  6304. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6305. {
  6306. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6307. {
  6308. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  6309. }
  6310. }
  6311. }
  6312. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6313. {
  6314. for (int index = 0; index < CCS_QUANTITY; index++)
  6315. {
  6316. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6317. {
  6318. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  6319. }
  6320. }
  6321. }
  6322. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6323. {
  6324. for (int index = 0; index < GB_QUANTITY; index++)
  6325. {
  6326. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6327. {
  6328. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6329. }
  6330. }
  6331. }
  6332. else if(gunType[gun_index] == GUN_TYPE_DO)
  6333. {
  6334. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6335. {
  6336. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6337. {
  6338. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6339. }
  6340. }
  6341. }
  6342. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6343. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6344. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6345. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6346. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6347. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6348. } // END FOR DC CASE
  6349. }
  6350. // ================================= Current.Import L2 ===============================================
  6351. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6352. {
  6353. // AC 3 phse L2 current
  6354. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6355. {
  6356. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6357. {
  6358. tempIndex = 2;
  6359. }
  6360. else
  6361. {
  6362. tempIndex = gun_index;
  6363. }
  6364. for (int index = 0; index < AC_QUANTITY; index++)
  6365. {
  6366. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6367. {
  6368. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6369. }
  6370. }// End of for AC_QUANTITY
  6371. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6372. }
  6373. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6374. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6375. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6376. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6377. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6378. }
  6379. // ================================= Current.Import L3 ===============================================
  6380. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6381. {
  6382. // AC 3 phse L3 current
  6383. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6384. {
  6385. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6386. {
  6387. tempIndex = 2;
  6388. }
  6389. else
  6390. {
  6391. tempIndex = gun_index;
  6392. }
  6393. for (int index = 0; index < AC_QUANTITY; index++)
  6394. {
  6395. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6396. {
  6397. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6398. }
  6399. }// End of for AC_QUANTITY
  6400. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6401. }
  6402. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6403. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6404. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6405. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6406. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6407. }
  6408. //============================ Voltage L2 ====================================
  6409. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6410. {
  6411. // AC 3 phse L2 voltage
  6412. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6413. {
  6414. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6415. {
  6416. tempIndex = 2;
  6417. }
  6418. else
  6419. {
  6420. tempIndex = gun_index;
  6421. }
  6422. for (int index = 0; index < AC_QUANTITY; index++)
  6423. {
  6424. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6425. {
  6426. 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
  6427. }
  6428. } // END OF FOR AC_QUANTITY
  6429. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6430. }
  6431. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6432. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6433. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6434. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6435. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6436. }
  6437. //============================ Voltage L3 ====================================
  6438. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6439. {
  6440. // AC 3 phse L3 voltage
  6441. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6442. {
  6443. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6444. {
  6445. tempIndex = 2;
  6446. }
  6447. else
  6448. {
  6449. tempIndex = gun_index;
  6450. }
  6451. for (int index = 0; index < AC_QUANTITY; index++)
  6452. {
  6453. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6454. {
  6455. 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
  6456. }
  6457. } // END OF FOR AC_QUANTITY
  6458. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6459. }
  6460. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6461. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6462. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6463. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6464. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6465. }
  6466. //====================== Start SoC ================================
  6467. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6468. {
  6469. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6470. 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))
  6471. {
  6472. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6473. {
  6474. tempIndex = ((gun_index==2) ? 1: 0);
  6475. }
  6476. else
  6477. {
  6478. tempIndex = gun_index;
  6479. }
  6480. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6481. {
  6482. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6483. {
  6484. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6485. {
  6486. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6487. }
  6488. }
  6489. }
  6490. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6491. {
  6492. for (int index = 0; index < CCS_QUANTITY; index++)
  6493. {
  6494. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6495. {
  6496. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6497. }
  6498. }
  6499. }
  6500. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6501. {
  6502. for (int index = 0; index < GB_QUANTITY; index++)
  6503. {
  6504. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6505. {
  6506. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6507. }
  6508. }
  6509. }
  6510. else if(gunType[gun_index] == GUN_TYPE_DO)
  6511. {
  6512. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6513. {
  6514. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6515. {
  6516. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6517. }
  6518. }
  6519. }
  6520. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6521. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6522. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6523. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6524. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6525. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6526. } // END FOR DC CASE
  6527. }
  6528. //================================================ Message create ====================================================
  6529. json_object *StopTransaction = json_object_new_object();
  6530. json_object *transactionDatas = json_object_new_array();
  6531. json_object *sampledValues = json_object_new_array();
  6532. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6533. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6534. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6535. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6536. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6537. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6538. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6539. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  6540. {
  6541. json_object *transactionData = json_object_new_object();
  6542. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6543. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6544. {
  6545. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6546. {
  6547. json_object *sampledValue = json_object_new_object();
  6548. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6549. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6550. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6551. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6552. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6553. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6554. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6555. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6556. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6557. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6558. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6559. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6560. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6561. json_object_array_add(sampledValues, sampledValue);
  6562. }
  6563. }
  6564. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6565. json_object_array_add(transactionDatas, transactionData);
  6566. }
  6567. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6568. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6569. ,MESSAGE_TYPE_CALL
  6570. ,guid
  6571. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6572. json_object_put(StopTransaction);
  6573. #if 1 // for TempStopTransaction
  6574. //Delete TempStopTransaction
  6575. if((access(TempStopTransaction,F_OK))!=-1)
  6576. {
  6577. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6578. }
  6579. #endif
  6580. #if 1
  6581. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6582. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6583. {
  6584. result = PASS;
  6585. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6586. }
  6587. #endif
  6588. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6589. OCPP_insert_transaction_msg(NO, queuedata);
  6590. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6591. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6592. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6593. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6594. {
  6595. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6596. }
  6597. //for test
  6598. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6599. return result;
  6600. }
  6601. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6602. {
  6603. mtrace();
  6604. int result = FAIL;
  6605. char guid[37]={0};
  6606. char tempdata[65]={0};
  6607. int tempIndex = 0;
  6608. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6609. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6610. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6611. //set value
  6612. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6613. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6614. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6615. -1);
  6616. random_uuid(guid);
  6617. //UTC Date time
  6618. struct timeval tmnow;
  6619. struct tm *tm;
  6620. char buf[28];//, usec_buf[6];
  6621. gettimeofday(&tmnow, NULL);
  6622. time_t t;
  6623. t = time(NULL);
  6624. /*UTC time and date*/
  6625. tm = gmtime(&t);
  6626. if(dataType == ReadingContext_Sample_Clock)
  6627. {
  6628. struct tm *tmTarget;
  6629. struct timeb tbTarget;
  6630. tbTarget.time = mktime(tm);
  6631. tbTarget.time -= (atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6632. tmTarget = gmtime(&tbTarget.time);
  6633. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6634. }
  6635. else
  6636. {
  6637. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6638. }
  6639. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6640. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6641. //********************************(1)Current.Import L1************************************************/
  6642. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6643. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6644. (dataType == ReadingContext_Trigger))
  6645. {
  6646. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6647. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6648. {
  6649. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6650. {
  6651. tempIndex = ((gun_index==2) ? 1: 0);
  6652. }
  6653. else
  6654. {
  6655. tempIndex = gun_index;
  6656. }
  6657. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6658. {
  6659. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6660. {
  6661. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6662. }
  6663. }
  6664. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6665. }
  6666. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6667. {
  6668. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6669. {
  6670. tempIndex = ((gun_index==2) ? 1: 0);
  6671. }
  6672. else
  6673. {
  6674. tempIndex = gun_index;
  6675. }
  6676. for (int index = 0; index < CCS_QUANTITY; index++)
  6677. {
  6678. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6679. {
  6680. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6681. }
  6682. }
  6683. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6684. }
  6685. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6686. {
  6687. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6688. {
  6689. tempIndex = ((gun_index==2) ? 1: 0);
  6690. }
  6691. else
  6692. {
  6693. tempIndex = gun_index;
  6694. }
  6695. for (int index = 0; index < GB_QUANTITY; index++)
  6696. {
  6697. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6698. {
  6699. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6700. }
  6701. }
  6702. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6703. }
  6704. else if(gunType[gun_index] == GUN_TYPE_DO)
  6705. {
  6706. tempIndex = gun_index;
  6707. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6708. {
  6709. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6710. {
  6711. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6712. }
  6713. }
  6714. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6715. }
  6716. else
  6717. {
  6718. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6719. {
  6720. tempIndex = 2;
  6721. }
  6722. else
  6723. {
  6724. tempIndex = gun_index;
  6725. }
  6726. for (int index = 0; index < AC_QUANTITY; index++)
  6727. {
  6728. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6729. {
  6730. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6731. }
  6732. }
  6733. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6734. }
  6735. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6736. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6737. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6738. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6739. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6740. }
  6741. //********************************(2)Energy.Active.Import.Register ************************************************/
  6742. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6743. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6744. (dataType == ReadingContext_Trigger))
  6745. {
  6746. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6747. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6748. {
  6749. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6750. {
  6751. tempIndex = ((gun_index==2) ? 1: 0);
  6752. }
  6753. else
  6754. {
  6755. tempIndex = gun_index;
  6756. }
  6757. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6758. {
  6759. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6760. {
  6761. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6762. }
  6763. }
  6764. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6765. }
  6766. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6767. {
  6768. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6769. {
  6770. tempIndex = ((gun_index==2) ? 1: 0);
  6771. }
  6772. else
  6773. {
  6774. tempIndex = gun_index;
  6775. }
  6776. for (int index = 0; index < CCS_QUANTITY; index++)
  6777. {
  6778. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6779. {
  6780. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6781. }
  6782. }
  6783. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6784. }
  6785. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6786. {
  6787. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6788. {
  6789. tempIndex = ((gun_index==2) ? 1: 0);
  6790. }
  6791. else
  6792. {
  6793. tempIndex = gun_index;
  6794. }
  6795. for (int index = 0; index < GB_QUANTITY; index++)
  6796. {
  6797. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6798. {
  6799. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6800. }
  6801. }
  6802. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6803. }
  6804. else if(gunType[gun_index] == GUN_TYPE_DO)
  6805. {
  6806. tempIndex = gun_index;
  6807. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6808. {
  6809. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6810. {
  6811. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6812. }
  6813. }
  6814. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6815. }
  6816. else
  6817. {
  6818. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6819. {
  6820. tempIndex = 2;
  6821. }
  6822. else
  6823. {
  6824. tempIndex = gun_index;
  6825. }
  6826. for (int index = 0; index < AC_QUANTITY; index++)
  6827. {
  6828. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6829. {
  6830. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6831. }
  6832. }
  6833. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6834. }
  6835. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6836. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6837. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6838. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6839. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6840. }
  6841. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6842. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6843. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6844. (dataType == ReadingContext_Trigger))
  6845. {
  6846. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6847. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6848. {
  6849. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6850. {
  6851. tempIndex = ((gun_index==2) ? 1: 0);
  6852. }
  6853. else
  6854. {
  6855. tempIndex = gun_index;
  6856. }
  6857. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6858. {
  6859. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6860. {
  6861. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6862. }
  6863. } // END OF FOR CHAdeMO_QUANTITY
  6864. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6865. }
  6866. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6867. {
  6868. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6869. {
  6870. tempIndex = ((gun_index==2) ? 1: 0);
  6871. }
  6872. else
  6873. {
  6874. tempIndex = gun_index;
  6875. }
  6876. for (int index = 0; index < CCS_QUANTITY; index++)
  6877. {
  6878. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6879. {
  6880. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6881. }
  6882. } // END OF CCS_QUANTITY
  6883. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6884. }
  6885. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6886. {
  6887. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6888. {
  6889. tempIndex = ((gun_index==2) ? 1: 0);
  6890. }
  6891. else
  6892. {
  6893. tempIndex = gun_index;
  6894. }
  6895. for (int index = 0; index < GB_QUANTITY; index++)
  6896. {
  6897. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6898. {
  6899. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6900. }
  6901. } // END OF GB_QUANTITY
  6902. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6903. }
  6904. else if(gunType[gun_index] == GUN_TYPE_DO)
  6905. {
  6906. tempIndex = gun_index;
  6907. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6908. {
  6909. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6910. {
  6911. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6912. }
  6913. }
  6914. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6915. }
  6916. else
  6917. {
  6918. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6919. {
  6920. tempIndex = 2;
  6921. }
  6922. else
  6923. {
  6924. tempIndex = gun_index;
  6925. }
  6926. for (int index = 0; index < AC_QUANTITY; index++)
  6927. {
  6928. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6929. {
  6930. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6931. }
  6932. }
  6933. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6934. }
  6935. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6936. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6937. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6938. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6939. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6940. }
  6941. //********************************(4)Power.Active.Import************************************************/
  6942. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6943. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6944. (dataType == ReadingContext_Trigger))
  6945. {
  6946. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6947. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6948. {
  6949. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6950. {
  6951. tempIndex = ((gun_index==2) ? 1: 0);
  6952. }
  6953. else
  6954. {
  6955. tempIndex = gun_index;
  6956. }
  6957. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6958. {
  6959. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6960. {
  6961. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6962. }
  6963. } // END OF FOR
  6964. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6965. }
  6966. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6967. {
  6968. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6969. {
  6970. tempIndex = ((gun_index==2) ? 1: 0);
  6971. }
  6972. else
  6973. {
  6974. tempIndex = gun_index;
  6975. }
  6976. for (int index = 0; index < CCS_QUANTITY; index++)
  6977. {
  6978. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6979. {
  6980. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6981. }
  6982. }
  6983. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6984. }
  6985. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6986. {
  6987. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6988. {
  6989. tempIndex = ((gun_index==2) ? 1: 0);
  6990. }
  6991. else
  6992. {
  6993. tempIndex = gun_index;
  6994. }
  6995. for (int index = 0; index < GB_QUANTITY; index++)
  6996. {
  6997. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6998. {
  6999. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7000. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  7001. }
  7002. }
  7003. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7004. }
  7005. else if(gunType[gun_index] == GUN_TYPE_DO)
  7006. {
  7007. tempIndex = gun_index;
  7008. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7009. {
  7010. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7011. {
  7012. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7013. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  7014. }
  7015. }
  7016. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7017. }
  7018. else
  7019. {
  7020. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7021. {
  7022. tempIndex = 2;
  7023. }
  7024. else
  7025. {
  7026. tempIndex = gun_index;
  7027. }
  7028. for (int index = 0; index < AC_QUANTITY; index++)
  7029. {
  7030. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7031. {
  7032. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  7033. }
  7034. }
  7035. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  7036. }
  7037. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  7038. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  7039. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  7040. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  7041. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  7042. }
  7043. //***********************************************(5)VOLTAGE L1******************************************************/
  7044. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7045. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7046. (dataType == ReadingContext_Trigger))
  7047. {
  7048. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7049. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7050. {
  7051. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7052. {
  7053. tempIndex = ((gun_index==2) ? 1: 0);
  7054. }
  7055. else
  7056. {
  7057. tempIndex = gun_index;
  7058. }
  7059. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7060. {
  7061. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7062. {
  7063. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  7064. }
  7065. }
  7066. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7067. }
  7068. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7069. {
  7070. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7071. {
  7072. tempIndex = ((gun_index==2) ? 1: 0);
  7073. }
  7074. else
  7075. {
  7076. tempIndex = gun_index;
  7077. }
  7078. for (int index = 0; index < CCS_QUANTITY; index++)
  7079. {
  7080. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7081. {
  7082. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  7083. }
  7084. }
  7085. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7086. }
  7087. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7088. {
  7089. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7090. {
  7091. tempIndex = ((gun_index==2) ? 1: 0);
  7092. }
  7093. else
  7094. {
  7095. tempIndex = gun_index;
  7096. }
  7097. for (int index = 0; index < GB_QUANTITY; index++)
  7098. {
  7099. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7100. {
  7101. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  7102. }
  7103. }
  7104. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7105. }
  7106. else if(gunType[gun_index] == GUN_TYPE_DO)
  7107. {
  7108. tempIndex = gun_index;
  7109. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7110. {
  7111. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7112. {
  7113. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  7114. }
  7115. }
  7116. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7117. }
  7118. else
  7119. {
  7120. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7121. {
  7122. tempIndex = 2;
  7123. }
  7124. else
  7125. {
  7126. tempIndex = gun_index;
  7127. }
  7128. for (int index = 0; index < AC_QUANTITY; index++)
  7129. {
  7130. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7131. {
  7132. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  7133. }
  7134. }
  7135. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  7136. }
  7137. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  7138. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  7139. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  7140. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  7141. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7142. }
  7143. //***********************************************(6)SOC******************************************************/
  7144. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7145. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7146. (dataType == ReadingContext_Trigger))
  7147. {
  7148. 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))
  7149. {
  7150. //idx_sample=5;
  7151. //sampledValue = NULL;
  7152. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7153. {
  7154. tempIndex = ((gun_index==2) ? 1: 0);
  7155. }
  7156. else
  7157. {
  7158. tempIndex = gun_index;
  7159. }
  7160. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7161. {
  7162. //tempIndex = ((gun_index==2) ? 1: 0);
  7163. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7164. {
  7165. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7166. {
  7167. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  7168. }
  7169. }
  7170. }
  7171. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7172. {
  7173. //tempIndex = ((gun_index==2) ? 1: 0);
  7174. for (int index = 0; index < CCS_QUANTITY; index++)
  7175. {
  7176. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7177. {
  7178. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  7179. }
  7180. }
  7181. }
  7182. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7183. {
  7184. //tempIndex = ((gun_index==2) ? 1: 0);
  7185. for (int index = 0; index < GB_QUANTITY; index++)
  7186. {
  7187. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7188. {
  7189. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  7190. }
  7191. }
  7192. }
  7193. else if(gunType[gun_index] == GUN_TYPE_DO)
  7194. {
  7195. //tempIndex = ((gun_index==2) ? 1: 0);
  7196. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7197. {
  7198. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7199. {
  7200. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  7201. }
  7202. }
  7203. }
  7204. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  7205. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  7206. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  7207. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  7208. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  7209. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  7210. }
  7211. }
  7212. //********************************(7)Current.Import L2************************************************/
  7213. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7214. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7215. (dataType == ReadingContext_Trigger))
  7216. {
  7217. // Only for AC 3 phase
  7218. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7219. {
  7220. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7221. {
  7222. tempIndex = 2;
  7223. }
  7224. else
  7225. {
  7226. tempIndex = gun_index;
  7227. }
  7228. for (int index = 0; index < AC_QUANTITY; index++)
  7229. {
  7230. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7231. {
  7232. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7233. }
  7234. }
  7235. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7236. }
  7237. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7238. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7239. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7240. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7241. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7242. }
  7243. //********************************(8)Current.Import L3************************************************/
  7244. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7245. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7246. (dataType == ReadingContext_Trigger))
  7247. {
  7248. // Only for AC 3 phase
  7249. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7250. {
  7251. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7252. {
  7253. tempIndex = 2;
  7254. }
  7255. else
  7256. {
  7257. tempIndex = gun_index;
  7258. }
  7259. for (int index = 0; index < AC_QUANTITY; index++)
  7260. {
  7261. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7262. {
  7263. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7264. }
  7265. }
  7266. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7267. }
  7268. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7269. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7270. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7271. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7272. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7273. }
  7274. //***********************************************(9)VOLTAGE L2******************************************************/
  7275. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7276. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7277. (dataType == ReadingContext_Trigger))
  7278. {
  7279. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7280. {
  7281. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7282. {
  7283. tempIndex = 2;
  7284. }
  7285. else
  7286. {
  7287. tempIndex = gun_index;
  7288. }
  7289. for (int index = 0; index < AC_QUANTITY; index++)
  7290. {
  7291. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7292. {
  7293. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7294. }
  7295. }
  7296. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7297. }
  7298. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7299. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7300. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7301. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7302. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7303. }
  7304. //***********************************************(10)VOLTAGE L3******************************************************/
  7305. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7306. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7307. (dataType == ReadingContext_Trigger))
  7308. {
  7309. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7310. {
  7311. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7312. {
  7313. tempIndex = 2;
  7314. }
  7315. else
  7316. {
  7317. tempIndex = gun_index;
  7318. }
  7319. for (int index = 0; index < AC_QUANTITY; index++)
  7320. {
  7321. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7322. {
  7323. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7324. }
  7325. }
  7326. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7327. }
  7328. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7329. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7330. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7331. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7332. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7333. }
  7334. //***********************************************(11)Current.Offered******************************************************/
  7335. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7336. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7337. (dataType == ReadingContext_Trigger))
  7338. {
  7339. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7340. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7341. {
  7342. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7343. {
  7344. tempIndex = ((gun_index==2) ? 1: 0);
  7345. }
  7346. else
  7347. {
  7348. tempIndex = gun_index;
  7349. }
  7350. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7351. {
  7352. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7353. {
  7354. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7355. }
  7356. } // END OF FOR CHAdeMO_QUANTITY
  7357. }
  7358. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7359. {
  7360. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7361. {
  7362. tempIndex = ((gun_index==2) ? 1: 0);
  7363. }
  7364. else
  7365. {
  7366. tempIndex = gun_index;
  7367. }
  7368. for (int index = 0; index < CCS_QUANTITY; index++)
  7369. {
  7370. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7371. {
  7372. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7373. }
  7374. } // END OF CCS_QUANTITY
  7375. }
  7376. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7377. {
  7378. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7379. {
  7380. tempIndex = ((gun_index==2) ? 1: 0);
  7381. }
  7382. else
  7383. {
  7384. tempIndex = gun_index;
  7385. }
  7386. for (int index = 0; index < GB_QUANTITY; index++)
  7387. {
  7388. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7389. {
  7390. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7391. }
  7392. } // END OF GB_QUANTITY
  7393. }
  7394. else if(gunType[gun_index] == GUN_TYPE_DO)
  7395. {
  7396. tempIndex = gun_index;
  7397. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7398. {
  7399. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7400. {
  7401. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7402. }
  7403. }
  7404. }
  7405. else
  7406. {
  7407. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7408. {
  7409. tempIndex = 2;
  7410. }
  7411. else
  7412. {
  7413. tempIndex = gun_index;
  7414. }
  7415. for (int index = 0; index < AC_QUANTITY; index++)
  7416. {
  7417. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7418. {
  7419. uint16_t currentOffer;
  7420. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7421. {
  7422. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7423. }
  7424. else
  7425. {
  7426. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7427. }
  7428. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7429. }
  7430. }
  7431. }
  7432. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7433. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7434. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7435. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7436. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7437. }
  7438. //***********************************************(12)Power.Offered******************************************************/
  7439. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7440. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7441. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7442. {
  7443. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7444. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7445. {
  7446. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7447. {
  7448. tempIndex = ((gun_index==2) ? 1: 0);
  7449. }
  7450. else
  7451. {
  7452. tempIndex = gun_index;
  7453. }
  7454. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7455. {
  7456. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7457. {
  7458. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7459. }
  7460. } // END OF FOR CHAdeMO_QUANTITY
  7461. }
  7462. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7463. {
  7464. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7465. {
  7466. tempIndex = ((gun_index==2) ? 1: 0);
  7467. }
  7468. else
  7469. {
  7470. tempIndex = gun_index;
  7471. }
  7472. for (int index = 0; index < CCS_QUANTITY; index++)
  7473. {
  7474. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7475. {
  7476. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7477. }
  7478. } // END OF CCS_QUANTITY
  7479. }
  7480. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7481. {
  7482. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7483. {
  7484. tempIndex = ((gun_index==2) ? 1: 0);
  7485. }
  7486. else
  7487. {
  7488. tempIndex = gun_index;
  7489. }
  7490. for (int index = 0; index < GB_QUANTITY; index++)
  7491. {
  7492. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7493. {
  7494. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7495. }
  7496. } // END OF GB_QUANTITY
  7497. }
  7498. else if(gunType[gun_index] == GUN_TYPE_DO)
  7499. {
  7500. tempIndex = gun_index;
  7501. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7502. {
  7503. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7504. {
  7505. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7506. }
  7507. }
  7508. }
  7509. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7510. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7511. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7512. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7513. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7514. }
  7515. // Message create ====================================================================================================
  7516. if(TRUE)
  7517. {
  7518. json_object *MeterValueReq = json_object_new_object();
  7519. json_object *MeterValues = json_object_new_array();
  7520. json_object *sampledValues = json_object_new_array();
  7521. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7522. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7523. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7524. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7525. {
  7526. json_object *MeterValue = json_object_new_object();
  7527. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7528. {
  7529. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7530. {
  7531. json_object *sampledValue = json_object_new_object();
  7532. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7533. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7534. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7535. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7536. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7537. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7538. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7539. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7540. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7541. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7542. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7543. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7544. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7545. json_object_array_add(sampledValues, sampledValue);
  7546. }
  7547. }
  7548. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7549. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7550. json_object_array_add(MeterValues, MeterValue);
  7551. }
  7552. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7553. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7554. ,gun_index + 1
  7555. ,MESSAGE_TYPE_CALL
  7556. ,guid
  7557. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7558. json_object_put(MeterValueReq);
  7559. }
  7560. // Put request guid to hash map
  7561. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7562. 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*/)
  7563. {
  7564. result = PASS;
  7565. //DEBUG_INFO("MeterValues mapitem pass\n");
  7566. }
  7567. if((dataType != ReadingContext_Trigger) &&
  7568. (dataType != ReadingContext_Sample_Clock) &&
  7569. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7570. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7571. else
  7572. {
  7573. if(FirstHeartBeat)
  7574. LWS_Send(queuedata +2);
  7575. }
  7576. return result;
  7577. }
  7578. int sendLogStatusNotificationRequest(char *status)
  7579. {
  7580. mtrace();
  7581. int result = PASS;
  7582. char message[4096]={0};
  7583. char guid[37]={0};
  7584. char tempdata[128]={0};
  7585. json_object *LogStatusNotification = json_object_new_object();
  7586. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7587. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7588. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7589. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7590. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7591. random_uuid(guid);
  7592. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7593. json_object_put(LogStatusNotification);
  7594. LWS_Send(message);
  7595. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7596. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7597. {
  7598. result = PASS;
  7599. }
  7600. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7601. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7602. return result;
  7603. }
  7604. int sendSecurityEventNotificationRequest()
  7605. {
  7606. mtrace();
  7607. int result = PASS;
  7608. char message[4096]={0};
  7609. char guid[37]={0};
  7610. char tempdata[128]={0};
  7611. json_object *SecurityEventNotification = json_object_new_object();
  7612. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7613. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7614. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7615. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7616. random_uuid(guid);
  7617. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7618. json_object_put(SecurityEventNotification);
  7619. LWS_Send(message);
  7620. sprintf(tempdata, "SecurityEventNotification,0");
  7621. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7622. {
  7623. result = PASS;
  7624. }
  7625. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7626. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7627. return result;
  7628. }
  7629. int sendSignCertificateRequest()
  7630. {
  7631. mtrace();
  7632. int result = PASS;
  7633. char message[4096]={0};
  7634. char guid[37]={0};
  7635. char tempdata[128]={0};
  7636. json_object *SignCertificate = json_object_new_object();
  7637. DEBUG_INFO("sendSignCertificateRequest...\n");
  7638. // Read csr file content
  7639. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7640. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  7641. char *line = NULL;
  7642. size_t len = 0;
  7643. while(getline(&line, &len, fp) != -1)
  7644. {
  7645. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7646. {
  7647. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7648. }
  7649. }
  7650. fclose(fp);
  7651. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7652. random_uuid(guid);
  7653. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7654. json_object_put(SignCertificate);
  7655. LWS_Send(message);
  7656. sprintf(tempdata, "SignCertificate,0");
  7657. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7658. {
  7659. result = PASS;
  7660. }
  7661. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7662. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7663. return result;
  7664. }
  7665. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7666. {
  7667. mtrace();
  7668. int result = PASS;
  7669. char message[110]={0};
  7670. char guid[37]={0};
  7671. char tempdata[65]={0};
  7672. json_object *FirmwareStatusNotification = json_object_new_object();
  7673. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7674. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7675. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7676. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7677. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7678. random_uuid(guid);
  7679. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7680. json_object_put(FirmwareStatusNotification);
  7681. LWS_Send(message);
  7682. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7683. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7684. {
  7685. result = PASS;
  7686. }
  7687. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7688. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7689. return result;
  7690. }
  7691. //==========================================
  7692. // send confirm routine
  7693. //==========================================
  7694. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7695. {
  7696. mtrace();
  7697. int result = FAIL;
  7698. char message[100]={0};
  7699. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7700. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7701. LWS_Send(message);
  7702. result = TRUE;
  7703. return result;
  7704. }
  7705. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7706. {
  7707. mtrace();
  7708. int result = FAIL;
  7709. char message[100]={0};
  7710. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7711. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7712. LWS_Send(message);
  7713. result = TRUE;
  7714. return result;
  7715. }
  7716. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7717. {
  7718. mtrace();
  7719. int result = FAIL;
  7720. char message[100]={0};
  7721. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7722. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7723. LWS_Send(message);
  7724. result = TRUE;
  7725. return result;
  7726. }
  7727. int sendClearCacheConfirmation(char *uuid,char *payload)
  7728. {
  7729. mtrace();
  7730. int result = FAIL;
  7731. char message[500]={0};
  7732. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7733. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7734. LWS_Send(message);
  7735. return result;
  7736. }
  7737. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7738. {
  7739. mtrace();
  7740. int result = FAIL;
  7741. char message[500]={0};
  7742. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7743. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7744. LWS_Send(message);
  7745. return result;
  7746. }
  7747. int sendDataTransferConfirmation(char *uuid,char *payload)
  7748. {
  7749. mtrace();
  7750. char statusStr[20]={0};
  7751. char dataStr[10]={0};
  7752. char sstr[20]={0};
  7753. int c = 0;
  7754. char *loc;
  7755. int result = FAIL;
  7756. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7757. /**********************status**************************/
  7758. loc = strstr(payload, "status");
  7759. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7760. c = 0;
  7761. while (loc[3+strlen("status")+c] != '\"')
  7762. {
  7763. sstr[c] = loc[3+strlen("status")+c];
  7764. c++;
  7765. }
  7766. sstr[c] = '\0';
  7767. strcpy(statusStr, sstr);
  7768. /**********************data**************************/
  7769. loc = strstr(payload, "data");
  7770. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7771. c = 0;
  7772. while (loc[3+strlen("data")+c] != '\"')
  7773. {
  7774. sstr[c] = loc[3+strlen("data")+c];
  7775. c++;
  7776. }
  7777. sstr[c] = '\0';
  7778. strcpy(dataStr, sstr);
  7779. return result;
  7780. }
  7781. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7782. {
  7783. mtrace();
  7784. int result = FAIL;
  7785. char message[1000]={0};
  7786. int CompositeScheduleIndex = 0;
  7787. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7788. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7789. if(nPeriod == 0)
  7790. {
  7791. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7792. {
  7793. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7794. ,MESSAGE_TYPE_CALLRESULT
  7795. ,uuid
  7796. ,payload
  7797. ,connectorIdInt);
  7798. }
  7799. else
  7800. {
  7801. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7802. ,MESSAGE_TYPE_CALLRESULT
  7803. ,uuid
  7804. ,payload
  7805. ,connectorIdInt
  7806. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7807. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7808. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7809. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7810. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7811. }
  7812. }
  7813. else
  7814. {
  7815. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7816. ,MESSAGE_TYPE_CALLRESULT
  7817. ,uuid
  7818. ,payload
  7819. ,connectorIdInt
  7820. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7821. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7822. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7823. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7824. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7825. {
  7826. if (idx_sample == 0)
  7827. {
  7828. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7829. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7830. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7831. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7832. }
  7833. else
  7834. {
  7835. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7836. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7837. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7838. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7839. }
  7840. }
  7841. sprintf(message + strlen(message), "]}}]");
  7842. }
  7843. LWS_Send(message);
  7844. result = TRUE;
  7845. return result;
  7846. }
  7847. int sendGetConfigurationConfirmation(char *uuid)
  7848. {
  7849. mtrace();
  7850. int result = FAIL;
  7851. int MaxKeySupported = 0;
  7852. int sentConfigurationNumber= 0;
  7853. int sentunConfigurationNumber= 0;
  7854. char message[1024*10]={0};
  7855. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7856. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7857. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7858. ,MESSAGE_TYPE_CALLRESULT
  7859. ,uuid );
  7860. //configuration key
  7861. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7862. {
  7863. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7864. {
  7865. if (sentConfigurationNumber == 0)
  7866. {
  7867. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7868. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7869. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7870. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7871. }
  7872. else
  7873. {
  7874. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7875. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7876. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7877. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7878. }
  7879. sentConfigurationNumber = sentConfigurationNumber + 1;
  7880. }
  7881. }
  7882. sprintf(message + strlen(message), "]");
  7883. if(UnknownKeynum != 0)
  7884. {
  7885. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7886. //unkown key
  7887. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7888. {
  7889. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7890. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7891. if(sentunConfigurationNumber == 0)
  7892. {
  7893. sprintf(message + strlen(message), "\"%s\""
  7894. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7895. }
  7896. else
  7897. {
  7898. sprintf(message + strlen(message), ",\"%s\""
  7899. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7900. }
  7901. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7902. }
  7903. sprintf(message + strlen(message), "]");
  7904. }
  7905. sprintf(message + strlen(message), "}]");
  7906. LWS_Send(message);
  7907. return result;
  7908. }
  7909. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7910. {
  7911. mtrace();
  7912. int result = FAIL;
  7913. char message[400]={0};
  7914. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7915. if(strcmp(payload,"")==0)
  7916. {
  7917. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7918. }
  7919. else
  7920. {
  7921. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7922. }
  7923. LWS_Send(message);
  7924. result = TRUE;
  7925. return result;
  7926. }
  7927. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7928. {
  7929. mtrace();
  7930. int result = FAIL;
  7931. char message[80]={0};
  7932. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7933. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  7934. LWS_Send(message);
  7935. result = TRUE;
  7936. return result;
  7937. }
  7938. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7939. {
  7940. mtrace();
  7941. int result = FAIL;
  7942. char message[80]={0};
  7943. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7944. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7945. LWS_Send(message);
  7946. result = TRUE;
  7947. return result;
  7948. }
  7949. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7950. {
  7951. mtrace();
  7952. int result = FAIL;
  7953. char message[80]={0};
  7954. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7955. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7956. LWS_Send(message);
  7957. result = TRUE;
  7958. return result;
  7959. }
  7960. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7961. {
  7962. mtrace();
  7963. int result = FAIL;
  7964. char message[80]={0};
  7965. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7966. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7967. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7968. LWS_Send(message);
  7969. result = TRUE;
  7970. return result;
  7971. }
  7972. int sendResetConfirmation(char *uuid,char *payload)
  7973. {
  7974. mtrace();
  7975. int result = FAIL;
  7976. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7977. char message[80]={0};
  7978. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  7979. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7980. LWS_Send(message);
  7981. result = TRUE;
  7982. return result;
  7983. }
  7984. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7985. {
  7986. mtrace();
  7987. int result = FAIL;
  7988. char message[500]={0};
  7989. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7990. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7991. LWS_Send(message);
  7992. result = TRUE;
  7993. return result;
  7994. }
  7995. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7996. {
  7997. mtrace();
  7998. int result = FAIL;
  7999. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  8000. char message[80]={0};
  8001. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  8002. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8003. LWS_Send(message);
  8004. result = TRUE;
  8005. return result;
  8006. }
  8007. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  8008. {
  8009. mtrace();
  8010. int result = FAIL;
  8011. char message[80]={0};
  8012. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  8013. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8014. LWS_Send(message);
  8015. result = TRUE;
  8016. return result;
  8017. }
  8018. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  8019. {
  8020. mtrace();
  8021. int result = FAIL;
  8022. char message[80]={0};
  8023. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8024. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  8025. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8026. LWS_Send(message);
  8027. result = TRUE;
  8028. return result;
  8029. }
  8030. int sendUpdateFirmwareConfirmation(char *uuid)
  8031. {
  8032. mtrace();
  8033. int result = FAIL;
  8034. char message[60]={0};
  8035. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8036. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  8037. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8038. LWS_Send(message);
  8039. result = TRUE;
  8040. return result;
  8041. }
  8042. int sendCertificateSignedConfirmation(char *uuid)
  8043. {
  8044. mtrace();
  8045. int result = PASS;
  8046. char message[4096]={0};
  8047. json_object *CertificateSigned = json_object_new_object();
  8048. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  8049. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  8050. sprintf(message,"[%d,\"%s\",%s]"
  8051. ,MESSAGE_TYPE_CALLRESULT
  8052. ,uuid
  8053. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  8054. json_object_put(CertificateSigned);
  8055. LWS_Send(message);
  8056. return result;
  8057. }
  8058. int sendDeleteCertificateConfirmation(char *uuid)
  8059. {
  8060. mtrace();
  8061. int result = PASS;
  8062. char message[4096]={0};
  8063. json_object *DeleteCertificate = json_object_new_object();
  8064. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  8065. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  8066. sprintf(message,"[%d,\"%s\",%s]"
  8067. ,MESSAGE_TYPE_CALLRESULT
  8068. ,uuid
  8069. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  8070. json_object_put(DeleteCertificate);
  8071. LWS_Send(message);
  8072. return result;
  8073. }
  8074. int sendExtendedTriggerMessageConfirmation(char *uuid)
  8075. {
  8076. mtrace();
  8077. int result = PASS;
  8078. char message[4096]={0};
  8079. json_object *ExtendedTriggerMessage = json_object_new_object();
  8080. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  8081. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  8082. sprintf(message,"[%d,\"%s\",%s]"
  8083. ,MESSAGE_TYPE_CALLRESULT
  8084. ,uuid
  8085. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  8086. json_object_put(ExtendedTriggerMessage);
  8087. LWS_Send(message);
  8088. return result;
  8089. }
  8090. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  8091. {
  8092. mtrace();
  8093. int result = PASS;
  8094. char message[4096]={0};
  8095. json_object *GetInstalledCertificateIds = json_object_new_object();
  8096. json_object *certificateHashDataDatas = json_object_new_array();
  8097. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  8098. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  8099. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  8100. {
  8101. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  8102. {
  8103. json_object *certificateHashData = json_object_new_object();
  8104. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  8105. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  8106. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  8107. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  8108. json_object_array_add(certificateHashDataDatas, certificateHashData);
  8109. }
  8110. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  8111. }
  8112. else
  8113. {
  8114. json_object_put(certificateHashDataDatas);
  8115. }
  8116. sprintf(message,"[%d,\"%s\",%s]"
  8117. ,MESSAGE_TYPE_CALLRESULT
  8118. ,uuid
  8119. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  8120. json_object_put(GetInstalledCertificateIds);
  8121. LWS_Send(message);
  8122. return result;
  8123. }
  8124. int sendGetLogConfirmation(char *uuid)
  8125. {
  8126. mtrace();
  8127. int result = PASS;
  8128. char message[4096]={0};
  8129. json_object *GetLog = json_object_new_object();
  8130. DEBUG_INFO("sendGetLogConfirmation...\n");
  8131. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  8132. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  8133. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  8134. sprintf(message,"[%d,\"%s\",%s]"
  8135. ,MESSAGE_TYPE_CALLRESULT
  8136. ,uuid
  8137. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  8138. json_object_put(GetLog);
  8139. LWS_Send(message);
  8140. return result;
  8141. }
  8142. int sendInstallCertificateConfirmation(char *uuid)
  8143. {
  8144. mtrace();
  8145. int result = PASS;
  8146. char message[4096]={0};
  8147. json_object *InstallCertificate = json_object_new_object();
  8148. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  8149. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  8150. sprintf(message,"[%d,\"%s\",%s]"
  8151. ,MESSAGE_TYPE_CALLRESULT
  8152. ,uuid
  8153. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  8154. json_object_put(InstallCertificate);
  8155. LWS_Send(message);
  8156. return result;
  8157. }
  8158. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  8159. {
  8160. mtrace();
  8161. int result = PASS;
  8162. char message[4096]={0};
  8163. json_object *SignedUpdateFirmware = json_object_new_object();
  8164. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  8165. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  8166. sprintf(message,"[%d,\"%s\",%s]"
  8167. ,MESSAGE_TYPE_CALLRESULT
  8168. ,uuid
  8169. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  8170. json_object_put(SignedUpdateFirmware);
  8171. LWS_Send(message);
  8172. return result;
  8173. }
  8174. int sendUnknownConfirmation(char *uuid)
  8175. {
  8176. mtrace();
  8177. int result = PASS;
  8178. char message[256]={0};
  8179. DEBUG_INFO("sendUnknownConfirmation...\n");
  8180. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  8181. LWS_Send(message);
  8182. return result;
  8183. }
  8184. //==========================================
  8185. // Handle server request routine Start
  8186. //==========================================
  8187. int handleCancelReservationRequest(char *uuid, char *payload)
  8188. {
  8189. mtrace();
  8190. int result = FAIL;
  8191. int gunNO = 0;
  8192. int reservationIdInt = -1;
  8193. char comfirmstr[20];
  8194. DEBUG_INFO("handleCancelReservationRequest...\n");
  8195. json_object *CancelReservation;
  8196. CancelReservation = json_tokener_parse(payload);
  8197. if(!is_error(CancelReservation))
  8198. {
  8199. // Required data
  8200. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  8201. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  8202. }
  8203. json_object_put(CancelReservation);
  8204. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  8205. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8206. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  8207. if(reservationIdInt != -1)
  8208. {
  8209. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8210. //check Transaction active
  8211. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8212. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8213. {
  8214. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  8215. {
  8216. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8217. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8218. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8219. {
  8220. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8221. }
  8222. else
  8223. {
  8224. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8225. }
  8226. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8227. goto end;
  8228. }
  8229. }
  8230. for (int index = 0; index < CCS_QUANTITY; index++)
  8231. {
  8232. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8233. {
  8234. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8235. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8236. if(gunType[2] == GUN_TYPE_CCS)
  8237. {
  8238. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8239. }
  8240. else
  8241. {
  8242. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8243. }
  8244. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8245. goto end;
  8246. }
  8247. }
  8248. for (int index = 0; index < GB_QUANTITY; index++)
  8249. {
  8250. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8251. {
  8252. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8253. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8254. if(gunType[2] == GUN_TYPE_GBT)
  8255. {
  8256. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8257. }
  8258. else
  8259. {
  8260. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8261. }
  8262. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8263. goto end;
  8264. }
  8265. }
  8266. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8267. {
  8268. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8269. {
  8270. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8271. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8272. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8273. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8274. goto end;
  8275. }
  8276. }
  8277. for (int index = 0; index < AC_QUANTITY; index++)
  8278. {
  8279. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8280. {
  8281. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8282. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8283. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8284. {
  8285. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8286. }
  8287. else
  8288. {
  8289. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8290. }
  8291. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8292. goto end;
  8293. }
  8294. }
  8295. }
  8296. //The reservationId does NOT match the reservationId
  8297. sendCancelReservationConfirmation(uuid, comfirmstr);
  8298. end:
  8299. // Fill in ocpp packet uuid
  8300. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  8301. return result;
  8302. }
  8303. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8304. {
  8305. mtrace();
  8306. int result = FAIL;
  8307. int gunIndex = -1;
  8308. char typeStr[16]={0};
  8309. char comfirmstr[20];
  8310. int specificId = FALSE;
  8311. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8312. json_object *ChangeAvailability;
  8313. ChangeAvailability = json_tokener_parse(payload);
  8314. if(!is_error(ChangeAvailability))
  8315. {
  8316. // Required data
  8317. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8318. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8319. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8320. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8321. }
  8322. json_object_put(ChangeAvailability);
  8323. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8324. {
  8325. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8326. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8327. }
  8328. else if(gunIndex == 0)
  8329. {
  8330. for(int i=0; i < gunTotalNumber; i++)
  8331. {
  8332. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8333. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8334. }
  8335. }
  8336. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8337. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8338. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8339. {
  8340. specificId = TRUE;
  8341. }
  8342. if(specificId == FALSE)
  8343. goto end;
  8344. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8345. {
  8346. //----------------------gunIndex is 0 ------------------------------------------------//
  8347. if(gunIndex == 0)
  8348. {
  8349. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8350. {
  8351. for(int i=0; i < gunTotalNumber; i++)
  8352. {
  8353. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8354. {
  8355. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8356. {
  8357. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8358. {
  8359. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8360. goto end;
  8361. }
  8362. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8363. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8364. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8365. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8366. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8367. {
  8368. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8369. goto end;
  8370. }
  8371. }
  8372. }//END FOR CHAdeMO_QUANTITY
  8373. for (int index = 0; index < CCS_QUANTITY; index++)
  8374. {
  8375. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8376. {
  8377. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8378. {
  8379. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8380. goto end;
  8381. }
  8382. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8383. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8384. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8385. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8386. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8387. {
  8388. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8389. goto end;
  8390. }
  8391. }
  8392. }//END FOR CCS_QUANTITY
  8393. for (int index = 0; index < GB_QUANTITY; index++)
  8394. {
  8395. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8396. {
  8397. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8398. {
  8399. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8400. goto end;
  8401. }
  8402. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8403. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8404. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8405. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8406. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8407. {
  8408. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8409. goto end;
  8410. }
  8411. }
  8412. }// END FOR GB_QUANTITY
  8413. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8414. {
  8415. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8416. {
  8417. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8418. {
  8419. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8420. goto end;
  8421. }
  8422. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8423. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8424. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8425. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8426. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8427. {
  8428. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8429. goto end;
  8430. }
  8431. }
  8432. }// END FOR GENERAL_GUN_QUANTITY
  8433. for (int index = 0; index < AC_QUANTITY; index++)
  8434. {
  8435. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8436. {
  8437. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8438. {
  8439. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8440. goto end;
  8441. }
  8442. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8443. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8444. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8445. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8446. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8447. {
  8448. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8449. goto end;
  8450. }
  8451. }
  8452. }//END FOR AC_QUANTITY
  8453. }// END FOR gunTotalNumber
  8454. }
  8455. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8456. {
  8457. for(int i=0; i < gunTotalNumber; i++)
  8458. {
  8459. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8460. {
  8461. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8462. goto end;
  8463. }
  8464. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8465. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8466. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8467. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8468. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8469. {
  8470. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8471. goto end;
  8472. }
  8473. }
  8474. }
  8475. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8476. goto end;
  8477. }
  8478. //----------------------gunIndex is not 0 ------------------------------------------------//
  8479. //check Transaction active
  8480. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8481. {
  8482. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8483. {
  8484. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8485. {
  8486. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8487. goto end;
  8488. }
  8489. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8490. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8491. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8492. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8493. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8494. {
  8495. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8496. goto end;
  8497. }
  8498. else
  8499. {
  8500. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8501. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8502. goto end;
  8503. }
  8504. }
  8505. }//END FOR CHAdeMO_QUANTITY
  8506. for (int index = 0; index < CCS_QUANTITY; index++)
  8507. {
  8508. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8509. {
  8510. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8511. {
  8512. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8513. goto end;
  8514. }
  8515. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8516. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8517. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8518. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8519. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8520. {
  8521. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8522. goto end;
  8523. }
  8524. else
  8525. {
  8526. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8527. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8528. goto end;
  8529. }
  8530. }
  8531. }//END FOR CCS_QUANTITY
  8532. for (int index = 0; index < GB_QUANTITY; index++)
  8533. {
  8534. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8535. {
  8536. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8537. {
  8538. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8539. goto end;
  8540. }
  8541. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8542. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8543. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8544. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8545. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8546. {
  8547. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8548. goto end;
  8549. }
  8550. else
  8551. {
  8552. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8553. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8554. goto end;
  8555. }
  8556. }
  8557. }// END FOR GB_QUANTITY
  8558. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8559. {
  8560. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8561. {
  8562. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8563. {
  8564. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8565. goto end;
  8566. }
  8567. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8568. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8569. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8570. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8571. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8572. {
  8573. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8574. goto end;
  8575. }
  8576. else
  8577. {
  8578. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8579. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8580. goto end;
  8581. }
  8582. }
  8583. }// END FOR GENERAL_GUN_QUANTITY
  8584. for (int index = 0; index < AC_QUANTITY; index++)
  8585. {
  8586. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8587. {
  8588. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8589. {
  8590. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8591. goto end;
  8592. }
  8593. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8594. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8595. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8596. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8597. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8598. {
  8599. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8600. goto end;
  8601. }
  8602. else
  8603. {
  8604. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8605. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8606. goto end;
  8607. }
  8608. }
  8609. }//END FOR AC_QUANTITY
  8610. }//END FOR AvailabilityTypeStr[Inoperative]
  8611. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8612. {
  8613. //----------------------gunIndex is 0 ------------------------------------------------//
  8614. if(gunIndex == 0)
  8615. {
  8616. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8617. {
  8618. for(int i=0; i < gunTotalNumber; i++)
  8619. {
  8620. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8621. {
  8622. 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
  8623. {
  8624. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8625. goto end;
  8626. }
  8627. }//END FOR CHAdeMO_QUANTITY
  8628. for (int index = 0; index < CCS_QUANTITY; index++)
  8629. {
  8630. 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
  8631. {
  8632. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8633. goto end;
  8634. }
  8635. }//END FOR CCS_QUANTITY
  8636. for (int index = 0; index < GB_QUANTITY; index++)
  8637. {
  8638. 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
  8639. {
  8640. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8641. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8642. goto end;
  8643. }
  8644. }// END FOR GB_QUANTITY
  8645. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8646. {
  8647. 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
  8648. {
  8649. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8650. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8651. goto end;
  8652. }
  8653. }// END FOR GENERAL_GUN_QUANTITY
  8654. for (int index = 0; index < AC_QUANTITY; index++)
  8655. {
  8656. 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
  8657. {
  8658. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8659. goto end;
  8660. }
  8661. }//END FOR CHAdeMO_QUANTITY
  8662. }// END FOR gunTotalNumber
  8663. }
  8664. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8665. {
  8666. for(int i=0; i < gunTotalNumber; i++)
  8667. {
  8668. for (int index = 0; index < AC_QUANTITY; index++)
  8669. {
  8670. 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
  8671. {
  8672. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8673. goto end;
  8674. }
  8675. }//END FOR CHAdeMO_QUANTITY
  8676. } // END FOR gunTotalNumber
  8677. }
  8678. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8679. goto end;
  8680. }
  8681. //----------------------gunIndex is not 0 ------------------------------------------------//
  8682. //check Transaction active
  8683. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8684. {
  8685. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8686. {
  8687. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8688. goto end;
  8689. }
  8690. }//END FOR CHAdeMO_QUANTITY
  8691. for (int index = 0; index < CCS_QUANTITY; index++)
  8692. {
  8693. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8694. {
  8695. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8696. goto end;
  8697. }
  8698. }//END FOR CCS_QUANTITY
  8699. for (int index = 0; index < GB_QUANTITY; index++)
  8700. {
  8701. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8702. {
  8703. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8704. goto end;
  8705. }
  8706. }// END FOR GB_QUANTITY
  8707. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8708. {
  8709. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8710. {
  8711. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8712. goto end;
  8713. }
  8714. }// END FOR GENERAL_GUN_QUANTITY
  8715. for (int index = 0; index < AC_QUANTITY; index++)
  8716. {
  8717. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8718. {
  8719. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8720. goto end;
  8721. }
  8722. }//END FOR AC_QUANTITY
  8723. }//END FOR AvailabilityTypeStr[Operative]
  8724. end:
  8725. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8726. {
  8727. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8728. }
  8729. else
  8730. {
  8731. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8732. }
  8733. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8734. {
  8735. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8736. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8737. }
  8738. else if(gunIndex == 0)
  8739. {
  8740. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8741. {
  8742. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8743. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8744. }
  8745. }
  8746. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8747. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8748. return result;
  8749. }
  8750. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8751. {
  8752. mtrace();
  8753. int valueInvalid = NO;
  8754. int result = FAIL;
  8755. char keystr[40]={0};
  8756. char valuestr[501]={0}; //value should be limited in 500 bytes
  8757. char comfirmstr[20]={0};
  8758. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8759. json_object *ChangeConfiguration;
  8760. ChangeConfiguration = json_tokener_parse(payload);
  8761. if(!is_error(ChangeConfiguration))
  8762. {
  8763. // Required data
  8764. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8765. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8766. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8767. {
  8768. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8769. }
  8770. else
  8771. {
  8772. valueInvalid = YES;
  8773. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8774. }
  8775. }
  8776. json_object_put(ChangeConfiguration);
  8777. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  8778. {
  8779. DEBUG_ERROR("Payload is null or value is invalid.\n");
  8780. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8781. }
  8782. else
  8783. {
  8784. int status = setKeyValue(keystr, valuestr);
  8785. switch(status)
  8786. {
  8787. case ConfigurationStatus_Accepted:
  8788. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8789. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  8790. StoreConfigurationTable();
  8791. break;
  8792. case RebootRequired:
  8793. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8794. StoreConfigurationTable();
  8795. break;
  8796. case NotSupported:
  8797. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8798. break;
  8799. case ConfigurationStatus_Rejected:
  8800. default:
  8801. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8802. break;
  8803. }
  8804. }
  8805. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8806. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  8807. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8808. {
  8809. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8810. SetOcppConnStatus(FALSE);
  8811. }
  8812. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8813. {
  8814. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8815. }
  8816. return result;
  8817. }
  8818. int handleClearCacheRequest(char *uuid, char *payload)
  8819. {
  8820. mtrace();
  8821. int result = FAIL;
  8822. char comfirmstr[20];
  8823. char rmFileCmd[100]={0};
  8824. struct stat stats;
  8825. DEBUG_INFO("handleClearCacheRequest...\n");
  8826. stat("/Storage/OCPP", &stats);
  8827. // Check for directory existence
  8828. if (S_ISDIR(stats.st_mode) == 1)
  8829. {}
  8830. else
  8831. {
  8832. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8833. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  8834. system(rmFileCmd);
  8835. }
  8836. if(OCPP_cleanLocalCache())
  8837. {
  8838. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8839. }
  8840. else
  8841. {
  8842. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8843. }
  8844. sendClearCacheConfirmation(uuid, comfirmstr);
  8845. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8846. return result;
  8847. }
  8848. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8849. {
  8850. mtrace();
  8851. int result = FAIL;
  8852. int resultRename;
  8853. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8854. char chargingProfilePurposeStr[26]={0};
  8855. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8856. char tempchargingProfilePurposeStr[26]={0};
  8857. char str[100]={0};
  8858. char fname[200]={0};
  8859. char comfirmstr[20]={0};
  8860. char word[1600]={0};
  8861. int clearflag = FALSE;
  8862. int chargingProfileIdIsNULL = FALSE;
  8863. int connectorIsNULL = FALSE;
  8864. int chargingProfilePurposeIsNULL = FALSE;
  8865. int stackLevelIsNULL = FALSE;
  8866. //int GotoEnd = FALSE;
  8867. FILE *fptr1, *fptr2;
  8868. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  8869. int n_chargingProfile=0;
  8870. int isEmptyFile = FALSE;
  8871. char sLineWord[1600]={0};
  8872. char chargingProfiles[10][100]={0};
  8873. int ChargeProfileCount = 0;
  8874. int ch;
  8875. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8876. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8877. json_object *ClearChargingProfile;
  8878. ClearChargingProfile = json_tokener_parse(payload);
  8879. if(!is_error(ClearChargingProfile))
  8880. {
  8881. // Optional data
  8882. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8883. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8884. else
  8885. chargingProfileIdIsNULL = TRUE;
  8886. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8887. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8888. else
  8889. connectorIsNULL = TRUE;
  8890. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8891. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8892. else
  8893. chargingProfilePurposeIsNULL = TRUE;
  8894. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8895. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8896. else
  8897. stackLevelIsNULL = TRUE;
  8898. }
  8899. json_object_put(ClearChargingProfile);
  8900. if(connectorIsNULL == FALSE)
  8901. {
  8902. switch(connectorIdInt)
  8903. {
  8904. case 0:
  8905. if(chargingProfilePurposeIsNULL == TRUE)
  8906. {
  8907. int l = 0;
  8908. strcpy(fname, ChargePointMaxProfile_JSON);
  8909. if((access(fname,F_OK))!=-1)
  8910. {
  8911. strcpy(chargingProfiles[l], fname);
  8912. l = l + 1;
  8913. }
  8914. strcpy(fname, TxDefaultProfile_0_JSON);
  8915. if((access(fname,F_OK))!=-1)
  8916. {
  8917. strcpy(chargingProfiles[l], fname);
  8918. l = l + 1;
  8919. }
  8920. ChargeProfileCount = l;
  8921. }
  8922. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8923. {
  8924. strcpy(fname, ChargePointMaxProfile_JSON);
  8925. if((access(fname,F_OK))!=-1)
  8926. {
  8927. strcpy(chargingProfiles[0], fname);
  8928. ChargeProfileCount = 1;
  8929. }
  8930. }
  8931. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8932. {
  8933. strcpy(fname, TxDefaultProfile_0_JSON);
  8934. if((access(fname,F_OK))!=-1)
  8935. {
  8936. strcpy(chargingProfiles[0], fname);
  8937. ChargeProfileCount = 1;
  8938. }
  8939. }
  8940. break;
  8941. default:
  8942. if(chargingProfilePurposeIsNULL == TRUE)
  8943. {
  8944. int m = 0;
  8945. memset(fname, 0, ARRAY_SIZE(fname));
  8946. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8947. if((access(fname,F_OK))!=-1)
  8948. {
  8949. strcpy(chargingProfiles[m], fname);
  8950. m = m + 1;
  8951. }
  8952. memset(fname, 0, ARRAY_SIZE(fname));
  8953. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8954. if((access(fname,F_OK))!=-1)
  8955. {
  8956. strcpy(chargingProfiles[m], fname);
  8957. m = m + 1;
  8958. }
  8959. ChargeProfileCount = m;
  8960. }
  8961. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8962. {
  8963. //strcpy(fname, TxDefaultProfile_1_JSON);
  8964. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8965. if((access(fname,F_OK))!=-1)
  8966. {
  8967. strcpy(chargingProfiles[0], fname);
  8968. ChargeProfileCount = 1;
  8969. }
  8970. }
  8971. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8972. {
  8973. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8974. if((access(fname,F_OK))!=-1)
  8975. {
  8976. strcpy(chargingProfiles[0], fname);
  8977. ChargeProfileCount = 1;
  8978. }
  8979. //strcpy(fname, TxProfile_1_JSON);
  8980. }
  8981. //strcpy(fname, ChargePointMaxProfile_JSON );
  8982. break;
  8983. }
  8984. }
  8985. else // Check all Charging Profiles
  8986. {
  8987. int i = 0;
  8988. char fnametemp[200]={0};
  8989. ChargeProfileCount = 0;
  8990. //Check ChargePointMaxProfile.json exit
  8991. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8992. {
  8993. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  8994. i = i + 1;
  8995. }
  8996. //Check TxDefaultProfile_0.json exit
  8997. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8998. {
  8999. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  9000. i = i + 1;
  9001. }
  9002. //Check TxDefaultProfile_%d.json
  9003. for(int j=1; j <= gunTotalNumber; j++)
  9004. {
  9005. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9006. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9007. if((access(fnametemp,F_OK))!=-1)
  9008. {
  9009. strcpy(chargingProfiles[i], fnametemp);
  9010. i = i + 1;
  9011. }
  9012. }
  9013. //Check TxProfile_%d.json
  9014. for(int j=1; j <= gunTotalNumber; j++)
  9015. {
  9016. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9017. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9018. if((access(fnametemp,F_OK))!=-1)
  9019. {
  9020. strcpy(chargingProfiles[i], fnametemp);
  9021. i = i + 1;
  9022. }
  9023. }
  9024. ChargeProfileCount = i;
  9025. }// End connectorIsNULL is TRUE
  9026. if(ChargeProfileCount == 0)
  9027. {
  9028. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9029. goto end;
  9030. }
  9031. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  9032. {
  9033. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9034. goto end;
  9035. }
  9036. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  9037. {
  9038. memset(str, 0, ARRAY_SIZE(str));
  9039. // clear temp file
  9040. sprintf(str,"rm -f %s",temp);
  9041. system(str);
  9042. for(int k=0; k < ChargeProfileCount; k++)
  9043. {
  9044. memset(str, 0, ARRAY_SIZE(str));
  9045. //clear file in C
  9046. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9047. system(str);
  9048. }
  9049. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9050. goto end;
  9051. }
  9052. else if(connectorIsNULL == TRUE)
  9053. {
  9054. for(int k=0; k < ChargeProfileCount; k++)
  9055. {
  9056. fptr1 = fopen(chargingProfiles[k], "r");
  9057. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  9058. //Check Charging Profile Count
  9059. while(fscanf(fptr1, "%s", word) != EOF)
  9060. {
  9061. //DEBUG_INFO("word=%s\n",word);
  9062. if(strstr(word, "chargingProfileId")!= NULL)
  9063. {
  9064. //DEBUG_INFO("test chargingProfileId \n");
  9065. n_chargingProfile = n_chargingProfile + 1;
  9066. //DEBUG_INFO("chargingProfileId Found\n");
  9067. }
  9068. }
  9069. rewind(fptr1);
  9070. //search Charging Profile Element
  9071. //int i= 0;
  9072. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9073. {
  9074. json_object *tmpProfilee;
  9075. tmpProfilee = json_tokener_parse(sLineWord);
  9076. if(!is_error(tmpProfilee))
  9077. {
  9078. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9079. {
  9080. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9081. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9082. }
  9083. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9084. {
  9085. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9086. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9087. }
  9088. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9089. {
  9090. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9091. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9092. }
  9093. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9094. {
  9095. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9096. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9097. }
  9098. }
  9099. json_object_put(tmpProfilee);
  9100. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9101. {
  9102. //------- not write to fptr2-------//
  9103. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9104. //clearflag = TRUE;
  9105. }
  9106. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9107. {
  9108. //------- not write to fptr2-------//
  9109. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9110. }
  9111. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9112. {
  9113. //------- not write to fptr2-------//
  9114. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9115. }
  9116. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  9117. {
  9118. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9119. }
  9120. else
  9121. {
  9122. fprintf(fptr2, sLineWord);//writing data into file
  9123. }
  9124. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9125. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9126. if(clearflag == TRUE)
  9127. {
  9128. fclose(fptr1);
  9129. fclose(fptr2);
  9130. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9131. system(str);
  9132. // clear temp file
  9133. sprintf(str,"rm -f %s",temp);
  9134. system(str);
  9135. }
  9136. else
  9137. {
  9138. fclose(fptr1);
  9139. fclose(fptr2);
  9140. memset(str, 0, ARRAY_SIZE(str));
  9141. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9142. system(str);
  9143. resultRename = rename(temp, chargingProfiles[k]);
  9144. if(resultRename == 0)
  9145. {
  9146. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  9147. }
  9148. else
  9149. {
  9150. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  9151. }
  9152. if(comfirmstr[0]== 0)
  9153. {
  9154. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9155. }
  9156. //Check chargingProfile is empty file
  9157. /*------ Read the file ----------------*/
  9158. fptr1=fopen(chargingProfiles[k],"r");
  9159. ch=fgetc(fptr1);
  9160. rewind(fptr1);
  9161. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9162. if(ch!=EOF)
  9163. {
  9164. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9165. {
  9166. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9167. if(sLineWord[0]=='\0')
  9168. {
  9169. isEmptyFile = TRUE;
  9170. break;
  9171. }
  9172. else
  9173. {
  9174. isEmptyFile = FALSE;
  9175. break;
  9176. }
  9177. }
  9178. }
  9179. else
  9180. isEmptyFile = TRUE;
  9181. fclose(fptr1);
  9182. if(isEmptyFile == TRUE)
  9183. {
  9184. memset(str, 0, ARRAY_SIZE(str));
  9185. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9186. system(str);
  9187. }
  9188. }
  9189. }// End of while(int k=0; k < ChargePointCount; k++)
  9190. }
  9191. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  9192. {
  9193. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  9194. for(int k=0; k < ChargeProfileCount; k++)
  9195. {
  9196. fptr1 = fopen(chargingProfiles[k], "r");
  9197. fptr2 = fopen(temp, "w+");
  9198. //Check Charging Profile Count
  9199. while(fscanf(fptr1, "%s", word) != EOF)
  9200. {
  9201. //DEBUG_INFO("word=%s\n",word);
  9202. if(strstr(word, "chargingProfileId")!= NULL)
  9203. {
  9204. n_chargingProfile = n_chargingProfile + 1;
  9205. }
  9206. }
  9207. rewind(fptr1);
  9208. //search Charging Profile Element
  9209. //int i= 0;
  9210. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9211. {
  9212. json_object *tmpProfilee;
  9213. tmpProfilee = json_tokener_parse(sLineWord);
  9214. if(!is_error(tmpProfilee))
  9215. {
  9216. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9217. {
  9218. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9219. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9220. }
  9221. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9222. {
  9223. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9224. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9225. }
  9226. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9227. {
  9228. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9229. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9230. }
  9231. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9232. {
  9233. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9234. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9235. }
  9236. }
  9237. json_object_put(tmpProfilee);
  9238. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9239. {
  9240. //------- not write to fptr2-------//
  9241. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9242. //clearflag = TRUE;
  9243. }
  9244. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9245. {
  9246. //------- not write to fptr2-------//
  9247. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9248. }
  9249. else if(stackLevelIsNULL == TRUE)
  9250. {
  9251. //Clear Whole File
  9252. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9253. clearflag = TRUE;
  9254. break;
  9255. }
  9256. else
  9257. {
  9258. fprintf(fptr2, sLineWord);//writing data into file
  9259. }
  9260. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9261. }
  9262. if(clearflag == TRUE)
  9263. {
  9264. fclose(fptr1);
  9265. fclose(fptr2);
  9266. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9267. system(str);
  9268. // clear temp file
  9269. sprintf(str,"rm -f %s",temp);
  9270. system(str);
  9271. }
  9272. else
  9273. {
  9274. fclose(fptr1);
  9275. fclose(fptr2);
  9276. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9277. system(str);
  9278. resultRename = rename(temp, chargingProfiles[k]);
  9279. if(resultRename == 0)
  9280. {
  9281. DEBUG_INFO("File ChargingProfile renamed successfully");
  9282. }
  9283. else
  9284. {
  9285. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9286. }
  9287. if(comfirmstr[0]== 0)
  9288. {
  9289. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9290. }
  9291. //Check chargingProfile is empty file
  9292. /*------ Read the file ----------------*/
  9293. fptr1=fopen(chargingProfiles[k],"r");
  9294. ch=fgetc(fptr1);
  9295. rewind(fptr1);
  9296. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9297. if(ch!=EOF)
  9298. {
  9299. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9300. {
  9301. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9302. if(sLineWord[0]=='\0')
  9303. {
  9304. isEmptyFile = TRUE;
  9305. break;
  9306. }
  9307. else
  9308. {
  9309. isEmptyFile = FALSE;
  9310. break;
  9311. }
  9312. }
  9313. }
  9314. else
  9315. isEmptyFile = TRUE;
  9316. fclose(fptr1);
  9317. if(isEmptyFile == TRUE)
  9318. {
  9319. memset(str, 0, ARRAY_SIZE(str));
  9320. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9321. system(str);
  9322. }
  9323. /*------- End of reading ---------------*/
  9324. }
  9325. } // while(int k=0; k < ChargeProfileCount; k++)
  9326. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9327. end:
  9328. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9329. {
  9330. if(connectorIdInt == 0)
  9331. {
  9332. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9333. {
  9334. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9335. }
  9336. }
  9337. else
  9338. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9339. }
  9340. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9341. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9342. return result;
  9343. }
  9344. void createFirmwareVersionByDataTransfer(void)
  9345. {
  9346. json_object *FirmwareDataTransfer = json_object_new_object();
  9347. // AC & DC model
  9348. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9349. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9350. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9351. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9352. // DC model
  9353. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9354. {
  9355. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9356. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9357. (gunType[3] != GUN_TYPE_UNKNOWN))
  9358. {
  9359. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9360. }
  9361. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9362. {
  9363. // DS DM DW
  9364. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9365. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9366. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9367. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9368. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9369. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9370. }
  9371. else
  9372. {
  9373. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9374. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9375. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9376. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9377. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9378. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9379. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9380. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9381. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9382. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9383. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9384. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9385. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9386. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9387. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9388. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9389. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9390. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9391. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9392. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9393. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9394. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9395. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9396. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9397. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9398. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9399. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9400. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9401. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9402. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9403. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9404. }
  9405. }
  9406. // 4G model
  9407. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9408. {
  9409. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9410. }
  9411. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9412. json_object_put(FirmwareDataTransfer);
  9413. }
  9414. int handleDataTransferRequest(char *uuid, char *payload)
  9415. {
  9416. mtrace();
  9417. json_object *response = json_object_new_object();
  9418. int result = FAIL;
  9419. char tempvendorId[255]={0};
  9420. char tempmessageId[50]={0};
  9421. char tempdata[1024]={0};
  9422. char message[2048]={0};
  9423. DEBUG_INFO("handleDataTransferRequest...\n");
  9424. if((uuid != NULL) && (payload != NULL))
  9425. {
  9426. json_object *DataTransfer;
  9427. DataTransfer = json_tokener_parse(payload);
  9428. if(!is_error(DataTransfer))
  9429. {
  9430. // Required data
  9431. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9432. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9433. // Optional data
  9434. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9435. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9436. if(json_object_object_get(DataTransfer, "data") != NULL)
  9437. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9438. result = PASS;
  9439. }
  9440. json_object_put(DataTransfer);
  9441. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9442. {
  9443. // Send all moudle firmware version on EVSE
  9444. createFirmwareVersionByDataTransfer();
  9445. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9446. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9447. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9448. json_object_put(response);
  9449. }
  9450. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9451. {
  9452. system("/usr/bin/run_tmate_restart.sh &");
  9453. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9454. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9455. json_object_put(response);
  9456. }
  9457. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9458. {
  9459. json_object *data;
  9460. data = json_tokener_parse(tempdata);
  9461. if(!is_error(data))
  9462. {
  9463. 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))
  9464. {
  9465. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9466. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9467. if(json_object_object_get(data, "SOC") != NULL)
  9468. {
  9469. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9470. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9471. }
  9472. if(json_object_object_get(data, "Energy") != NULL)
  9473. {
  9474. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9475. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9476. }
  9477. if(json_object_object_get(data, "Duration") != NULL)
  9478. {
  9479. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9480. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9481. }
  9482. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9483. }
  9484. else
  9485. {
  9486. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9487. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9488. }
  9489. }
  9490. else
  9491. {
  9492. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9493. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9494. }
  9495. json_object_put(data);
  9496. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9497. json_object_put(response);
  9498. }
  9499. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9500. {
  9501. json_object *data;
  9502. data = json_tokener_parse(tempdata);
  9503. if(!is_error(data))
  9504. {
  9505. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9506. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9507. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9508. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9509. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9510. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9511. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9512. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9513. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9514. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9515. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9516. }
  9517. else
  9518. {
  9519. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9520. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9521. }
  9522. json_object_put(data);
  9523. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9524. json_object_put(response);
  9525. }
  9526. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9527. {
  9528. json_object *data;
  9529. data = json_tokener_parse(tempdata);
  9530. if(!is_error(data))
  9531. {
  9532. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9533. if(json_object_object_get(data, "idToken") != NULL)
  9534. {
  9535. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9536. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9537. }
  9538. if(json_object_object_get(data, "price") != NULL)
  9539. {
  9540. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9541. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9542. }
  9543. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9544. }
  9545. else
  9546. {
  9547. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9548. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9549. }
  9550. json_object_put(data);
  9551. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9552. json_object_put(response);
  9553. }
  9554. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9555. {
  9556. json_object *data;
  9557. data = json_tokener_parse(tempdata);
  9558. if(!is_error(data))
  9559. {
  9560. if(json_object_object_get(data, "txId") != NULL)
  9561. {
  9562. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9563. for(int idx = 0;idx<gunTotalNumber;idx++)
  9564. {
  9565. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9566. {
  9567. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9568. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9569. if(json_object_object_get(data, "description") != NULL)
  9570. {
  9571. // California pricing V1.0
  9572. DEBUG_INFO("California pricing V1.0\n");
  9573. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9574. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9575. }
  9576. else
  9577. {
  9578. // California pricing V1.1
  9579. DEBUG_INFO("California pricing V1.1\n");
  9580. if(json_object_object_get(data, "timestamp") != NULL)
  9581. {
  9582. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9583. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9584. }
  9585. if(json_object_object_get(data, "meterValue") != NULL)
  9586. {
  9587. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9588. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9589. }
  9590. if(json_object_object_get(data, "cost") != NULL)
  9591. {
  9592. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9593. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9594. }
  9595. if(json_object_object_get(data, "state") != NULL)
  9596. {
  9597. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9598. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9599. }
  9600. if(json_object_object_get(data, "chargingPrice") != NULL)
  9601. {
  9602. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9603. {
  9604. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9605. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9606. }
  9607. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9608. {
  9609. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9610. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9611. }
  9612. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9613. {
  9614. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9615. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9616. }
  9617. }
  9618. if(json_object_object_get(data, "idlePrice") != NULL)
  9619. {
  9620. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9621. {
  9622. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9623. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9624. }
  9625. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9626. {
  9627. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9628. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9629. }
  9630. }
  9631. if(json_object_object_get(data, "nextPeriod") != NULL)
  9632. {
  9633. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9634. {
  9635. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9636. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9637. }
  9638. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9639. {
  9640. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9641. {
  9642. 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")));
  9643. 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"));
  9644. }
  9645. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9646. {
  9647. 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")));
  9648. 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"));
  9649. }
  9650. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9651. {
  9652. 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")));
  9653. 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"));
  9654. }
  9655. }
  9656. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9657. {
  9658. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9659. {
  9660. 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")));
  9661. 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"));
  9662. }
  9663. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9664. {
  9665. 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")));
  9666. 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"));
  9667. }
  9668. }
  9669. }
  9670. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9671. {
  9672. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9673. {
  9674. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9675. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9676. }
  9677. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9678. {
  9679. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9680. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9681. }
  9682. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9683. {
  9684. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9685. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9686. }
  9687. }
  9688. }
  9689. }
  9690. }
  9691. }
  9692. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9693. }
  9694. else
  9695. {
  9696. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9697. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9698. }
  9699. json_object_put(data);
  9700. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9701. json_object_put(response);
  9702. }
  9703. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9704. {
  9705. json_object *data;
  9706. data = json_tokener_parse(tempdata);
  9707. if(!is_error(data))
  9708. {
  9709. if(json_object_object_get(data, "txId") != NULL)
  9710. {
  9711. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9712. for(int idx = 0;idx<gunTotalNumber;idx++)
  9713. {
  9714. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9715. {
  9716. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9717. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9718. if(json_object_object_get(data, "description") != NULL)
  9719. {
  9720. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9721. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9722. }
  9723. }
  9724. }
  9725. }
  9726. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9727. }
  9728. else
  9729. {
  9730. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9731. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9732. }
  9733. json_object_put(data);
  9734. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9735. json_object_put(response);
  9736. }
  9737. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9738. {
  9739. json_object *data;
  9740. data = json_tokener_parse(tempdata);
  9741. if(!is_error(data))
  9742. {
  9743. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9744. if(json_object_object_get(data, "Content_Type") != NULL)
  9745. {
  9746. 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))
  9747. {
  9748. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9749. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9750. {
  9751. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9752. }
  9753. }
  9754. else
  9755. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9756. }
  9757. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9758. }
  9759. else
  9760. {
  9761. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9762. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9763. }
  9764. json_object_put(data);
  9765. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9766. json_object_put(response);
  9767. }
  9768. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9769. {
  9770. json_object *data;
  9771. data = json_tokener_parse(tempdata);
  9772. if(!is_error(data))
  9773. {
  9774. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9775. if(json_object_object_get(data, "ConnectorId") != NULL)
  9776. {
  9777. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9778. }
  9779. if(json_object_object_get(data, "SerialNo") != NULL)
  9780. {
  9781. sprintf((char *)ShmOCPP16Data->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9782. }
  9783. if(json_object_object_get(data, "Page_Index") != NULL)
  9784. {
  9785. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9786. }
  9787. if(json_object_object_get(data, "Duration") != NULL)
  9788. {
  9789. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9790. }
  9791. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9792. }
  9793. else
  9794. {
  9795. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9796. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9797. }
  9798. json_object_put(data);
  9799. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9800. json_object_put(response);
  9801. }
  9802. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9803. {
  9804. json_object *data;
  9805. data = json_tokener_parse(tempdata);
  9806. if(!is_error(data))
  9807. {
  9808. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9809. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9810. {
  9811. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9812. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9813. else
  9814. {
  9815. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9816. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9817. }
  9818. }
  9819. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9820. {
  9821. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9822. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9823. else
  9824. {
  9825. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9826. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9827. }
  9828. }
  9829. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9830. {
  9831. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9832. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9833. else
  9834. {
  9835. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9836. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9837. }
  9838. }
  9839. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9840. {
  9841. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9842. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9843. else
  9844. {
  9845. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9846. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9847. }
  9848. }
  9849. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9850. {
  9851. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9852. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9853. else
  9854. {
  9855. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9856. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9857. }
  9858. }
  9859. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9860. {
  9861. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9862. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9863. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9864. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9865. else
  9866. {
  9867. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9868. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9869. }
  9870. }
  9871. if(json_object_object_get(data, "isAuthentication") != NULL)
  9872. {
  9873. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9874. {
  9875. case 0:
  9876. case 1:
  9877. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9878. break;
  9879. default:
  9880. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9881. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9882. break;
  9883. }
  9884. }
  9885. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9886. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9887. }
  9888. else
  9889. {
  9890. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9891. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9892. }
  9893. json_object_put(data);
  9894. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9895. json_object_put(response);
  9896. }
  9897. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  9898. {
  9899. json_object *data;
  9900. data = json_tokener_parse(tempdata);
  9901. if(!is_error(data))
  9902. {
  9903. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9904. {
  9905. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  9906. {
  9907. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9908. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9909. }
  9910. else
  9911. {
  9912. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9913. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  9914. }
  9915. }
  9916. else
  9917. {
  9918. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9919. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9920. }
  9921. }
  9922. else
  9923. {
  9924. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9925. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9926. }
  9927. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9928. json_object_put(response);
  9929. }
  9930. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9931. {
  9932. json_object *data;
  9933. data = json_tokener_parse(tempdata);
  9934. if(!is_error(data))
  9935. {
  9936. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9937. if(json_object_object_get(data, "stationName") != NULL)
  9938. {
  9939. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9940. }
  9941. else
  9942. {
  9943. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9944. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9945. }
  9946. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9947. {
  9948. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  9949. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9950. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  9951. }
  9952. }
  9953. else
  9954. {
  9955. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9956. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9957. }
  9958. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9959. json_object_put(response);
  9960. }
  9961. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9962. {
  9963. json_object *data;
  9964. data = json_tokener_parse(tempdata);
  9965. if(!is_error(data))
  9966. {
  9967. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9968. if(json_object_object_get(data, "weatherId") != NULL)
  9969. {
  9970. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9971. }
  9972. else
  9973. {
  9974. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9975. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9976. }
  9977. if(json_object_object_get(data, "Temperature") != NULL)
  9978. {
  9979. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9980. }
  9981. else
  9982. {
  9983. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9984. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9985. }
  9986. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9987. {
  9988. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  9989. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9990. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  9991. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  9992. );
  9993. }
  9994. }
  9995. else
  9996. {
  9997. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9998. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9999. }
  10000. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10001. json_object_put(response);
  10002. }
  10003. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  10004. {
  10005. json_object *data;
  10006. data = json_tokener_parse(tempdata);
  10007. if(!is_error(data))
  10008. {
  10009. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10010. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  10011. {
  10012. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  10013. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  10014. }
  10015. else
  10016. {
  10017. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10018. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  10019. }
  10020. }
  10021. else
  10022. {
  10023. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10024. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10025. }
  10026. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10027. json_object_put(response);
  10028. }
  10029. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  10030. {
  10031. json_object *data;
  10032. data = json_tokener_parse(tempdata);
  10033. if(!is_error(data))
  10034. {
  10035. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10036. {
  10037. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10038. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10039. if(gun_index < gunTotalNumber)
  10040. {
  10041. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10042. {
  10043. json_object *responsedata = json_object_new_object();
  10044. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  10045. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  10046. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  10047. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  10048. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  10049. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10050. }
  10051. else
  10052. {
  10053. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10054. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  10055. }
  10056. }
  10057. else
  10058. {
  10059. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10060. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  10061. }
  10062. }
  10063. else
  10064. {
  10065. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10066. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10067. }
  10068. }
  10069. else
  10070. {
  10071. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10072. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10073. }
  10074. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10075. json_object_put(response);
  10076. }
  10077. else
  10078. {
  10079. // Can not find valid message id
  10080. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  10081. }
  10082. }
  10083. else
  10084. {
  10085. // Payload is null
  10086. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  10087. }
  10088. LWS_Send(message);
  10089. return result;
  10090. }
  10091. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  10092. {
  10093. mtrace();
  10094. int result = FAIL;
  10095. int connectorIdInt, durationInt;
  10096. char chargingRateUnitStr[4]={0};
  10097. char comfirmstr[20];
  10098. int confirmPeriods = 0;
  10099. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  10100. json_object *GetCompositeSchedule;
  10101. GetCompositeSchedule = json_tokener_parse(payload);
  10102. if(!is_error(GetCompositeSchedule))
  10103. {
  10104. // Required data
  10105. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  10106. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  10107. else
  10108. connectorIdInt = -1;
  10109. if(json_object_object_get(GetCompositeSchedule, "duration"))
  10110. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  10111. else
  10112. durationInt = 86400;
  10113. // Optional data
  10114. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  10115. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  10116. }
  10117. json_object_put(GetCompositeSchedule);
  10118. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  10119. if((connectorIdInt == 0) ||
  10120. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  10121. {
  10122. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  10123. struct StructChargingProfile tmpProfile[1];
  10124. if(strstr(chargingRateUnitStr, "W") != NULL)
  10125. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  10126. else
  10127. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  10128. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10129. {
  10130. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10131. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10132. }
  10133. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  10134. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  10135. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  10136. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10137. {
  10138. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10139. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10140. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  10141. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  10142. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  10143. {
  10144. confirmPeriods = idx;
  10145. break;
  10146. }
  10147. }
  10148. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  10149. {
  10150. confirmPeriods += 1;
  10151. }
  10152. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  10153. }
  10154. else
  10155. {
  10156. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  10157. }
  10158. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  10159. return result;
  10160. }
  10161. int handleGetConfigurationRequest(char *uuid, char *payload)
  10162. {
  10163. mtrace();
  10164. int result = FAIL;
  10165. int MaxKeySupported = 0;
  10166. int n_keys = 0;
  10167. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  10168. DEBUG_INFO("handleGetConfigurationRequest...\n");
  10169. json_object *GetConfiguration;
  10170. GetConfiguration = json_tokener_parse(payload);
  10171. if(!is_error(GetConfiguration))
  10172. {
  10173. // Optional data
  10174. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10175. {
  10176. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10177. {
  10178. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10179. n_keys = idx + 1;
  10180. }
  10181. }
  10182. }
  10183. json_object_put(GetConfiguration);
  10184. UnknownKeynum = 0;
  10185. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10186. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10187. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10188. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10189. if(n_keys != 0)
  10190. {
  10191. for(int i=0;i<n_keys;i++)
  10192. {
  10193. getKeyValue(requestKey[i]);
  10194. }
  10195. }
  10196. else
  10197. {
  10198. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10199. getKeyValue("");
  10200. }
  10201. processUnkownKey();
  10202. sendGetConfigurationConfirmation(uuid);
  10203. return result;
  10204. }
  10205. static char fnamePlusPath[100]={0};
  10206. static char fnamePWithNoPath[60]={0};
  10207. void checkUploadLog(void)
  10208. {
  10209. FILE *fp;
  10210. /* Open the command for reading. */
  10211. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10212. if (fp == NULL) {
  10213. DEBUG_WARN("Failed to run command\n" );
  10214. exit(1);
  10215. }
  10216. int ftppathlen = 0;
  10217. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10218. int i = 0;
  10219. /* Read the output a line at a time - output it. */
  10220. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10221. if(i==0)
  10222. {
  10223. ftppathlen = strlen(fnamePlusPath);
  10224. DEBUG_INFO("%s\n", fnamePlusPath);
  10225. fnamePlusPath[ftppathlen]='\0';
  10226. break;
  10227. }
  10228. i= i+1;
  10229. }
  10230. /* close */
  10231. pclose(fp);
  10232. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10233. {
  10234. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10235. {
  10236. fnamePlusPath[k]='\0';
  10237. }
  10238. }
  10239. i=1;
  10240. //char fname[60]={0};
  10241. while(i < ftppathlen)
  10242. {
  10243. int len=ftppathlen-i;
  10244. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10245. {
  10246. DEBUG_INFO("compare '/' all right\n");
  10247. break;
  10248. }
  10249. i=i+1;
  10250. }
  10251. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  10252. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  10253. fnamePWithNoPath[i+1] = '\0';
  10254. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  10255. {
  10256. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  10257. {
  10258. fnamePWithNoPath[j]='\0';
  10259. }
  10260. }
  10261. FILE* fp1 = fopen(fnamePlusPath, "r");
  10262. if (fp1)
  10263. {
  10264. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  10265. // file exists
  10266. fclose(fp1);
  10267. }
  10268. else
  10269. {
  10270. // file doesn't exist
  10271. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  10272. }
  10273. }
  10274. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  10275. {
  10276. mtrace();
  10277. int result = FAIL;
  10278. time_t CurrentTime;
  10279. struct tm *tm;
  10280. pthread_t th_Status;
  10281. CurrentTime = time(NULL);
  10282. tm = localtime(&CurrentTime);
  10283. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  10284. 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);
  10285. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10286. if(!interLock.isGetDiagnosticGoing)
  10287. {
  10288. interLock.isGetDiagnosticGoing = 1;
  10289. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  10290. sleep(1);
  10291. }
  10292. else
  10293. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  10294. return result;
  10295. }
  10296. void* GetDiagnosticsProcess(void* data)
  10297. {
  10298. pthread_detach(pthread_self());
  10299. mtrace();
  10300. int retriesInt=0, retryIntervalInt=0;
  10301. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  10302. 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};
  10303. int port=0;
  10304. int isSuccess = FALSE;
  10305. char cmdBuf[2048];
  10306. struct tm *tmNow;
  10307. time_t CurrentTime;
  10308. struct tm tmStart;
  10309. struct tm tmStop;
  10310. CurrentTime = time(NULL);
  10311. tmNow=localtime(&CurrentTime);
  10312. uint16_t targetYear, targetMonth;
  10313. json_object *GetDiagnostics;
  10314. DEBUG_INFO("GetDiagnosticsProcess...\n");
  10315. GetDiagnostics = json_tokener_parse(data);
  10316. if(!is_error(GetDiagnostics))
  10317. {
  10318. // Required data
  10319. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  10320. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  10321. // Optional data
  10322. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  10323. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  10324. else
  10325. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  10326. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  10327. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  10328. else
  10329. retryIntervalInt = 30;
  10330. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  10331. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  10332. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  10333. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  10334. }
  10335. json_object_put(GetDiagnostics);
  10336. // Pack log to compress file
  10337. 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) &&
  10338. (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))
  10339. {
  10340. // Pack system log
  10341. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10342. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10343. targetYear = tmStart.tm_year;
  10344. targetMonth = tmStart.tm_mon;
  10345. do
  10346. {
  10347. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10348. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  10349. if(targetMonth+1>=13)
  10350. {
  10351. targetYear += 1;
  10352. targetMonth = 1;
  10353. }
  10354. else
  10355. {
  10356. targetMonth += 1;
  10357. }
  10358. }while((targetYear < (tmNow->tm_year+1900)) ||
  10359. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10360. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  10361. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  10362. system(cmdBuf);
  10363. // Pack charging & event log
  10364. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10365. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  10366. targetYear = tmStart.tm_year;
  10367. targetMonth = tmStart.tm_mon;
  10368. do
  10369. {
  10370. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10371. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  10372. if(targetMonth+1>=13)
  10373. {
  10374. targetYear += 1;
  10375. targetMonth = 1;
  10376. }
  10377. else
  10378. {
  10379. targetMonth += 1;
  10380. }
  10381. }while((targetYear < (tmNow->tm_year+1900)) ||
  10382. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10383. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10384. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10385. system(cmdBuf);
  10386. // Combine log file
  10387. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10388. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10389. }
  10390. else
  10391. {
  10392. system("exec /root/logPackTools 'log' 6");
  10393. }
  10394. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10395. system(cmdBuf);
  10396. checkUploadLog();
  10397. //****************location*******************/
  10398. if(strcmp(locationstr,"")==0)
  10399. {
  10400. DEBUG_INFO("location is <Empty>!\n");
  10401. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10402. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10403. goto end;
  10404. }
  10405. memset(protocol, 0, ARRAY_SIZE(protocol));
  10406. memset(user, 0, ARRAY_SIZE(user) );
  10407. memset(password, 0, ARRAY_SIZE(password));
  10408. memset(host, 0, ARRAY_SIZE(host));
  10409. memset(path, 0, ARRAY_SIZE(path));
  10410. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10411. memset(host1, 0, ARRAY_SIZE(host1));
  10412. memset(path1, 0, ARRAY_SIZE(path1));
  10413. /*location: ftp://user:password@host:port/path*/
  10414. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10415. if((access(fnamePlusPath,F_OK))!=-1)
  10416. {
  10417. DEBUG_INFO("fnamePlusPath exist.\n");
  10418. }
  10419. else
  10420. {
  10421. DEBUG_INFO("fnamePlusPath not exist!\n");
  10422. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10423. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10424. goto end;
  10425. }
  10426. if(strchr(locationstr,'@')==NULL)
  10427. {
  10428. sscanf(locationstr,
  10429. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10430. protocol, host, &port, path);
  10431. strcpy(user,"anonymous");
  10432. strcpy(password,"");
  10433. }
  10434. else
  10435. {
  10436. //DEBUG_INFO("pch=%s\n", pch);
  10437. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10438. protocol, user, password, host, &port, path);
  10439. }
  10440. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10441. {
  10442. DEBUG_INFO("protocol is not ftp/http ! \n");
  10443. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10444. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10445. goto end;
  10446. }
  10447. if(strncmp(locationstr,"http", 4) == 0)
  10448. {
  10449. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10450. sprintf(ftppath,"/%s", path);
  10451. do
  10452. {
  10453. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10454. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10455. sleep(3);
  10456. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10457. if(!isSuccess)
  10458. {
  10459. DEBUG_INFO("Diagnostics fail.\n");
  10460. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10461. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10462. sleep(retryIntervalInt);
  10463. }
  10464. else
  10465. {
  10466. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10467. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10468. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10469. }
  10470. retriesInt--;
  10471. }while((isSuccess == 0)&&(retriesInt >= 0));
  10472. }
  10473. else
  10474. {
  10475. sscanf(host,"%[^/]%s",host1, path1);
  10476. if(strlen(path) > 0)
  10477. sprintf(ftppath,"/%s", path);
  10478. else
  10479. sprintf(ftppath,"/%s", path1);
  10480. int ftppathlen=strlen(ftppath);
  10481. int i=1;
  10482. char filenametemp[50];
  10483. while(i < ftppathlen)
  10484. {
  10485. int len=ftppathlen-i;
  10486. if(ftppath[len]== 47) // '/' ascll code: 47
  10487. {
  10488. DEBUG_INFO("find '/' all right\n");
  10489. break;
  10490. }
  10491. i=i+1;
  10492. }
  10493. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10494. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10495. filenametemp[i+1] = 0;
  10496. if(port == 0)
  10497. port = 21;
  10498. do
  10499. {
  10500. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10501. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10502. sleep(3);
  10503. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10504. if(!isSuccess)
  10505. {
  10506. DEBUG_INFO("Diagnostics fail.\n");
  10507. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10508. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10509. sleep(retryIntervalInt);
  10510. }
  10511. else
  10512. {
  10513. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10514. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10515. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10516. }
  10517. retriesInt--;
  10518. }while((!isSuccess)&&(retriesInt >= 0));
  10519. }
  10520. end:
  10521. system("rm -f /mnt/*");
  10522. sleep(5);
  10523. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10524. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10525. interLock.isGetDiagnosticGoing = 0;
  10526. pthread_exit(NULL);
  10527. }
  10528. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10529. {
  10530. mtrace();
  10531. int result = FAIL;
  10532. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10533. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10534. {
  10535. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10536. locallistVersion = -1;
  10537. }
  10538. else
  10539. {
  10540. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10541. OCPP_getListVerion();
  10542. }
  10543. //from db.OCPP_getListVerion
  10544. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10545. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  10546. sendGetLocalListVersionConfirmation(uuid,"");
  10547. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  10548. return result;
  10549. }
  10550. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10551. {
  10552. mtrace();
  10553. int result = FAIL;
  10554. int connectorIdInt=-1;
  10555. int tempIndex = 0;
  10556. int connectorIdIsNULL, chargingProfileIsNULL;
  10557. char comfirmstr[20]={0};
  10558. char cmdBuf[512];
  10559. json_object *RemoteStartTransaction;
  10560. FILE *fp;
  10561. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10562. if(server_pending == TRUE)
  10563. {
  10564. return 0;
  10565. }
  10566. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10567. RemoteStartTransaction = json_tokener_parse(payload);
  10568. if(!is_error(RemoteStartTransaction))
  10569. {
  10570. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10571. {
  10572. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10573. }
  10574. else
  10575. {
  10576. connectorIdIsNULL = TRUE;
  10577. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10578. {
  10579. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10580. {
  10581. connectorIdIsNULL = FALSE;
  10582. connectorIdInt = (gun_index+1);
  10583. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10584. break;
  10585. }
  10586. }
  10587. }
  10588. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10589. {
  10590. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10591. // Required data
  10592. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10593. // Optional data
  10594. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10595. {
  10596. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10597. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10598. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10599. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10600. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10601. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10602. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10603. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10604. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10605. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10606. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10607. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10608. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10609. {
  10610. 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")));
  10611. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10612. 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"));
  10613. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10614. 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"));
  10615. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10616. 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")));
  10617. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10618. {
  10619. 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++)
  10620. {
  10621. 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"));
  10622. 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"));
  10623. 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)
  10624. 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"));
  10625. }
  10626. }
  10627. }
  10628. }
  10629. else
  10630. {
  10631. chargingProfileIsNULL = TRUE;
  10632. }
  10633. }
  10634. }
  10635. else
  10636. {
  10637. connectorIdIsNULL = TRUE;
  10638. }
  10639. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10640. {
  10641. DEBUG_WARN("Connector id is NULL\n.");
  10642. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10643. goto end;
  10644. }
  10645. /*
  10646. enum _SYSTEM_STATUS
  10647. {
  10648. S_BOOTING = 0,
  10649. S_IDLE, = 1
  10650. S_AUTHORIZING, = 2
  10651. S_REASSIGN_CHECK, = 3
  10652. S_REASSIGN, = 4
  10653. S_PRECHARGE, = 5
  10654. S_PREPARING_FOR_EV, = 6
  10655. S_PREPARING_FOR_EVSE, = 7
  10656. S_CHARGING, = 8
  10657. S_TERMINATING, = 9
  10658. S_COMPLETE, = 10
  10659. S_ALARM, = 11
  10660. S_FAULT = 12
  10661. }
  10662. */
  10663. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10664. {
  10665. //check Transaction active
  10666. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10667. {
  10668. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10669. {
  10670. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10671. }
  10672. else
  10673. {
  10674. tempIndex = connectorIdInt -1;
  10675. }
  10676. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10677. {
  10678. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10679. {
  10680. 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))
  10681. {
  10682. //Reserved
  10683. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10684. }
  10685. 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))
  10686. {
  10687. //Reserved
  10688. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10689. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10690. goto end;
  10691. }
  10692. else
  10693. {
  10694. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10695. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10696. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10697. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10698. {
  10699. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10700. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10701. goto end;
  10702. }
  10703. }//END FOR ELSE
  10704. }
  10705. }// END FOR CHAdeMO_QUANTITY
  10706. }
  10707. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10708. {
  10709. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10710. {
  10711. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10712. }
  10713. else
  10714. {
  10715. tempIndex = connectorIdInt -1;
  10716. }
  10717. for (int index = 0; index < CCS_QUANTITY; index++)
  10718. {
  10719. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10720. {
  10721. 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))
  10722. {
  10723. //Reserved
  10724. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10725. }
  10726. 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))
  10727. {
  10728. //Reserved
  10729. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10730. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10731. goto end;
  10732. }
  10733. else
  10734. {
  10735. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10736. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10737. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10738. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10739. {
  10740. DEBUG_WARN("CCS connector not allow start\n.");
  10741. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10742. goto end;
  10743. }
  10744. }// END FOR ELSE
  10745. }
  10746. }// END FOR CCS_QUANTITY
  10747. }
  10748. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10749. {
  10750. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10751. {
  10752. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10753. }
  10754. else
  10755. {
  10756. tempIndex = connectorIdInt -1;
  10757. }
  10758. for (int index = 0; index < GB_QUANTITY; index++)
  10759. {
  10760. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10761. {
  10762. 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))
  10763. {
  10764. //Reserved
  10765. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10766. }
  10767. 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))
  10768. {
  10769. //Reserved
  10770. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10771. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10772. goto end;
  10773. }
  10774. else
  10775. {
  10776. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10777. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10778. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10779. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10780. {
  10781. DEBUG_WARN("GB connector not allow start\n.");
  10782. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10783. goto end;
  10784. }
  10785. }// END FOR ELSE
  10786. }
  10787. } // END FOR GB_QUANTITY
  10788. }
  10789. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10790. {
  10791. tempIndex = connectorIdInt -1;
  10792. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10793. {
  10794. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10795. {
  10796. 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))
  10797. {
  10798. //Reserved
  10799. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10800. }
  10801. 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))
  10802. {
  10803. //Reserved
  10804. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10805. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10806. goto end;
  10807. }
  10808. else
  10809. {
  10810. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10811. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10812. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10813. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10814. {
  10815. DEBUG_WARN("GB connector not allow start\n.");
  10816. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10817. goto end;
  10818. }
  10819. }// END FOR ELSE
  10820. }
  10821. } // END FOR GB_QUANTITY
  10822. }
  10823. else
  10824. {
  10825. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10826. {
  10827. tempIndex = 2;
  10828. }
  10829. else
  10830. {
  10831. tempIndex = connectorIdInt -1;
  10832. }
  10833. for (int index = 0; index < AC_QUANTITY; index++)
  10834. {
  10835. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10836. {
  10837. 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))
  10838. {
  10839. //Reserved
  10840. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10841. }
  10842. 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))
  10843. {
  10844. //Reserved
  10845. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10846. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10847. goto end;
  10848. }
  10849. else
  10850. {
  10851. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10852. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10853. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10854. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10855. {
  10856. DEBUG_WARN("AC connector not allow start\n.");
  10857. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10858. goto end;
  10859. }
  10860. }//END FOR ELSE
  10861. }
  10862. }// END FOR AC_QUANTITY
  10863. }
  10864. if(chargingProfileIsNULL == FALSE)
  10865. {
  10866. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10867. {
  10868. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10869. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10870. //memset idTag
  10871. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10872. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10873. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10874. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10875. // Save profile to file
  10876. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10877. system(cmdBuf);
  10878. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10879. fp = fopen(cmdBuf, "w");
  10880. 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));
  10881. fclose(fp);
  10882. }
  10883. else
  10884. {
  10885. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10886. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10887. }
  10888. }
  10889. else
  10890. {
  10891. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10892. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10893. //memset idTag
  10894. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10895. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10896. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10897. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10898. }
  10899. }
  10900. else
  10901. {
  10902. DEBUG_WARN("Connector id over\n.");
  10903. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10904. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10905. }
  10906. end:
  10907. json_object_put(RemoteStartTransaction);
  10908. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10909. {
  10910. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10911. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10912. }
  10913. //OCPP send RemoteStartConfirmation by first.
  10914. sendRemoteStartConfirmation(uuid, comfirmstr);
  10915. return result;
  10916. }
  10917. int handleRemoteStartRequest(char *uuid, char *payload)
  10918. {
  10919. mtrace();
  10920. int result = PASS;
  10921. int connectorIdInt=-1;
  10922. int tempIndex = 0;
  10923. char comfirmstr[20]={0};
  10924. char cmdBuf[512];
  10925. json_object *RemoteStartTransaction;
  10926. FILE *fp;
  10927. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10928. if(server_pending == TRUE)
  10929. {
  10930. result = FAIL;
  10931. }
  10932. RemoteStartTransaction = json_tokener_parse(payload);
  10933. if(!is_error(RemoteStartTransaction))
  10934. {
  10935. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10936. {
  10937. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10938. }
  10939. else
  10940. {
  10941. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10942. {
  10943. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10944. {
  10945. connectorIdInt = (gun_index+1);
  10946. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10947. break;
  10948. }
  10949. }
  10950. }
  10951. if(connectorIdInt == 0)
  10952. {
  10953. DEBUG_WARN("Connector id shall not equal 0.\n");
  10954. result = FAIL;
  10955. }
  10956. else if(connectorIdInt == -1)
  10957. {
  10958. DEBUG_INFO("Connector id does not specific.\n");
  10959. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10960. {
  10961. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10962. // Required data
  10963. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10964. // Optional data
  10965. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10966. {
  10967. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10968. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10969. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10970. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10971. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10972. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10973. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10974. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10975. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10976. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10977. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10978. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10979. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10980. {
  10981. 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")));
  10982. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10983. 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"));
  10984. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10985. 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"));
  10986. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10987. 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")));
  10988. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10989. {
  10990. 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++)
  10991. {
  10992. 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"));
  10993. 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"));
  10994. 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)
  10995. 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"));
  10996. }
  10997. }
  10998. }
  10999. }
  11000. else
  11001. {
  11002. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  11003. }
  11004. }
  11005. }
  11006. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  11007. {
  11008. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  11009. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  11010. // Required data
  11011. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11012. // Optional data
  11013. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11014. {
  11015. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11016. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11017. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11018. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11019. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11020. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11021. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11022. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11023. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11024. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11025. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11026. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11027. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11028. {
  11029. 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")));
  11030. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11031. 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"));
  11032. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11033. 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"));
  11034. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11035. 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")));
  11036. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11037. {
  11038. 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++)
  11039. {
  11040. 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"));
  11041. 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"));
  11042. 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)
  11043. 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"));
  11044. }
  11045. }
  11046. }
  11047. }
  11048. else
  11049. {
  11050. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  11051. }
  11052. }
  11053. else
  11054. {
  11055. DEBUG_WARN("Connector id is over maximun value.\n");
  11056. result = FAIL;
  11057. }
  11058. }
  11059. if(result == PASS)
  11060. {
  11061. if(connectorIdInt > 0)
  11062. {
  11063. //check Transaction active
  11064. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11065. {
  11066. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11067. {
  11068. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11069. }
  11070. else
  11071. {
  11072. tempIndex = connectorIdInt -1;
  11073. }
  11074. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11075. {
  11076. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11077. {
  11078. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11079. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11080. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11081. {
  11082. //Reserved
  11083. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  11084. }
  11085. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11086. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11087. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11088. {
  11089. //Reserved
  11090. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  11091. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11092. goto end;
  11093. }
  11094. else
  11095. {
  11096. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11097. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  11098. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  11099. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  11100. {
  11101. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  11102. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11103. goto end;
  11104. }
  11105. }//END FOR ELSE
  11106. }
  11107. }// END FOR CHAdeMO_QUANTITY
  11108. }
  11109. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11110. {
  11111. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11112. {
  11113. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11114. }
  11115. else
  11116. {
  11117. tempIndex = connectorIdInt -1;
  11118. }
  11119. for (int index = 0; index < CCS_QUANTITY; index++)
  11120. {
  11121. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11122. {
  11123. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11124. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11125. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11126. {
  11127. //Reserved
  11128. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  11129. }
  11130. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11131. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11132. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11133. {
  11134. //Reserved
  11135. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  11136. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11137. goto end;
  11138. }
  11139. else
  11140. {
  11141. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11142. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11143. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11144. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11145. {
  11146. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11147. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11148. goto end;
  11149. }
  11150. }// END FOR ELSE
  11151. }
  11152. }// END FOR CCS_QUANTITY
  11153. }
  11154. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11155. {
  11156. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11157. {
  11158. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11159. }
  11160. else
  11161. {
  11162. tempIndex = connectorIdInt -1;
  11163. }
  11164. for (int index = 0; index < GB_QUANTITY; index++)
  11165. {
  11166. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11167. {
  11168. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11169. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11170. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11171. {
  11172. //Reserved
  11173. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11174. }
  11175. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11176. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11177. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11178. {
  11179. //Reserved
  11180. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11181. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11182. goto end;
  11183. }
  11184. else
  11185. {
  11186. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11187. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11188. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11189. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11190. {
  11191. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11192. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11193. goto end;
  11194. }
  11195. }// END FOR ELSE
  11196. }
  11197. } // END FOR GB_QUANTITY
  11198. }
  11199. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11200. {
  11201. tempIndex = connectorIdInt -1;
  11202. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11203. {
  11204. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11205. {
  11206. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11207. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11208. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11209. {
  11210. //Reserved
  11211. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11212. }
  11213. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11214. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11215. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11216. {
  11217. //Reserved
  11218. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11219. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11220. goto end;
  11221. }
  11222. else
  11223. {
  11224. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11225. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11226. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11227. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11228. {
  11229. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11230. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11231. goto end;
  11232. }
  11233. }// END FOR ELSE
  11234. }
  11235. } // END FOR GB_QUANTITY
  11236. }
  11237. else
  11238. {
  11239. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11240. {
  11241. tempIndex = 2;
  11242. }
  11243. else
  11244. {
  11245. tempIndex = connectorIdInt -1;
  11246. }
  11247. for (int index = 0; index < AC_QUANTITY; index++)
  11248. {
  11249. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11250. {
  11251. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11252. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11253. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11254. {
  11255. //Reserved
  11256. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11257. }
  11258. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11259. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11260. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11261. {
  11262. //Reserved
  11263. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11264. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11265. goto end;
  11266. }
  11267. else
  11268. {
  11269. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11270. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11271. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11272. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11273. {
  11274. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11275. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11276. goto end;
  11277. }
  11278. }//END FOR ELSE
  11279. }
  11280. }// END FOR AC_QUANTITY
  11281. }
  11282. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11283. {
  11284. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11285. {
  11286. // Save profile to file
  11287. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11288. system(cmdBuf);
  11289. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11290. fp = fopen(cmdBuf, "w");
  11291. 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));
  11292. fclose(fp);
  11293. }
  11294. else
  11295. {
  11296. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11297. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11298. goto end;
  11299. }
  11300. }
  11301. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11302. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11303. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11304. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11305. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11306. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11307. }
  11308. else
  11309. {
  11310. uint8_t isHasIdleConnector = FALSE;
  11311. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11312. {
  11313. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11314. {
  11315. isHasIdleConnector = TRUE;
  11316. break;
  11317. }
  11318. }
  11319. if(isHasIdleConnector == TRUE)
  11320. {
  11321. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11322. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11323. {
  11324. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11325. {
  11326. // Save profile to file
  11327. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11328. system(cmdBuf);
  11329. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11330. fp = fopen(cmdBuf, "w");
  11331. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11332. fclose(fp);
  11333. refreshStartTimer(&clientTime.RemoteStartWait);
  11334. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11335. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11336. }
  11337. else
  11338. {
  11339. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11340. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11341. }
  11342. }
  11343. else
  11344. {
  11345. refreshStartTimer(&clientTime.RemoteStartWait);
  11346. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11347. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11348. }
  11349. }
  11350. else
  11351. {
  11352. DEBUG_INFO("There is not any connector is idle.\n");
  11353. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11354. }
  11355. }
  11356. }
  11357. else
  11358. {
  11359. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11360. }
  11361. end:
  11362. json_object_put(RemoteStartTransaction);
  11363. sendRemoteStartConfirmation(uuid, comfirmstr);
  11364. return result;
  11365. }
  11366. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11367. {
  11368. mtrace();
  11369. int result = FAIL;
  11370. int match = FALSE;
  11371. int GunNO = 0;
  11372. int tempIndex = 0;
  11373. int transactionIdInt=0;
  11374. int transactionIdIsNULL= TRUE;
  11375. char comfirmstr[20];
  11376. json_object *RemoteStopTransaction;
  11377. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11378. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11379. if(server_pending == TRUE)
  11380. {
  11381. return 0;
  11382. }
  11383. RemoteStopTransaction = json_tokener_parse(payload);
  11384. if(!is_error(RemoteStopTransaction))
  11385. {
  11386. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11387. {
  11388. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11389. transactionIdIsNULL = FALSE;
  11390. }
  11391. }
  11392. json_object_put(RemoteStopTransaction);
  11393. if(transactionIdIsNULL == FALSE)
  11394. {
  11395. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11396. {
  11397. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11398. {
  11399. //check Transaction active
  11400. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11401. {
  11402. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11403. {
  11404. tempIndex = ((gun_index==2) ? 1: 0);
  11405. }
  11406. else
  11407. {
  11408. tempIndex = gun_index;
  11409. }
  11410. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11411. {
  11412. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11413. {
  11414. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11415. {
  11416. match = TRUE;
  11417. GunNO = gun_index;
  11418. }
  11419. }
  11420. }// END FOR CHAdeMO_QUANTITY
  11421. }
  11422. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11423. {
  11424. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11425. {
  11426. tempIndex = ((gun_index==2) ? 1: 0);
  11427. }
  11428. else
  11429. {
  11430. tempIndex = gun_index;
  11431. }
  11432. for (int index = 0; index < CCS_QUANTITY; index++)
  11433. {
  11434. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11435. {
  11436. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11437. {
  11438. match = TRUE;
  11439. GunNO = gun_index;
  11440. }
  11441. }
  11442. }// END FOR CCS_QUANTITY
  11443. }
  11444. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11445. {
  11446. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11447. {
  11448. tempIndex = ((gun_index==2) ? 1: 0);
  11449. }
  11450. else
  11451. {
  11452. tempIndex = gun_index;
  11453. }
  11454. for (int index = 0; index < GB_QUANTITY; index++)
  11455. {
  11456. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11457. {
  11458. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11459. {
  11460. match = TRUE;
  11461. GunNO = gun_index;
  11462. }
  11463. }
  11464. }// END FOR GB_QUANTITY
  11465. }
  11466. else if(gunType[gun_index] == GUN_TYPE_DO)
  11467. {
  11468. tempIndex = gun_index;
  11469. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11470. {
  11471. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11472. {
  11473. 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
  11474. {
  11475. match = TRUE;
  11476. GunNO = gun_index;
  11477. }
  11478. }
  11479. }// END FOR GB_QUANTITY
  11480. }
  11481. else
  11482. {
  11483. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11484. {
  11485. tempIndex = 2;
  11486. }
  11487. else
  11488. {
  11489. tempIndex = gun_index;
  11490. }
  11491. for (int index = 0; index < AC_QUANTITY; index++)
  11492. {
  11493. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11494. {
  11495. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11496. {
  11497. match = TRUE;
  11498. GunNO = gun_index;
  11499. }
  11500. }
  11501. }// END FOR CHAdeMO_QUANTITY
  11502. } // END FOR AC ELSE
  11503. }// CHECK IF ResponseTransactionId == transactionIdInt
  11504. }//END FOR
  11505. if( match == TRUE)
  11506. {
  11507. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11508. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11509. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11510. }
  11511. else
  11512. {
  11513. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11514. }
  11515. }
  11516. else
  11517. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11518. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11519. return result;
  11520. }
  11521. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11522. {
  11523. mtrace();
  11524. int result = FAIL;
  11525. int connectorIdInt=0, reservationIdInt=0;
  11526. int tempIndex = 0;
  11527. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  11528. char comfirmstr[20]={0};
  11529. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11530. int c = 0;
  11531. char *loc;
  11532. //char *ptr;
  11533. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11534. strcpy(sstrtemp, stringtrimspace(payload));
  11535. //***(1)connectorId ****/
  11536. c=0;
  11537. loc = strstr(sstrtemp, "connectorId");
  11538. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11539. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11540. {
  11541. sstr[c] = loc[strlen("connectorId")+2+c];
  11542. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11543. c++;
  11544. }
  11545. sstr[c] = '\0';
  11546. connectorIdInt = atoi(sstr);
  11547. //***(2)expiryDate ****/
  11548. loc = strstr(sstrtemp, "expiryDate");
  11549. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11550. c = 0;
  11551. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11552. {
  11553. sstr[c] = loc[3+strlen("expiryDate")+c];
  11554. c++;
  11555. }
  11556. sstr[c] = '\0';
  11557. strcpy(expiryDatestr, sstr);
  11558. //***(3)idTag ****/
  11559. loc = strstr(sstrtemp, "idTag");
  11560. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11561. c = 0;
  11562. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11563. {
  11564. sstr[c] = loc[3+strlen("idTag")+c];
  11565. c++;
  11566. }
  11567. sstr[c] = '\0';
  11568. strcpy(idTagstr, sstr);
  11569. //***(4)parentIdTag ****/
  11570. loc = strstr(sstrtemp, "parentIdTag");
  11571. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11572. c = 0;
  11573. if(loc == NULL)
  11574. {
  11575. strcpy(parentIdTagstr, "");
  11576. }
  11577. else
  11578. {
  11579. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11580. {
  11581. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11582. c++;
  11583. }
  11584. sstr[c] = '\0';
  11585. strcpy(parentIdTagstr, sstr);
  11586. }
  11587. //***(5)reservationId ****/
  11588. c=0;
  11589. loc = strstr(sstrtemp, "reservationId");
  11590. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11591. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11592. {
  11593. sstr[c] = loc[strlen("reservationId")+2+c];
  11594. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11595. c++;
  11596. }
  11597. sstr[c] = '\0';
  11598. reservationIdInt = atoi(sstr);
  11599. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11600. /*
  11601. enum SYSTEM_STATUS
  11602. {
  11603. SYS_MODE_BOOTING = 0,
  11604. SYS_MODE_IDLE = 1,
  11605. SYS_MODE_AUTHORIZING = 2,
  11606. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11607. SYS_MODE_REASSIGN = 4,
  11608. SYS_MODE_PREPARING = 5,
  11609. SYS_MODE_PREPARE_FOR_EV = 6,
  11610. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11611. SYS_MODE_CHARGING = 8,
  11612. SYS_MODE_TERMINATING = 9,
  11613. SYS_MODE_COMPLETE = 10,
  11614. SYS_MODE_ALARM = 11,
  11615. SYS_MODE_FAULT = 12,
  11616. SYS_MODE_RESERVATION = 13,
  11617. SYS_MODE_BOOKING = 14,
  11618. SYS_MODE_MAINTAIN = 15,
  11619. SYS_MODE_DEBUG = 16,
  11620. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11621. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11622. SYS_MODE_UPDATE = 19
  11623. };
  11624. */
  11625. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11626. {
  11627. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11628. goto end;
  11629. }
  11630. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11631. {
  11632. //check Transaction active
  11633. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11634. {
  11635. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11636. {
  11637. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11638. }
  11639. else
  11640. {
  11641. tempIndex = connectorIdInt -1;
  11642. }
  11643. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11644. {
  11645. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11646. {
  11647. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11648. {
  11649. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11650. {
  11651. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11652. {
  11653. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11654. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11655. }
  11656. 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'))
  11657. {
  11658. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11659. }
  11660. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11661. {
  11662. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11663. }
  11664. else
  11665. {
  11666. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11667. }
  11668. }
  11669. 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
  11670. {
  11671. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11672. }
  11673. }
  11674. else
  11675. {
  11676. //replace reservation
  11677. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11678. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11679. }
  11680. }
  11681. } // END FOR CHAdeMO_QUANTITY
  11682. }
  11683. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11684. {
  11685. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11686. {
  11687. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11688. }
  11689. else
  11690. {
  11691. tempIndex = connectorIdInt -1;
  11692. }
  11693. for (int index = 0; index < CCS_QUANTITY; index++)
  11694. {
  11695. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11696. {
  11697. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11698. {
  11699. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11700. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11701. {
  11702. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11703. {
  11704. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11705. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11706. }
  11707. 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'))
  11708. {
  11709. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11710. }
  11711. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11712. {
  11713. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11714. }
  11715. else
  11716. {
  11717. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11718. }
  11719. }
  11720. 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
  11721. {
  11722. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11723. }
  11724. }
  11725. else
  11726. {
  11727. //replace reservation
  11728. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11729. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11730. }
  11731. }
  11732. } // END FOR CCS_QUANTITY
  11733. }
  11734. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11735. {
  11736. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11737. {
  11738. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11739. }
  11740. else
  11741. {
  11742. tempIndex = connectorIdInt -1;
  11743. }
  11744. for (int index = 0; index < GB_QUANTITY; index++)
  11745. {
  11746. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11747. {
  11748. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11749. {
  11750. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11751. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11752. {
  11753. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11754. {
  11755. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11756. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11757. }
  11758. 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'))
  11759. {
  11760. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11761. }
  11762. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11763. {
  11764. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11765. }
  11766. else
  11767. {
  11768. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11769. }
  11770. }
  11771. 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
  11772. {
  11773. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11774. }
  11775. }
  11776. else
  11777. {
  11778. //replace reservation
  11779. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11780. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11781. }
  11782. }
  11783. }// END FOR GB_QUANTITY
  11784. }
  11785. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11786. {
  11787. tempIndex = connectorIdInt -1;
  11788. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11789. {
  11790. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11791. {
  11792. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11793. {
  11794. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11795. 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
  11796. {
  11797. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11798. {
  11799. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11800. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11801. }
  11802. 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'))
  11803. {
  11804. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11805. }
  11806. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11807. {
  11808. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11809. }
  11810. else
  11811. {
  11812. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11813. }
  11814. }
  11815. 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
  11816. {
  11817. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11818. }
  11819. }
  11820. else
  11821. {
  11822. //replace reservation
  11823. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11824. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11825. }
  11826. }
  11827. }// END FOR GB_QUANTITY
  11828. }
  11829. else
  11830. {
  11831. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11832. {
  11833. tempIndex = 2;
  11834. }
  11835. else
  11836. {
  11837. tempIndex = (connectorIdInt -1);
  11838. }
  11839. for (int index = 0; index < AC_QUANTITY; index++)
  11840. {
  11841. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11842. {
  11843. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11844. {
  11845. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11846. {
  11847. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11848. {
  11849. 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))
  11850. {
  11851. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11852. }
  11853. else
  11854. {
  11855. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11856. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11857. }
  11858. }
  11859. 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'))
  11860. {
  11861. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11862. }
  11863. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11864. {
  11865. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11866. }
  11867. else
  11868. {
  11869. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11870. }
  11871. }
  11872. 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
  11873. {
  11874. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11875. }
  11876. }
  11877. else
  11878. {
  11879. //replace reservation
  11880. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11881. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11882. }
  11883. }
  11884. } // END FOR AC_QUANTITY
  11885. }
  11886. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11887. }
  11888. else if(connectorIdInt == 0)
  11889. {
  11890. //check Transaction active
  11891. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11892. {
  11893. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11894. {
  11895. 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'))
  11896. {
  11897. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11898. goto end;
  11899. }
  11900. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11901. {
  11902. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11903. goto end;
  11904. }
  11905. 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
  11906. {
  11907. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11908. goto end;
  11909. }
  11910. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11911. {
  11912. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11913. goto end;
  11914. }
  11915. }
  11916. }// END FOR CHAdeMO_QUANTITY
  11917. for (int index = 0; index < CCS_QUANTITY; index++)
  11918. {
  11919. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11920. {
  11921. 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'))
  11922. {
  11923. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11924. goto end;
  11925. }
  11926. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11927. {
  11928. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11929. goto end;
  11930. }
  11931. 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
  11932. {
  11933. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11934. goto end;
  11935. }
  11936. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11937. {
  11938. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11939. goto end;
  11940. }
  11941. }
  11942. } // END FOR CCS_QUANTITY
  11943. for (int index = 0; index < GB_QUANTITY; index++)
  11944. {
  11945. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11946. {
  11947. 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'))
  11948. {
  11949. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11950. goto end;
  11951. }
  11952. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11953. {
  11954. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11955. goto end;
  11956. }
  11957. 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
  11958. {
  11959. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11960. goto end;
  11961. }
  11962. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11963. {
  11964. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11965. goto end;
  11966. }
  11967. }
  11968. } // END FOR GB_QUANTITY
  11969. for (int index = 0; index < AC_QUANTITY; index++)
  11970. {
  11971. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11972. {
  11973. 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'))
  11974. {
  11975. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11976. goto end;
  11977. }
  11978. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11979. {
  11980. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11981. goto end;
  11982. }
  11983. 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
  11984. {
  11985. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11986. goto end;
  11987. }
  11988. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11989. {
  11990. 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))
  11991. {
  11992. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11993. goto end;
  11994. }
  11995. }
  11996. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11997. {
  11998. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11999. goto end;
  12000. }
  12001. }
  12002. }// END FOR AC_QUANTITY
  12003. //The connectorId is 0
  12004. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  12005. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12006. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  12007. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  12008. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  12009. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  12010. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  12011. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  12012. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  12013. result = TRUE;
  12014. return result;
  12015. }
  12016. else
  12017. {
  12018. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12019. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12020. }
  12021. if(strcmp(comfirmstr,"Accepted") == 0)
  12022. {
  12023. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  12024. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  12025. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  12026. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  12027. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  12028. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12029. result = TRUE;
  12030. return result;
  12031. }
  12032. end:
  12033. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  12034. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  12035. return result;
  12036. }
  12037. int handleResetRequest(char *uuid, char *payload)
  12038. {
  12039. mtrace();
  12040. int result = FAIL;
  12041. char sstr[10]={0},sstrtemp[30]={ 0 };
  12042. char typestr[10]={0};
  12043. char comfirmstr[20]={0};
  12044. int c = 0;
  12045. char *loc;
  12046. DEBUG_INFO("handleResetRequest...\n");
  12047. strcpy(sstrtemp, stringtrimspace(payload));
  12048. loc = strstr(sstrtemp, "type");
  12049. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12050. c = 0;
  12051. while (loc[3+strlen("type")+c] != '\"')
  12052. {
  12053. sstr[c] = loc[3+strlen("type")+c];
  12054. c++;
  12055. }
  12056. sstr[c] = '\0';
  12057. strcpy(typestr,sstr);
  12058. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  12059. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  12060. {
  12061. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  12062. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  12063. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  12064. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12065. }
  12066. else
  12067. {
  12068. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  12069. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12070. result = PASS;
  12071. }
  12072. sendResetConfirmation(uuid, comfirmstr);
  12073. return result;
  12074. }
  12075. int handleSendLocalListRequest(char *uuid, char *payload)
  12076. {
  12077. mtrace();
  12078. int result = FAIL;
  12079. char comfirmstr[20];
  12080. int checkState_Faulted = FALSE;
  12081. json_object *SendLocalList;
  12082. DEBUG_INFO("handleSendLocalListRequest...\n");
  12083. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  12084. {
  12085. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12086. goto end;
  12087. }
  12088. //check Charge Point state
  12089. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12090. {
  12091. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12092. {
  12093. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12094. }
  12095. }
  12096. for (int index = 0; index < CCS_QUANTITY; index++)
  12097. {
  12098. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12099. {
  12100. checkState_Faulted = TRUE; //OCPP Status
  12101. }
  12102. }
  12103. for (int index = 0; index < GB_QUANTITY; index++)
  12104. {
  12105. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12106. {
  12107. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12108. }
  12109. }
  12110. //check Charge Point state
  12111. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12112. {
  12113. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12114. {
  12115. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12116. }
  12117. }
  12118. //check Charge Point state
  12119. for (int index = 0; index < AC_QUANTITY; index++)
  12120. {
  12121. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12122. {
  12123. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12124. }
  12125. }
  12126. if(checkState_Faulted == TRUE)
  12127. {
  12128. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12129. goto end;
  12130. }
  12131. // Parsing payload
  12132. SendLocalList = json_tokener_parse(payload);
  12133. if(!is_error(SendLocalList))
  12134. {
  12135. // Required data
  12136. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12137. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12138. // Optional data
  12139. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12140. {
  12141. //Check UpdateType
  12142. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12143. {
  12144. //Local list full update
  12145. DEBUG_INFO("Local list full update.\n");
  12146. OCPP_getListVerion();
  12147. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12148. {
  12149. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12150. goto end;
  12151. }
  12152. OCPP_cleanLocalList();
  12153. }
  12154. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12155. {
  12156. //Local list different update
  12157. DEBUG_INFO("Local list different update.\n");
  12158. OCPP_getListVerion();
  12159. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12160. {
  12161. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12162. goto end;
  12163. }
  12164. }
  12165. else
  12166. {
  12167. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12168. goto end;
  12169. }
  12170. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12171. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12172. {
  12173. 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")));
  12174. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12175. {
  12176. 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")));
  12177. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12178. 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")));
  12179. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12180. 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")));
  12181. }
  12182. // Add to db
  12183. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12184. {
  12185. //Local list full update
  12186. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12187. idx,
  12188. ShmOCPP16Data->SendLocalList.ListVersion,
  12189. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12190. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12191. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12192. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12193. // update list
  12194. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12195. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12196. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12197. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12198. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12199. }
  12200. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12201. {
  12202. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12203. idx,
  12204. ShmOCPP16Data->SendLocalList.ListVersion,
  12205. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12206. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12207. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12208. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12209. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12210. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12211. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12212. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12213. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12214. }
  12215. }
  12216. }
  12217. else
  12218. {
  12219. //Check UpdateType
  12220. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12221. {
  12222. //Local list full update
  12223. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12224. OCPP_cleanLocalList();
  12225. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12226. goto end;
  12227. }
  12228. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12229. {
  12230. //Local list different update
  12231. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12232. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12233. goto end;
  12234. }
  12235. }
  12236. result = PASS;
  12237. }
  12238. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12239. end:
  12240. json_object_put(SendLocalList);
  12241. sendSendLocalListConfirmation(uuid, comfirmstr);
  12242. return result;
  12243. }
  12244. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12245. {
  12246. mtrace();
  12247. int result = FAIL;
  12248. struct StructSetChargingProfile SetProfileReq = {0};
  12249. int tempchargingProfileIdInt;
  12250. int tempstackLevelInt;
  12251. int chargingSchedulePeriodCount = 0;
  12252. char comfirmstr[20]={0};
  12253. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  12254. char rmFileCmd[128]={0};
  12255. int profileQuantity = 0;
  12256. int isReplaceable = FALSE;
  12257. json_object *SetChargingProfile;
  12258. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12259. SetChargingProfile = json_tokener_parse(payload);
  12260. if(!is_error(SetChargingProfile))
  12261. {
  12262. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12263. {
  12264. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12265. }
  12266. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12267. {
  12268. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12269. {
  12270. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12271. }
  12272. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12273. {
  12274. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12275. }
  12276. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12277. {
  12278. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12279. }
  12280. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12281. {
  12282. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12283. }
  12284. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12285. {
  12286. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12287. }
  12288. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12289. {
  12290. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12291. }
  12292. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12293. {
  12294. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12295. }
  12296. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12297. {
  12298. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12299. }
  12300. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12301. {
  12302. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12303. {
  12304. 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")));
  12305. }
  12306. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12307. {
  12308. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12309. }
  12310. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12311. {
  12312. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12313. }
  12314. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12315. {
  12316. 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")));
  12317. }
  12318. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12319. {
  12320. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12321. if(chargingSchedulePeriodCount <= 10)
  12322. {
  12323. 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++)
  12324. {
  12325. 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)
  12326. {
  12327. 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"));
  12328. }
  12329. 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)
  12330. {
  12331. 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"));
  12332. }
  12333. 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)
  12334. {
  12335. 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"));
  12336. }
  12337. }
  12338. }
  12339. }
  12340. }
  12341. }
  12342. }
  12343. // Profile periods quantity check
  12344. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12345. {
  12346. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12347. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12348. goto end;
  12349. }
  12350. // Check invalid limit
  12351. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12352. {
  12353. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12354. {
  12355. 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)))) ||
  12356. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12357. {
  12358. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12359. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12360. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12361. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12362. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12363. goto end;
  12364. }
  12365. }
  12366. }
  12367. else
  12368. {
  12369. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12370. {
  12371. 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))
  12372. {
  12373. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12374. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12375. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12376. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12377. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12378. goto end;
  12379. }
  12380. }
  12381. }
  12382. // Profile purpose info check
  12383. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12384. {
  12385. FILE *fp;
  12386. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12387. if(SetProfileReq.ConnectorId != 0)
  12388. {
  12389. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12390. DEBUG_WARN("Profile connector id is not 0.\n");
  12391. goto end;
  12392. }
  12393. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12394. if (!fp)
  12395. {
  12396. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12397. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12398. }
  12399. else
  12400. {
  12401. char *line = NULL;
  12402. size_t len = 0;
  12403. while(getline(&line, &len, fp) != -1)
  12404. {
  12405. json_object *obj = NULL;
  12406. obj = json_tokener_parse(line);
  12407. if(is_error(obj))
  12408. {
  12409. DEBUG_ERROR("Parse txProfile from file error.\n");
  12410. }
  12411. else
  12412. {
  12413. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12414. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12415. {
  12416. profileQuantity += 1;
  12417. }
  12418. else
  12419. isReplaceable = TRUE;
  12420. }
  12421. }
  12422. }
  12423. fclose(fp);
  12424. }
  12425. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12426. {
  12427. FILE *fp;
  12428. char filename[128]={0};
  12429. int tmpProfileQuantity;
  12430. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12431. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12432. {
  12433. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12434. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12435. goto end;
  12436. }
  12437. if(SetProfileReq.ConnectorId == 0)
  12438. {
  12439. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12440. {
  12441. tmpProfileQuantity = 0;
  12442. memset(filename, 0, ARRAY_SIZE(filename));
  12443. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12444. fp = fopen(filename, "r");
  12445. if (!fp)
  12446. {
  12447. DEBUG_INFO("%s does not create.\n", filename);
  12448. fp = fopen(filename, "w+");
  12449. }
  12450. else
  12451. {
  12452. char *line = NULL;
  12453. size_t len = 0;
  12454. while(getline(&line, &len, fp) != -1)
  12455. {
  12456. json_object *obj = NULL;
  12457. obj = json_tokener_parse(line);
  12458. if(is_error(obj))
  12459. {
  12460. DEBUG_ERROR("Parse txProfile from file error.\n");
  12461. }
  12462. else
  12463. {
  12464. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12465. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12466. {
  12467. tmpProfileQuantity += 1;
  12468. }
  12469. else
  12470. isReplaceable = TRUE;
  12471. }
  12472. }
  12473. }
  12474. fclose(fp);
  12475. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12476. }
  12477. }
  12478. else
  12479. {
  12480. memset(filename, 0, ARRAY_SIZE(filename));
  12481. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12482. fp = fopen(filename, "r");
  12483. if (!fp)
  12484. {
  12485. DEBUG_INFO("%s does not create.\n", filename);
  12486. fp = fopen(filename, "w+");
  12487. }
  12488. else
  12489. {
  12490. char *line = NULL;
  12491. size_t len = 0;
  12492. while(getline(&line, &len, fp) != -1)
  12493. {
  12494. json_object *obj = NULL;
  12495. obj = json_tokener_parse(line);
  12496. if(is_error(obj))
  12497. {
  12498. DEBUG_ERROR("Parse txProfile from file error.\n");
  12499. }
  12500. else
  12501. {
  12502. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12503. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12504. {
  12505. profileQuantity += 1;
  12506. }
  12507. else
  12508. isReplaceable = TRUE;
  12509. }
  12510. }
  12511. }
  12512. fclose(fp);
  12513. }
  12514. }
  12515. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12516. {
  12517. int isMatchTransactiodId= FALSE;
  12518. FILE *fp;
  12519. char filename[128]={0};
  12520. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12521. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12522. if(SetProfileReq.ConnectorId == 0)
  12523. {
  12524. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12525. DEBUG_WARN("Profile connector id is 0.\n");
  12526. goto end;
  12527. }
  12528. int tempIndex = 0;
  12529. //check Transaction active
  12530. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12531. {
  12532. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12533. {
  12534. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12535. }
  12536. else
  12537. {
  12538. tempIndex = SetProfileReq.ConnectorId -1;
  12539. }
  12540. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12541. {
  12542. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12543. {
  12544. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12545. {
  12546. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12547. {
  12548. isMatchTransactiodId = TRUE;
  12549. break;
  12550. }
  12551. }
  12552. }
  12553. }
  12554. }
  12555. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12556. {
  12557. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12558. {
  12559. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12560. }
  12561. else
  12562. {
  12563. tempIndex = SetProfileReq.ConnectorId -1;
  12564. }
  12565. for (int index = 0; index < CCS_QUANTITY; index++)
  12566. {
  12567. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12568. {
  12569. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12570. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12571. {
  12572. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12573. {
  12574. isMatchTransactiodId = TRUE;
  12575. break;
  12576. }
  12577. }
  12578. }
  12579. }
  12580. }
  12581. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12582. {
  12583. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12584. {
  12585. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12586. }
  12587. else
  12588. {
  12589. tempIndex = SetProfileReq.ConnectorId -1;
  12590. }
  12591. for (int index = 0; index < GB_QUANTITY; index++)
  12592. {
  12593. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12594. {
  12595. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12596. {
  12597. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12598. {
  12599. isMatchTransactiodId = TRUE;
  12600. break;
  12601. }
  12602. }
  12603. }
  12604. }
  12605. }
  12606. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12607. {
  12608. tempIndex = SetProfileReq.ConnectorId -1;
  12609. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12610. {
  12611. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12612. {
  12613. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12614. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12615. {
  12616. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12617. {
  12618. isMatchTransactiodId = TRUE;
  12619. break;
  12620. }
  12621. }
  12622. }
  12623. }
  12624. }
  12625. else
  12626. {
  12627. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12628. {
  12629. tempIndex = 2;
  12630. }
  12631. else
  12632. {
  12633. tempIndex = (SetProfileReq.ConnectorId -1);
  12634. }
  12635. for (int index = 0; index < AC_QUANTITY; index++)
  12636. {
  12637. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12638. {
  12639. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12640. {
  12641. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12642. {
  12643. isMatchTransactiodId = TRUE;
  12644. break;
  12645. }
  12646. }
  12647. }
  12648. }
  12649. }
  12650. //check Transaction active
  12651. if(isMatchTransactiodId == FALSE)
  12652. {
  12653. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12654. DEBUG_WARN("Tx profile transaction id is not match.\n");
  12655. goto end;
  12656. }
  12657. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12658. {
  12659. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12660. DEBUG_WARN("Connector id is over max gun number.\n");
  12661. goto end;
  12662. }
  12663. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12664. fp = fopen(filename, "r");
  12665. if (!fp)
  12666. {
  12667. DEBUG_INFO("%s does not create.\n", filename);
  12668. fp = fopen(filename, "w+");
  12669. }
  12670. else
  12671. {
  12672. char *line = NULL;
  12673. size_t len = 0;
  12674. while(getline(&line, &len, fp) != -1)
  12675. {
  12676. json_object *obj = NULL;
  12677. obj = json_tokener_parse(line);
  12678. if(is_error(obj))
  12679. {
  12680. DEBUG_ERROR("Parse txProfile from file error.\n");
  12681. }
  12682. else
  12683. {
  12684. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12685. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12686. {
  12687. profileQuantity += 1;
  12688. }
  12689. else
  12690. isReplaceable = TRUE;
  12691. }
  12692. }
  12693. }
  12694. fclose(fp);
  12695. }
  12696. // Check ChargeProfileMaxStackLevel
  12697. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12698. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12699. {
  12700. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12701. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12702. goto end;
  12703. }
  12704. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12705. {
  12706. FILE *fp;
  12707. char dataLine[4096]={0};
  12708. char fnametemp[128]={0};
  12709. int tmpProfileQuantity;
  12710. //Check ChargePointMaxProfile.json exit
  12711. profileQuantity = 0;
  12712. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12713. {
  12714. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  12715. //Check Charging Profile Count
  12716. tmpProfileQuantity = 0;
  12717. while(fscanf(fp, "%s", dataLine) != EOF)
  12718. {
  12719. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12720. {
  12721. profileQuantity += 1;
  12722. tmpProfileQuantity += 1;
  12723. }
  12724. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12725. }
  12726. fclose(fp);
  12727. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12728. }
  12729. //Check TxDefaultProfile_%d.json
  12730. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12731. {
  12732. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12733. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12734. if((access(fnametemp,F_OK))!=-1)
  12735. {
  12736. fp = fopen(fnametemp, "r");
  12737. //Check Charging Profile Count
  12738. tmpProfileQuantity = 0;
  12739. while(fscanf(fp, "%s", dataLine) != EOF)
  12740. {
  12741. //DEBUG_INFO("word=%s\n",word);
  12742. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12743. {
  12744. profileQuantity += 1;
  12745. tmpProfileQuantity += 1;
  12746. }
  12747. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12748. }
  12749. fclose(fp);
  12750. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12751. }
  12752. }
  12753. //Check TxProfile_%d.json
  12754. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12755. {
  12756. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12757. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  12758. if((access(fnametemp,F_OK))!=-1)
  12759. {
  12760. fp = fopen(fnametemp, "r");
  12761. //Check Charging Profile Count
  12762. tmpProfileQuantity = 0;
  12763. while(fscanf(fp, "%s", dataLine) != EOF)
  12764. {
  12765. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12766. {
  12767. profileQuantity += 1;
  12768. tmpProfileQuantity += 1;
  12769. }
  12770. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12771. }
  12772. fclose(fp);
  12773. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12774. }
  12775. }
  12776. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12777. if((profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData)) && (isReplaceable != TRUE))
  12778. {
  12779. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12780. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12781. goto end;
  12782. }
  12783. }
  12784. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12785. //**********************************Write to File********************************************************/
  12786. {
  12787. FILE *infile;
  12788. FILE *outfile;
  12789. char dataLine[4096]={0};
  12790. char filename[128]={0};
  12791. int chkChar=0;
  12792. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12793. {
  12794. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12795. {
  12796. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12797. }
  12798. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12799. {
  12800. if(SetProfileReq.ConnectorId==0)
  12801. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12802. else
  12803. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12804. }
  12805. else
  12806. {
  12807. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12808. }
  12809. infile = fopen (filename, "r");
  12810. outfile = fopen (tempfile, "w");
  12811. chkChar = fgetc(infile);
  12812. rewind(infile);
  12813. if(chkChar == EOF)
  12814. {
  12815. // Profile is empty
  12816. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12817. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12818. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12819. fclose(infile);
  12820. fclose(outfile);
  12821. sprintf(rmFileCmd,"rm -f %s",filename);
  12822. system(rmFileCmd);
  12823. rename(tempfile, filename);
  12824. }
  12825. else
  12826. {
  12827. // Profile is not empty
  12828. int ChargingProfileAdded = FALSE;
  12829. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12830. {
  12831. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12832. json_object *tmpChargingProfile;
  12833. tmpChargingProfile = json_tokener_parse(dataLine);
  12834. if(!is_error(SetChargingProfile))
  12835. {
  12836. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12837. {
  12838. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12839. {
  12840. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12841. }
  12842. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12843. {
  12844. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  12845. }
  12846. }
  12847. }
  12848. json_object_put(tmpChargingProfile);
  12849. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12850. {
  12851. if(ChargingProfileAdded == FALSE)
  12852. {
  12853. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12854. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12855. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12856. ChargingProfileAdded = TRUE;
  12857. }
  12858. }
  12859. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  12860. {
  12861. if(ChargingProfileAdded == FALSE)
  12862. {
  12863. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12864. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12865. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12866. ChargingProfileAdded = TRUE;
  12867. }
  12868. }
  12869. else
  12870. {
  12871. fprintf(outfile,"%s\n",dataLine);
  12872. if(ChargingProfileAdded == FALSE)
  12873. {
  12874. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12875. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12876. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12877. ChargingProfileAdded = TRUE;
  12878. }
  12879. }
  12880. } // end of while loop
  12881. fclose(infile);
  12882. fclose(outfile);
  12883. sprintf(rmFileCmd,"rm -f %s",filename);
  12884. system(rmFileCmd);
  12885. rename(tempfile, filename);
  12886. }
  12887. }
  12888. sleep(1);
  12889. result = TRUE;
  12890. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12891. }
  12892. end:
  12893. json_object_put(SetChargingProfile);
  12894. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12895. {
  12896. if(SetProfileReq.ConnectorId == 0)
  12897. {
  12898. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12899. {
  12900. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  12901. }
  12902. }
  12903. else
  12904. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12905. }
  12906. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12907. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12908. return result;
  12909. }
  12910. int handleTriggerMessageRequest(char *uuid, char *payload)
  12911. {
  12912. mtrace();
  12913. int result = FAIL;
  12914. int connectorIdIsNULL = FALSE;
  12915. int connectorIdInt =0;
  12916. char sstr[40]={0},sstrtemp[100]={ 0 };
  12917. char requestedMessagestr[40]={0};
  12918. char comfirmstr[20]={0};
  12919. int c = 0;
  12920. char *loc;
  12921. DEBUG_INFO("handleTriggerMessageRequest\n");
  12922. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12923. strcpy(sstrtemp, stringtrimspace(payload));
  12924. c = 0;
  12925. loc = strstr(sstrtemp, "requestedMessage");
  12926. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12927. {
  12928. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12929. c++;
  12930. }
  12931. sstr[c] = '\0';
  12932. strcpy(requestedMessagestr, sstr);
  12933. c = 0;
  12934. loc = strstr(sstrtemp, "connectorId");
  12935. if(loc == NULL)
  12936. {
  12937. connectorIdIsNULL = TRUE;
  12938. }
  12939. else
  12940. {
  12941. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12942. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12943. {
  12944. sstr[c] = loc[strlen("connectorId")+2+c];
  12945. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12946. c++;
  12947. }
  12948. sstr[c] = '\0';
  12949. connectorIdInt = atoi(sstr);
  12950. }
  12951. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12952. {
  12953. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12954. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12955. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12956. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12957. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12958. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12959. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12960. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12961. {
  12962. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12963. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12964. return TRUE;
  12965. }
  12966. else
  12967. {
  12968. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12969. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12970. }
  12971. }
  12972. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12973. {
  12974. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12975. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12976. return TRUE;
  12977. }
  12978. //==========================
  12979. // Trigger message
  12980. //==========================
  12981. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12982. {
  12983. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  12984. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12985. {
  12986. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12987. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12988. }
  12989. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12990. }
  12991. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12992. {
  12993. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  12994. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12995. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12996. }
  12997. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12998. {
  12999. //sendBootNotificationRequest();
  13000. server_sign = FALSE;
  13001. }
  13002. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  13003. {
  13004. refreshStartTimer(&clientTime.Heartbeat);
  13005. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13006. }
  13007. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  13008. {
  13009. if(connectorIdIsNULL == FALSE)
  13010. {
  13011. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13012. {
  13013. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  13014. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  13015. }
  13016. }
  13017. else
  13018. {
  13019. for(int idx=0;idx< gunTotalNumber;idx++)
  13020. {
  13021. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13022. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13023. }
  13024. }
  13025. }
  13026. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  13027. {
  13028. if(connectorIdIsNULL == FALSE)
  13029. {
  13030. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13031. {
  13032. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  13033. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  13034. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13035. }
  13036. }
  13037. else
  13038. {
  13039. for(int idx=0;idx< gunTotalNumber;idx++)
  13040. {
  13041. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  13042. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13043. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13044. }
  13045. }
  13046. }
  13047. return result;
  13048. }
  13049. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13050. {
  13051. mtrace();
  13052. int result = FAIL;
  13053. int connectorIdInt =0;
  13054. char comfirmstr[20]={0};
  13055. int tempIndex = 0;
  13056. json_object *UnlockConnector;
  13057. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13058. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13059. UnlockConnector = json_tokener_parse(payload);
  13060. if(!is_error(UnlockConnector))
  13061. {
  13062. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13063. {
  13064. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13065. }
  13066. }
  13067. json_object_put(UnlockConnector);
  13068. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13069. if(gunTotalNumber == 0)
  13070. {
  13071. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13072. goto end;
  13073. }
  13074. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13075. {
  13076. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13077. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13078. goto end;
  13079. }
  13080. else
  13081. {
  13082. //check Transaction active
  13083. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13084. {
  13085. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13086. {
  13087. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13088. }
  13089. else
  13090. {
  13091. tempIndex = connectorIdInt -1;
  13092. }
  13093. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13094. {
  13095. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13096. {
  13097. //stop Transaction
  13098. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13099. }
  13100. }
  13101. }
  13102. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13103. {
  13104. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13105. {
  13106. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13107. }
  13108. else
  13109. {
  13110. tempIndex = connectorIdInt -1;
  13111. }
  13112. for (int index = 0; index < CCS_QUANTITY; index++)
  13113. {
  13114. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13115. {
  13116. //stop Transaction
  13117. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13118. }
  13119. }
  13120. }
  13121. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13122. {
  13123. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13124. {
  13125. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13126. }
  13127. else
  13128. {
  13129. tempIndex = connectorIdInt -1;
  13130. }
  13131. for (int index = 0; index < GB_QUANTITY; index++)
  13132. {
  13133. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13134. {
  13135. //stop Transaction
  13136. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13137. }
  13138. }
  13139. }
  13140. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13141. {
  13142. tempIndex = connectorIdInt -1;
  13143. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13144. {
  13145. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13146. {
  13147. //stop Transaction
  13148. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13149. }
  13150. }
  13151. }
  13152. else
  13153. {
  13154. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13155. {
  13156. tempIndex = 2;
  13157. }
  13158. else
  13159. {
  13160. tempIndex = connectorIdInt-1;
  13161. }
  13162. for (int index = 0; index < AC_QUANTITY; index++)
  13163. {
  13164. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  13165. {
  13166. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13167. }
  13168. }
  13169. }
  13170. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  13171. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  13172. result = TRUE;
  13173. return result;
  13174. }
  13175. end:
  13176. //json_object_put(obj); --- remove temporally
  13177. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  13178. return result;
  13179. }
  13180. static char UpdateFirmwarepayloadData[300]={0};
  13181. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13182. {
  13183. mtrace();
  13184. int result = FAIL;
  13185. pthread_t t;
  13186. sendUpdateFirmwareConfirmation(uuid);
  13187. memset(UpdateFirmwarepayloadData, 0, 300);
  13188. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  13189. if(!interLock.isUpdateFirmwareGoing)
  13190. {
  13191. interLock.isUpdateFirmwareGoing = 1;
  13192. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  13193. sleep(1);
  13194. }
  13195. else
  13196. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13197. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  13198. return result;
  13199. }
  13200. void *UpdateFirmwareProcess(void *data)
  13201. {
  13202. pthread_detach(pthread_self());
  13203. mtrace();
  13204. int retriesInt =0, retryIntervalInt=0;
  13205. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  13206. int port=0;
  13207. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  13208. int isSuccess = 0;
  13209. char ftpbuf[1024];
  13210. char temp[1024];
  13211. char * pch;
  13212. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13213. json_object *UpdateFirmware;
  13214. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  13215. if(!is_error(UpdateFirmware))
  13216. {
  13217. // Required data
  13218. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13219. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13220. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13221. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13222. // Optional data
  13223. if(json_object_object_get(UpdateFirmware, "retries"))
  13224. {
  13225. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13226. }
  13227. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13228. {
  13229. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13230. }
  13231. }
  13232. json_object_put(UpdateFirmware);
  13233. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13234. memset(path, 0, ARRAY_SIZE(path));
  13235. // Wait retrieveData
  13236. if(strlen(retrieveDatestr) > 10)
  13237. {
  13238. do
  13239. {
  13240. sleep(1);
  13241. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13242. }
  13243. // Ready to download
  13244. system("rm -f /mnt/*");
  13245. if(strncmp(locationstr,"http", 4) == 0)
  13246. {
  13247. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13248. sprintf(ftppath,"/%s", path);
  13249. DEBUG_INFO("locationstr: %s\n", locationstr);
  13250. DEBUG_INFO("protocol: %s\n",protocol);
  13251. DEBUG_INFO("host: %s\n",host);
  13252. DEBUG_INFO("path: %s\n",path);
  13253. DEBUG_INFO("ftppath: %s\n",ftppath);
  13254. int ftppathlen=strlen(ftppath);
  13255. int i=1;
  13256. char filenametemp[50];
  13257. while(i < ftppathlen)
  13258. {
  13259. int len=ftppathlen-i;
  13260. if(ftppath[len]== 47) // '/' ascll code: 47
  13261. {
  13262. DEBUG_INFO("compare '/' all right\n");
  13263. break;
  13264. }
  13265. i=i+1;
  13266. }
  13267. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13268. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13269. filenametemp[i+1] = 0;
  13270. do
  13271. {
  13272. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13273. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13274. sleep(1);
  13275. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13276. if(!isSuccess)
  13277. {
  13278. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13279. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13280. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13281. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13282. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13283. }
  13284. else
  13285. {
  13286. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13287. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13288. }
  13289. retriesInt--;
  13290. }while((isSuccess == 0)&&(retriesInt >= 0));
  13291. }
  13292. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13293. {
  13294. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13295. memset(temp, 0, ARRAY_SIZE(temp));
  13296. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13297. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13298. int ftppathlen=strlen(ftpbuf);
  13299. int i=1;
  13300. char filenametemp[50];
  13301. while(i < ftppathlen)
  13302. {
  13303. int len=ftppathlen-i;
  13304. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13305. {
  13306. DEBUG_INFO(" compare '/' all right\n");
  13307. break;
  13308. }
  13309. i=i+1;
  13310. }
  13311. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13312. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13313. filenametemp[i+1] = 0;
  13314. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13315. pch=strchr(temp,'@');
  13316. if(pch==NULL)
  13317. {
  13318. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13319. protocol, host, &port, path);
  13320. strcpy(user,"anonymous");
  13321. strcpy(password,"");
  13322. }
  13323. else
  13324. {
  13325. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13326. protocol, user, password, host, &port, path);
  13327. }
  13328. sscanf(host,"%[^/]%s",host1, path1);
  13329. sprintf(ftppath,"%s", path1);
  13330. //DEBUG_INFO("protocol =%s\n",protocol);
  13331. //DEBUG_INFO("user =%s\n",user);
  13332. //DEBUG_INFO("password =%s\n",password);
  13333. //DEBUG_INFO("host1 =%s\n",host1);
  13334. //DEBUG_INFO("port =%d\n",port);
  13335. //DEBUG_INFO("path1 =%s\n",path1);
  13336. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13337. //ftpFile(host, user, password, port, ftppath, fname);
  13338. //download firmware pthred
  13339. if(port == 0)
  13340. {
  13341. port = 21;
  13342. }
  13343. do
  13344. {
  13345. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13346. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13347. sleep(1);
  13348. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13349. if(!isSuccess)
  13350. {
  13351. //BulldogUtil.sleepMs(interval*1000);
  13352. DEBUG_INFO("Update firmware request and download file fail.\n");
  13353. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13354. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13355. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13356. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13357. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13358. }
  13359. else
  13360. {
  13361. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13362. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13363. }
  13364. retriesInt--;
  13365. }while((!isSuccess)&&(retriesInt >= 0));
  13366. }
  13367. else
  13368. {
  13369. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13370. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13371. sleep(1);
  13372. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13373. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13374. }
  13375. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13376. interLock.isUpdateFirmwareGoing = 0;
  13377. pthread_exit(NULL);
  13378. }
  13379. int handleCertificateSignedRequest(char *uuid, char *payload)
  13380. {
  13381. mtrace();
  13382. int result = PASS;
  13383. json_object *CertificateSigned;
  13384. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13385. CertificateSigned = json_tokener_parse(payload);
  13386. if(!is_error(CertificateSigned))
  13387. {
  13388. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13389. }
  13390. json_object_put(CertificateSigned);
  13391. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  13392. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  13393. fclose(fp);
  13394. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13395. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  13396. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  13397. sendCertificateSignedConfirmation(uuid);
  13398. return result;
  13399. }
  13400. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13401. {
  13402. mtrace();
  13403. int result = PASS;
  13404. json_object *DeleteCertificate;
  13405. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13406. DeleteCertificate = json_tokener_parse(payload);
  13407. if(!is_error(DeleteCertificate))
  13408. {
  13409. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13410. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13411. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13412. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13413. }
  13414. json_object_put(DeleteCertificate);
  13415. /*
  13416. * TODO: Delete certificateSigned process
  13417. */
  13418. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  13419. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  13420. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  13421. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  13422. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  13423. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  13424. sendDeleteCertificateConfirmation(uuid);
  13425. return result;
  13426. }
  13427. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13428. {
  13429. mtrace();
  13430. int result = PASS;
  13431. json_object *ExtendedTriggerMessage;
  13432. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13433. ExtendedTriggerMessage = json_tokener_parse(payload);
  13434. if(!is_error(ExtendedTriggerMessage))
  13435. {
  13436. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13437. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13438. {
  13439. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13440. }
  13441. else
  13442. {
  13443. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  13444. }
  13445. }
  13446. json_object_put(ExtendedTriggerMessage);
  13447. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  13448. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  13449. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13450. {
  13451. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13452. }
  13453. else
  13454. {
  13455. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13456. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13457. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13458. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13459. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13460. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13461. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13462. {
  13463. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13464. }
  13465. else
  13466. {
  13467. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13468. }
  13469. }
  13470. sendExtendedTriggerMessageConfirmation(uuid);
  13471. //==========================
  13472. // Trigger message
  13473. //==========================
  13474. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13475. {
  13476. //sendBootNotificationRequest();
  13477. server_sign = FALSE;
  13478. }
  13479. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13480. {
  13481. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13482. }
  13483. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13484. {
  13485. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13486. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13487. {
  13488. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13489. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13490. }
  13491. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13492. }
  13493. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13494. {
  13495. refreshStartTimer(&clientTime.Heartbeat);
  13496. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13497. }
  13498. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13499. {
  13500. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13501. {
  13502. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13503. }
  13504. else
  13505. {
  13506. for(int idx=0;idx< gunTotalNumber;idx++)
  13507. {
  13508. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13509. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13510. }
  13511. }
  13512. }
  13513. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13514. {
  13515. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  13516. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  13517. {
  13518. 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\" &");
  13519. }
  13520. }
  13521. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13522. {
  13523. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13524. {
  13525. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13526. }
  13527. else
  13528. {
  13529. for(int idx=0;idx< gunTotalNumber;idx++)
  13530. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13531. }
  13532. }
  13533. return result;
  13534. }
  13535. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13536. {
  13537. mtrace();
  13538. int result = PASS;
  13539. json_object *GetInstalledCertificateIds;
  13540. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13541. GetInstalledCertificateIds = json_tokener_parse(payload);
  13542. if(!is_error(GetInstalledCertificateIds))
  13543. {
  13544. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13545. }
  13546. json_object_put(GetInstalledCertificateIds);
  13547. /*
  13548. * TODO: Return installed certificate process
  13549. */
  13550. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13551. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  13552. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13553. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13554. sendGetInstalledCertificateIdsConfirmation(uuid);
  13555. return result;
  13556. }
  13557. int handleGetLogRequest(char *uuid, char *payload)
  13558. {
  13559. mtrace();
  13560. int result = PASS;
  13561. json_object *GetLog;
  13562. DEBUG_INFO("handleGetLogRequest...\n");
  13563. GetLog = json_tokener_parse(payload);
  13564. if(!is_error(GetLog))
  13565. {
  13566. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13567. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13568. if(json_object_object_get(GetLog, "retries") != NULL)
  13569. {
  13570. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13571. }
  13572. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13573. {
  13574. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13575. }
  13576. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13577. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13578. {
  13579. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13580. }
  13581. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13582. {
  13583. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13584. }
  13585. }
  13586. json_object_put(GetLog);
  13587. /*
  13588. * TODO: Upload log process
  13589. */
  13590. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  13591. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  13592. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  13593. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  13594. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  13595. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  13596. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  13597. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  13598. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  13599. sendGetLogConfirmation(uuid);
  13600. return result;
  13601. }
  13602. int handleInstallCertificateRequest(char *uuid, char *payload)
  13603. {
  13604. mtrace();
  13605. int result = PASS;
  13606. json_object *InstallCertificate;
  13607. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13608. InstallCertificate = json_tokener_parse(payload);
  13609. if(!is_error(InstallCertificate))
  13610. {
  13611. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13612. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13613. /*
  13614. * TODO: Install certificate process
  13615. */
  13616. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  13617. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  13618. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  13619. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  13620. sendInstallCertificateConfirmation(uuid);
  13621. }
  13622. json_object_put(InstallCertificate);
  13623. return result;
  13624. }
  13625. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13626. {
  13627. mtrace();
  13628. int result = PASS;
  13629. json_object *SignedUpdateFirmware;
  13630. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13631. SignedUpdateFirmware = json_tokener_parse(payload);
  13632. if(!is_error(SignedUpdateFirmware))
  13633. {
  13634. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13635. {
  13636. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13637. }
  13638. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13639. {
  13640. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13641. }
  13642. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13643. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13644. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13645. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13646. {
  13647. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13648. }
  13649. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13650. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13651. }
  13652. json_object_put(SignedUpdateFirmware);
  13653. /*
  13654. * TODO: Upgrade firmware process
  13655. */
  13656. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13657. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  13658. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  13659. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  13660. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  13661. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  13662. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  13663. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  13664. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  13665. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  13666. sendInstallCertificateConfirmation(uuid);
  13667. return result;
  13668. }
  13669. int handleUnknownRequest(char *uuid, char *payload)
  13670. {
  13671. mtrace();
  13672. int result = PASS;
  13673. DEBUG_INFO("handleUnknownRequest...\n");
  13674. sendUnknownConfirmation(uuid);
  13675. result = PASS;
  13676. return result;
  13677. }
  13678. //==========================================
  13679. // Handle server response routine
  13680. //==========================================
  13681. void handleAuthorizeResponse(char *payload, int gun_index)
  13682. {
  13683. mtrace();
  13684. char expiryDatestr[30]={0};
  13685. char parentIdTagstr[20]={0};
  13686. char statusstr[20]={0};
  13687. int expiryDateISNULL=FALSE;
  13688. int parentIdTagISNULL=FALSE;
  13689. DEBUG_INFO("handleAuthorizeResponse...\n");
  13690. json_object *Authorize;
  13691. Authorize = json_tokener_parse(payload);
  13692. if(!is_error(Authorize))
  13693. {
  13694. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13695. {
  13696. // Required data
  13697. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13698. // Optional data
  13699. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13700. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13701. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13702. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13703. }
  13704. }
  13705. json_object_put(Authorize);
  13706. if(expiryDateISNULL == FALSE)
  13707. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13708. if(parentIdTagISNULL == FALSE)
  13709. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13710. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  13711. //Update idTag information to authorization cache if supproted
  13712. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13713. {
  13714. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13715. }
  13716. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  13717. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13718. authorizeRetryTimes = 0;
  13719. }
  13720. void handleBootNotificationResponse(char *payload, int gun_index)
  13721. {
  13722. mtrace();
  13723. char statusStr[12]={0};
  13724. char currentTimeStr[30]={0};
  13725. int intervalInt = 0;
  13726. DEBUG_INFO("handleBootNotificationResponse...\n");
  13727. json_object *BootNotification;
  13728. BootNotification = json_tokener_parse(payload);
  13729. if(!is_error(BootNotification))
  13730. {
  13731. // Required data
  13732. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13733. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13734. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13735. }
  13736. json_object_put(BootNotification);
  13737. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13738. BootNotificationInterval = intervalInt;
  13739. //write back to ShmOCPP16Data->BootNotification
  13740. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  13741. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13742. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  13743. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13744. {
  13745. BootNotificationInterval = 0;
  13746. if((intervalInt == 0) || (intervalInt >= 10))
  13747. {
  13748. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13749. HeartBeatWaitTime = intervalInt;
  13750. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13751. }
  13752. server_sign = TRUE;
  13753. server_pending =FALSE;
  13754. }
  13755. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13756. {
  13757. server_pending = TRUE;
  13758. }
  13759. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  13760. srand(time(NULL));
  13761. refreshStartTimer(&clientTime.Heartbeat);
  13762. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13763. SetOcppConnStatus(TRUE);
  13764. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  13765. }
  13766. void handleDataTransferResponse(char *payload, int gun_index)
  13767. {
  13768. json_object *DataTransfer = json_tokener_parse(payload);
  13769. if(!is_error(DataTransfer))
  13770. {
  13771. // Required data
  13772. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13773. // Optional data
  13774. if(json_object_object_get(DataTransfer, "data") != NULL)
  13775. {
  13776. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13777. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13778. if(!is_error(Data))
  13779. {
  13780. if(json_object_object_get(Data, "msgId") != NULL)
  13781. {
  13782. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13783. {
  13784. 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")));
  13785. }
  13786. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_ReaderStatus") != NULL)
  13787. {
  13788. if(json_object_object_get(Data, "ConnectorId") != NULL)
  13789. ShmOCPP16Data->TcciCustomData.ReaderStatus[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].ReportReaderStatusReq = 0;
  13790. }
  13791. }
  13792. }
  13793. json_object_put(Data);
  13794. }
  13795. }
  13796. json_object_put(DataTransfer);
  13797. }
  13798. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13799. {
  13800. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13801. //struct json_object *obj;
  13802. // obj = json_tokener_parse(payload);
  13803. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13804. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13805. //No fields are defined.
  13806. }
  13807. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13808. {
  13809. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13810. //struct json_object *obj;
  13811. // obj = json_tokener_parse(payload);
  13812. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13813. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13814. //No fields are defined.
  13815. }
  13816. void handleHeartbeatResponse(char *payload, int gun_index)
  13817. {
  13818. mtrace();
  13819. DEBUG_INFO("handleHeartbeatResponse...\n");
  13820. json_object *Heartbeat;
  13821. Heartbeat = json_tokener_parse(payload);
  13822. if(!is_error(Heartbeat))
  13823. {
  13824. // Required data
  13825. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13826. }
  13827. json_object_put(Heartbeat);
  13828. if(FirstHeartBeat == 0)
  13829. {
  13830. FirstHeartBeat = 1;
  13831. DEBUG_INFO("FirstHeartBeat \n");
  13832. }
  13833. HeartBeatWithNOResponse = 0;
  13834. refreshStartTimer(&clientTime.Heartbeat);
  13835. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  13836. }
  13837. void handleMeterValuesResponse(char *payload, int gun_index)
  13838. {
  13839. mtrace();
  13840. DEBUG_INFO("handleMeterValuesResponse...\n");
  13841. isQueueSendable = 1;
  13842. }
  13843. void handleStartTransactionResponse(char *payload, int gun_index)
  13844. {
  13845. mtrace();
  13846. //int transactionIdInt = 0;
  13847. FILE *outfile;
  13848. char data[100]={0};
  13849. DEBUG_INFO("handleStartTransactionResponse...\n");
  13850. json_object *StartTransaction;
  13851. StartTransaction = json_tokener_parse(payload);
  13852. if(!is_error(StartTransaction))
  13853. {
  13854. // Required data
  13855. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13856. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13857. // Optional data
  13858. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13859. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13860. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13861. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13862. }
  13863. json_object_put(StartTransaction);
  13864. isQueueSendable = 1;
  13865. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13866. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13867. //-----------Start : write to the Queue TransactionId file -----------------//
  13868. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  13869. {}
  13870. else
  13871. {
  13872. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  13873. if(log == NULL)
  13874. {
  13875. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13876. return ;
  13877. }
  13878. else
  13879. {
  13880. fclose(log);
  13881. }
  13882. }
  13883. // open file for writing
  13884. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13885. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  13886. {
  13887. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  13888. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13889. fputs(data, outfile);
  13890. fclose (outfile);
  13891. }
  13892. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13893. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13894. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13895. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  13896. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13897. }
  13898. void handleStatusNotificationResponse(char *payload, int gun_index)
  13899. {
  13900. mtrace();
  13901. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13902. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13903. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13904. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13905. }
  13906. void handleStopTransactionnResponse(char *payload, int gun_index)
  13907. {
  13908. mtrace();
  13909. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13910. json_object *StopTransaction;
  13911. StopTransaction = json_tokener_parse(payload);
  13912. if(!is_error(StopTransaction))
  13913. {
  13914. // Optional data
  13915. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13916. {
  13917. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13918. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13919. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13920. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13921. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13922. }
  13923. }
  13924. json_object_put(StopTransaction);
  13925. isQueueSendable = 1;
  13926. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13927. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13928. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13929. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13930. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13931. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13932. }
  13933. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13934. {
  13935. mtrace();
  13936. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13937. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  13938. }
  13939. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13940. {
  13941. mtrace();
  13942. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13943. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  13944. }
  13945. void handleSignCertificateResponse(char *payload, int gun_index)
  13946. {
  13947. mtrace();
  13948. DEBUG_INFO("handleSignCertificateResponse...\n");
  13949. json_object *SignCertificate;
  13950. SignCertificate = json_tokener_parse(payload);
  13951. if(!is_error(SignCertificate))
  13952. {
  13953. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13954. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  13955. }
  13956. json_object_put(SignCertificate);
  13957. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  13958. }
  13959. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13960. {
  13961. mtrace();
  13962. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13963. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13964. }
  13965. //==========================================
  13966. // Handle Error routine
  13967. //==========================================
  13968. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13969. {
  13970. mtrace();
  13971. #ifdef SystemLogMessage
  13972. DEBUG_INFO("errorCode: %s\n", errorCode);
  13973. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13974. DEBUG_INFO("errorDetails: %s\n", payload);
  13975. #endif
  13976. }
  13977. //===============================================
  13978. // Common routine
  13979. //===============================================
  13980. int initialConfigurationTable(void)
  13981. {
  13982. //clock_t start_t, end_t, total_t;
  13983. FILE *fp;
  13984. FILE *outfile;
  13985. char str[512]={0};
  13986. char sstr[256]={0};
  13987. int c = 0;
  13988. char *loc;
  13989. int confVersion = 14;
  13990. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13991. //start_t = clock();
  13992. //printf("Starting of the program, start_t = %ld\n", start_t);
  13993. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13994. // Check configuration file size is correct
  13995. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  13996. {
  13997. struct stat st;
  13998. stat("/Storage/OCPP/OCPPConfiguration", &st);
  13999. if(st.st_size < 3100)
  14000. {
  14001. system("rm -f /Storage/OCPP/OCPPConfiguration");
  14002. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  14003. }
  14004. }
  14005. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  14006. {
  14007. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14008. if(outfile == NULL)
  14009. {
  14010. DEBUG_INFO("Error opening file\n");
  14011. return FALSE;
  14012. }
  14013. /*Core Profile*/
  14014. //AllowOfflineTxForUnknownId
  14015. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14016. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14017. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  14018. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14019. //AuthorizationCacheEnabled
  14020. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14022. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14023. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14024. //AuthorizeRemoteTxRequests
  14025. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14026. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  14028. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14029. //BlinkRepeat
  14030. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14031. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14032. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14033. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14034. //ClockAlignedDataInterval
  14035. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14036. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14037. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14038. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14039. //ConnectionTimeOut
  14040. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14043. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14044. //GetConfigurationMaxKeys
  14045. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14046. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14047. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  14048. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14049. // HeartbeatInterval
  14050. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  14053. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14054. // LightIntensity
  14055. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14058. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14059. // LocalAuthorizeOffline
  14060. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  14061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14063. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14064. // LocalPreAuthorize
  14065. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  14066. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14067. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14068. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14069. // MaxEnergyOnInvalidId
  14070. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14071. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14073. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14074. // MeterValuesAlignedData
  14075. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14077. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14078. 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" );
  14079. else
  14080. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14081. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14082. // MeterValuesAlignedDataMaxLength
  14083. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14085. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14086. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  14087. else
  14088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  14089. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14090. // MeterValuesSampledData
  14091. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14093. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14094. 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" );
  14095. else
  14096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14097. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14098. // MeterValuesSampledDataMaxLength
  14099. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14101. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  14103. else
  14104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  14105. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14106. // MeterValueSampleInterval
  14107. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  14110. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14111. // MinimumStatusDuration
  14112. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  14115. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  14116. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14117. // NumberOfConnectors
  14118. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14120. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14121. {
  14122. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14123. }
  14124. else
  14125. {
  14126. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14127. }
  14128. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14129. // ResetRetries
  14130. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14133. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14134. // ConnectorPhaseRotation
  14135. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14138. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14139. // ConnectorPhaseRotationMaxLength
  14140. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14143. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14144. // StopTransactionOnEVSideDisconnect
  14145. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14148. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14149. // StopTransactionOnInvalidId
  14150. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  14151. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14152. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14153. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14154. // StopTxnAlignedData
  14155. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  14156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  14158. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14159. // StopTxnAlignedDataMaxLength
  14160. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14163. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14164. // StopTxnSampledData
  14165. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14166. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14167. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  14169. else
  14170. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  14171. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14172. // StopTxnSampledDataMaxLength
  14173. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14175. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14176. {
  14177. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  14178. }
  14179. else
  14180. {
  14181. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  14182. }
  14183. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14184. // SupportedFeatureProfiles
  14185. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14186. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14187. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14188. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14189. // SupportedFeatureProfilesMaxLength
  14190. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14192. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14193. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14194. // TransactionMessageAttempts
  14195. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14197. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14198. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14199. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14200. // TransactionMessageRetryInterval
  14201. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14202. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14204. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14205. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14206. // UnlockConnectorOnEVSideDisconnect
  14207. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14208. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14210. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14211. // WebSocketPingInterval
  14212. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14215. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14216. // QueueOffLineMeterValues
  14217. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  14218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14219. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  14220. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14221. // AuthorizationKey
  14222. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14225. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14226. // SecurityProfile
  14227. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14229. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14230. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14231. // DefaultPrice
  14232. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14234. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14235. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14236. // CustomDisplayCostAndPrice
  14237. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14239. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14240. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14241. // CustomIdleFeeAfterStop
  14242. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14243. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14244. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14245. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14246. // TimeOffset
  14247. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14249. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  14250. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14251. // NextTimeOffsetTransitionDateTime
  14252. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  14255. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14256. // TimeOffsetNextTransition
  14257. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14258. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  14260. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14261. // SystemUptimeSec
  14262. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14263. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14264. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14265. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14266. // FreeVend
  14267. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14270. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14271. // FreeVendIdtag
  14272. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14274. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14275. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14276. // OcppServer
  14277. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14279. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14280. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14281. // MaintainServer
  14282. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14284. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  14285. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14286. // StatusNotificationPeriodically
  14287. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  14288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14290. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14291. // StatusNotificationInterval
  14292. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14295. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14296. // PreAuthAmount
  14297. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  14298. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  14299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "888" );
  14300. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  14301. // Configuration Version
  14302. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  14303. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14304. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  14305. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14306. //* Local Auth List Management Profile*/
  14307. #if 0
  14308. //For OCTT Test Case
  14309. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  14311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14312. #endif
  14313. #if 1
  14314. //LocalAuthListEnabled
  14315. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14317. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14318. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14319. #endif
  14320. //LocalAuthListMaxLength
  14321. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14323. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  14324. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14325. //SendLocalListMaxLength
  14326. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14327. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14329. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14330. //ReserveConnectorZeroSupported
  14331. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14332. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14333. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14334. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14335. //* Smart Charging Profile */
  14336. //ChargeProfileMaxStackLevel
  14337. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14338. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14340. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14341. // ChargingScheduleAllowedChargingRateUnit
  14342. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  14345. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14346. // ChargingScheduleMaxPeriods
  14347. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14350. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14351. // ConnectorSwitch3to1PhaseSupported
  14352. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14354. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  14355. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14356. // MaxChargingProfilesInstalled
  14357. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14359. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14360. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14361. fclose(outfile);
  14362. }
  14363. else
  14364. {
  14365. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  14366. char keystr[60]={0};
  14367. char readonlystr[10]={0};
  14368. char valuestr[256]={0};
  14369. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  14370. if(fp == NULL) {
  14371. DEBUG_INFO("Error opening file");
  14372. return FALSE;
  14373. }
  14374. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  14375. {
  14376. //DEBUG_INFO("Get Configuration \n");
  14377. if(strlen(str) > 0)
  14378. {
  14379. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14380. //*************************key*********************************/
  14381. if(strstr(str, "key") != NULL)
  14382. {
  14383. loc = strstr(str, "key");
  14384. c = 0;
  14385. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14386. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14387. {
  14388. sstr[c] = loc[strlen("key")+3+c];
  14389. c++;
  14390. }
  14391. sstr[c] = '\0';
  14392. strcpy(keystr,sstr);
  14393. }
  14394. //*************************readonly*********************************/
  14395. if(strstr(str, "readonly") != NULL)
  14396. {
  14397. loc = strstr(str, "readonly");
  14398. c = 0;
  14399. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14400. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  14401. {
  14402. sstr[c] = loc[strlen("readonly")+2+c];
  14403. c++;
  14404. }
  14405. sstr[c] = '\0';
  14406. strcpy(readonlystr,sstr);
  14407. }
  14408. //*************************value*********************************/
  14409. if(strstr(str, "value") != NULL)
  14410. {
  14411. loc = strstr(str, "value");
  14412. c = 0;
  14413. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14414. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14415. {
  14416. sstr[c] = loc[strlen("value")+3+c];
  14417. c++;
  14418. }
  14419. sstr[c] = '\0';
  14420. strcpy(valuestr,sstr);
  14421. }
  14422. // DEBUG_INFO("keystr=%s\n",keystr);
  14423. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  14424. // DEBUG_INFO("valuestr=%s\n",valuestr);
  14425. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  14426. {
  14427. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14428. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14429. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14430. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14431. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14432. }
  14433. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14434. {
  14435. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14436. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14437. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14438. }
  14439. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14440. {
  14441. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14442. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14443. }
  14444. if(strcmp(keystr, "BlinkRepeat") == 0)
  14445. {
  14446. //Charger.BlinkRepeat = Integer.parseInt(value);
  14447. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14448. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14449. }
  14450. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14451. {
  14452. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14453. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14454. }
  14455. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14456. {
  14457. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14458. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14459. }
  14460. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14461. {
  14462. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14463. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14464. }
  14465. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14466. {
  14467. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14468. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14469. HeartBeatWaitTime = atoi(valuestr);
  14470. }
  14471. if(strcmp(keystr, "LightIntensity") == 0)
  14472. {
  14473. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14474. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14475. }
  14476. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14477. {
  14478. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14479. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14480. }
  14481. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14482. {
  14483. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14484. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14485. }
  14486. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14487. {
  14488. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14489. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14490. }
  14491. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14492. {
  14493. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14494. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14495. }
  14496. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14497. {
  14498. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14499. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14500. }
  14501. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14502. {
  14503. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14504. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14505. }
  14506. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14507. {
  14508. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14509. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14510. }
  14511. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14512. {
  14513. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14514. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14515. }
  14516. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14517. {
  14518. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14519. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14520. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14521. }
  14522. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14523. {
  14524. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14525. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14526. }
  14527. if(strcmp(keystr, "ResetRetries") == 0)
  14528. {
  14529. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14530. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14531. }
  14532. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14533. {
  14534. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14535. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14536. }
  14537. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14538. {
  14539. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14540. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14541. }
  14542. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14543. {
  14544. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14545. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14546. }
  14547. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14548. {
  14549. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14550. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14551. }
  14552. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14553. {
  14554. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14555. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14556. }
  14557. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14558. {
  14559. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14560. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14561. }
  14562. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14563. {
  14564. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14565. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14566. }
  14567. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14568. {
  14569. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14570. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14571. }
  14572. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14573. {
  14574. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14575. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14576. }
  14577. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14578. {
  14579. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14580. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14581. }
  14582. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14583. {
  14584. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14585. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14586. TransactionMessageAttemptsValue = atoi(valuestr);
  14587. }
  14588. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14589. {
  14590. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14591. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14592. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14593. }
  14594. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14595. {
  14596. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14597. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14598. }
  14599. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14600. {
  14601. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14602. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14603. }
  14604. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14605. {
  14606. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14607. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14608. }
  14609. if(strcmp(keystr, "AuthorizationKey") == 0)
  14610. {
  14611. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14612. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14613. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14614. }
  14615. if(strcmp(keystr, "SecurityProfile") == 0)
  14616. {
  14617. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14618. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14619. }
  14620. if(strcmp(keystr, "DefaultPrice") == 0)
  14621. {
  14622. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14623. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14624. }
  14625. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14626. {
  14627. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14628. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14629. }
  14630. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14631. {
  14632. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14633. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14634. }
  14635. if(strcmp(keystr, "TimeOffset") == 0)
  14636. {
  14637. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14638. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  14639. }
  14640. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  14641. {
  14642. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14643. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  14644. }
  14645. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  14646. {
  14647. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14648. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  14649. }
  14650. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14651. {
  14652. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14653. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  14654. }
  14655. if(strcmp(keystr, "FreeVend") == 0)
  14656. {
  14657. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14658. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14659. }
  14660. if(strcmp(keystr, "FreeVendIdtag") == 0)
  14661. {
  14662. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14663. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  14664. }
  14665. if(strcmp(keystr, "OcppServer") == 0)
  14666. {
  14667. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14668. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14669. }
  14670. if(strcmp(keystr, "MaintainServer") == 0)
  14671. {
  14672. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14673. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14674. }
  14675. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14676. {
  14677. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14678. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14679. }
  14680. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14681. {
  14682. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14683. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14684. }
  14685. if(strcmp(keystr, "PreAuthAmount") == 0)
  14686. {
  14687. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14688. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(valuestr));
  14689. }
  14690. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14691. {
  14692. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14693. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14694. }
  14695. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14696. {
  14697. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14698. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14699. }
  14700. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14701. {
  14702. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14703. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14704. }
  14705. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14706. {
  14707. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14708. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14709. }
  14710. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14711. {
  14712. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14713. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14714. }
  14715. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14716. {
  14717. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14718. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14719. }
  14720. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14721. {
  14722. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14723. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14724. }
  14725. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14726. {
  14727. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14728. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14729. }
  14730. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14731. {
  14732. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14733. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14734. }
  14735. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14736. {
  14737. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14738. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14739. }
  14740. }
  14741. }
  14742. fclose(fp);
  14743. }
  14744. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14745. {
  14746. return PASS;
  14747. }
  14748. else
  14749. {
  14750. return FAIL;
  14751. }
  14752. }
  14753. void StoreConfigurationTable(void)
  14754. {
  14755. FILE *outfile;
  14756. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14757. if(outfile == NULL)
  14758. {
  14759. DEBUG_INFO("Error opening file");
  14760. return ;
  14761. }
  14762. /*Core Profile*/
  14763. //AllowOfflineTxForUnknownId
  14764. /*
  14765. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14766. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14769. */
  14770. //DEBUG_INFO("data=%s\n",data);
  14771. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14772. //AuthorizationCacheEnabled
  14773. /*
  14774. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14776. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14777. */
  14778. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14779. //AuthorizeRemoteTxRequests
  14780. /*
  14781. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14784. */
  14785. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14786. //BlinkRepeat
  14787. /*
  14788. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14790. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14791. */
  14792. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14793. //ClockAlignedDataInterval
  14794. /*
  14795. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14798. */
  14799. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14800. //ConnectionTimeOut
  14801. /*
  14802. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14804. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14805. */
  14806. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14807. //GetConfigurationMaxKeys
  14808. /*
  14809. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14811. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14812. */
  14813. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14814. // HeartbeatInterval
  14815. /*
  14816. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14819. */
  14820. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14821. // LightIntensity
  14822. /*
  14823. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14826. */
  14827. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14828. // LocalAuthorizeOffline
  14829. /*
  14830. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14833. */
  14834. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14835. // LocalPreAuthorize
  14836. /*
  14837. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14840. */
  14841. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14842. // MaxEnergyOnInvalidId
  14843. /*
  14844. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14846. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14847. */
  14848. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14849. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14850. // MeterValuesAlignedData
  14851. /*
  14852. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14854. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14855. */
  14856. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14857. // MeterValuesAlignedDataMaxLength
  14858. /*
  14859. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14861. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14862. */
  14863. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14864. // MeterValuesSampledData
  14865. /*
  14866. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14868. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14869. */
  14870. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14871. // MeterValuesSampledDataMaxLength
  14872. /*
  14873. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14875. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14876. */
  14877. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14878. // MeterValueSampleInterval
  14879. /*
  14880. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14881. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14883. */
  14884. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14885. // MinimumStatusDuration
  14886. /*
  14887. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14889. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14890. */
  14891. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14892. // NumberOfConnectors
  14893. /*
  14894. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14896. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14897. {
  14898. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14899. }
  14900. else
  14901. {
  14902. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14903. }
  14904. */
  14905. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14906. // ResetRetries
  14907. /*
  14908. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14909. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14910. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14911. */
  14912. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14913. // ConnectorPhaseRotation
  14914. /*
  14915. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14916. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14917. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14918. */
  14919. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14920. // ConnectorPhaseRotationMaxLength
  14921. /*
  14922. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14923. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14924. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14925. */
  14926. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14927. // StopTransactionOnEVSideDisconnect
  14928. /*
  14929. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14931. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14932. */
  14933. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14934. // StopTransactionOnInvalidId
  14935. /*
  14936. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14938. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14939. */
  14940. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14941. // StopTxnAlignedData
  14942. /*
  14943. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14945. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14946. */
  14947. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14948. // StopTxnAlignedDataMaxLength
  14949. /*
  14950. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14952. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14953. */
  14954. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14955. // StopTxnSampledData
  14956. /*
  14957. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14959. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14960. */
  14961. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14962. // StopTxnSampledDataMaxLength
  14963. /*
  14964. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14966. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14967. */
  14968. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14969. // SupportedFeatureProfiles
  14970. /*
  14971. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14973. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14974. */
  14975. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14976. // SupportedFeatureProfilesMaxLength
  14977. /*
  14978. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14979. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14980. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14981. */
  14982. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14983. // TransactionMessageAttempts
  14984. /*
  14985. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14987. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14988. */
  14989. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14990. // TransactionMessageRetryInterval
  14991. /*
  14992. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14994. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14995. */
  14996. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14997. // UnlockConnectorOnEVSideDisconnect
  14998. /*
  14999. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  15000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  15001. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  15002. */
  15003. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15004. // WebSocketPingInterval
  15005. /*
  15006. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15008. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15009. */
  15010. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15011. // QueueOffLineMeterValues
  15012. /*
  15013. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  15014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15015. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  15016. */
  15017. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15018. // AuthorizationKey
  15019. /*
  15020. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15022. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  15023. */
  15024. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15025. // SecurityProfile
  15026. /*
  15027. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  15030. */
  15031. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15032. // DefaultPrice
  15033. /*
  15034. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15036. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15037. */
  15038. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15039. // CustomDisplayCostAndPrice
  15040. /*
  15041. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15044. */
  15045. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15046. // CustomIdleFeeAfterStop
  15047. /*
  15048. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15051. */
  15052. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15053. // TimeOffset
  15054. /*
  15055. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  15056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  15057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  15058. */
  15059. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  15060. // NextTimeOffsetTransitionDateTime
  15061. /*
  15062. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  15063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  15064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  15065. */
  15066. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  15067. // TimeOffsetNextTransition
  15068. /*
  15069. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  15070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  15071. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  15072. */
  15073. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  15074. // SystemUptimeSec
  15075. /*
  15076. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15079. */
  15080. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15081. // FreeVend
  15082. /*
  15083. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  15086. */
  15087. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15088. // FreeVendIdtag
  15089. /*
  15090. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15093. */
  15094. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15095. // OcppServer
  15096. /*
  15097. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  15100. */
  15101. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15102. // MaintainServer
  15103. /*
  15104. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  15107. */
  15108. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15109. // StatusNotificationPeriodically
  15110. /*
  15111. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  15112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15114. */
  15115. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15116. // StatusNotificationInterval
  15117. /*
  15118. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15121. */
  15122. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15123. // PreAuthAmount
  15124. /*
  15125. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  15126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  15127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "120" );
  15128. */
  15129. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  15130. // ConfigurationVersion
  15131. /*
  15132. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  15133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  15135. */
  15136. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15137. //* Local Auth List Management Profile*/
  15138. //LocalAuthListEnabled
  15139. /*
  15140. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15143. */
  15144. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15145. //LocalAuthListMaxLength
  15146. /*
  15147. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15149. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  15150. */
  15151. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15152. //SendLocalListMaxLength
  15153. /*
  15154. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  15157. */
  15158. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15159. //ReserveConnectorZeroSupported
  15160. /*
  15161. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15164. */
  15165. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15166. //* Smart Charging Profile */
  15167. //ChargeProfileMaxStackLevel
  15168. /*
  15169. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  15170. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  15171. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  15172. */
  15173. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15174. // ChargingScheduleAllowedChargingRateUnit
  15175. /*
  15176. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  15177. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  15178. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  15179. */
  15180. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15181. // ChargingScheduleMaxPeriods
  15182. /*
  15183. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  15184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  15185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  15186. */
  15187. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15188. // ConnectorSwitch3to1PhaseSupported
  15189. /*
  15190. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  15191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  15192. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  15193. */
  15194. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15195. // MaxChargingProfilesInstalled
  15196. /*
  15197. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  15198. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  15199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  15200. */
  15201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15202. fclose(outfile);
  15203. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15204. }
  15205. void getKeyValue(char *keyReq)
  15206. {
  15207. int isEmpty = FALSE;
  15208. int isKnowKey = FALSE;
  15209. DEBUG_INFO("keyReq = %s\n", keyReq);
  15210. if((keyReq == NULL) || (strlen(keyReq) == 0))
  15211. isEmpty = TRUE;
  15212. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  15213. {
  15214. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  15215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  15216. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15217. {
  15218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  15219. }
  15220. else
  15221. {
  15222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  15223. }
  15224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  15225. isKnowKey = TRUE;
  15226. }
  15227. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  15228. {
  15229. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  15230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  15231. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15232. {
  15233. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  15234. }
  15235. else
  15236. {
  15237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  15238. }
  15239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  15240. isKnowKey = TRUE;
  15241. }
  15242. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  15243. {
  15244. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  15245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  15246. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15247. {
  15248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  15249. }
  15250. else
  15251. {
  15252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  15253. }
  15254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  15255. isKnowKey = TRUE;
  15256. }
  15257. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  15258. {
  15259. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  15260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  15261. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15262. {
  15263. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  15264. }
  15265. else
  15266. {
  15267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  15268. }
  15269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  15270. isKnowKey = TRUE;
  15271. }
  15272. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  15273. {
  15274. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  15275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  15276. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15277. {
  15278. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  15279. }
  15280. else
  15281. {
  15282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  15283. }
  15284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  15285. isKnowKey = TRUE;
  15286. }
  15287. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  15288. {
  15289. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  15290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  15291. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15292. {
  15293. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  15294. }
  15295. else
  15296. {
  15297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  15298. }
  15299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  15300. isKnowKey = TRUE;
  15301. }
  15302. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  15303. {
  15304. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  15305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  15306. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15307. {
  15308. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  15309. }
  15310. else
  15311. {
  15312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  15313. }
  15314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  15315. isKnowKey = TRUE;
  15316. }
  15317. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  15318. {
  15319. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  15320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  15321. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15322. {
  15323. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  15324. }
  15325. else
  15326. {
  15327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  15328. }
  15329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  15330. isKnowKey = TRUE;
  15331. }
  15332. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  15333. {
  15334. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  15335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  15336. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15337. {
  15338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  15339. }
  15340. else
  15341. {
  15342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  15343. }
  15344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  15345. isKnowKey = TRUE;
  15346. }
  15347. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  15348. {
  15349. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  15350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  15351. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15352. {
  15353. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  15354. }
  15355. else
  15356. {
  15357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  15358. }
  15359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  15360. isKnowKey = TRUE;
  15361. }
  15362. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  15363. {
  15364. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  15365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  15366. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15367. {
  15368. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  15369. }
  15370. else
  15371. {
  15372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  15373. }
  15374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  15375. isKnowKey = TRUE;
  15376. }
  15377. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  15378. {
  15379. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  15380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  15381. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15382. {
  15383. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15384. }
  15385. else
  15386. {
  15387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15388. }
  15389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  15390. isKnowKey = TRUE;
  15391. }
  15392. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  15393. {
  15394. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  15395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  15396. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15397. {
  15398. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15399. }
  15400. else
  15401. {
  15402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15403. }
  15404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  15405. isKnowKey = TRUE;
  15406. }
  15407. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  15408. {
  15409. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  15410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  15411. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15412. {
  15413. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15414. }
  15415. else
  15416. {
  15417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15418. }
  15419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  15420. isKnowKey = TRUE;
  15421. }
  15422. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  15423. {
  15424. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  15425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  15426. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15427. {
  15428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  15429. }
  15430. else
  15431. {
  15432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  15433. }
  15434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  15435. isKnowKey = TRUE;
  15436. }
  15437. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  15438. {
  15439. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  15440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  15441. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15442. {
  15443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15444. }
  15445. else
  15446. {
  15447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15448. }
  15449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  15450. isKnowKey = TRUE;
  15451. }
  15452. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  15453. {
  15454. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  15455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  15456. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15457. {
  15458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  15459. }
  15460. else
  15461. {
  15462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  15463. }
  15464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  15465. isKnowKey = TRUE;
  15466. }
  15467. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  15468. {
  15469. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  15470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  15471. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15472. {
  15473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  15474. }
  15475. else
  15476. {
  15477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  15478. }
  15479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  15480. isKnowKey = TRUE;
  15481. }
  15482. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  15483. {
  15484. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  15485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  15486. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15487. {
  15488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  15489. }
  15490. else
  15491. {
  15492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15493. }
  15494. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15496. isKnowKey = TRUE;
  15497. }
  15498. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15499. {
  15500. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15502. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15503. {
  15504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15505. }
  15506. else
  15507. {
  15508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15509. }
  15510. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15511. isKnowKey = TRUE;
  15512. }
  15513. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15514. {
  15515. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15517. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15518. {
  15519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15520. }
  15521. else
  15522. {
  15523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15524. }
  15525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15526. isKnowKey = TRUE;
  15527. }
  15528. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15529. {
  15530. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15532. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15533. {
  15534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15535. }
  15536. else
  15537. {
  15538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15539. }
  15540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15541. isKnowKey = TRUE;
  15542. }
  15543. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15544. {
  15545. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15547. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15548. {
  15549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15550. }
  15551. else
  15552. {
  15553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15554. }
  15555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15556. isKnowKey = TRUE;
  15557. }
  15558. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15559. {
  15560. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15562. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15563. {
  15564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15565. }
  15566. else
  15567. {
  15568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15569. }
  15570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15571. isKnowKey = TRUE;
  15572. }
  15573. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15574. {
  15575. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15577. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15578. {
  15579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15580. }
  15581. else
  15582. {
  15583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15584. }
  15585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15586. isKnowKey = TRUE;
  15587. }
  15588. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15589. {
  15590. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15592. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15593. {
  15594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15595. }
  15596. else
  15597. {
  15598. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15599. }
  15600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15601. isKnowKey = TRUE;
  15602. }
  15603. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15604. {
  15605. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15607. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15608. {
  15609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15610. }
  15611. else
  15612. {
  15613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15614. }
  15615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15616. isKnowKey = TRUE;
  15617. }
  15618. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15619. {
  15620. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15622. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15623. {
  15624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15625. }
  15626. else
  15627. {
  15628. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15629. }
  15630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15631. isKnowKey = TRUE;
  15632. }
  15633. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15634. {
  15635. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15636. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15637. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15638. {
  15639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15640. }
  15641. else
  15642. {
  15643. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15644. }
  15645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15646. isKnowKey = TRUE;
  15647. }
  15648. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15649. {
  15650. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15651. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15652. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15653. {
  15654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15655. }
  15656. else
  15657. {
  15658. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15659. }
  15660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15661. isKnowKey = TRUE;
  15662. }
  15663. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15664. {
  15665. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15666. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15667. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15668. {
  15669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15670. }
  15671. else
  15672. {
  15673. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15674. }
  15675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15676. isKnowKey = TRUE;
  15677. }
  15678. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15679. {
  15680. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15681. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15682. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15683. {
  15684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15685. }
  15686. else
  15687. {
  15688. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15689. }
  15690. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15691. isKnowKey = TRUE;
  15692. }
  15693. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15694. {
  15695. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15696. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15697. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15698. {
  15699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15700. }
  15701. else
  15702. {
  15703. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15704. }
  15705. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15706. isKnowKey = TRUE;
  15707. }
  15708. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15709. {
  15710. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15711. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15712. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15713. {
  15714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15715. }
  15716. else
  15717. {
  15718. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15719. }
  15720. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15721. isKnowKey = TRUE;
  15722. }
  15723. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15724. {
  15725. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15726. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15727. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15728. {
  15729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15730. }
  15731. else
  15732. {
  15733. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15734. }
  15735. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15736. isKnowKey = TRUE;
  15737. }
  15738. /*
  15739. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15740. {
  15741. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15743. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15744. {
  15745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15746. }
  15747. else
  15748. {
  15749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15750. }
  15751. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15752. isKnowKey = TRUE;
  15753. }*/
  15754. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15755. {
  15756. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15758. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15759. {
  15760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15761. }
  15762. else
  15763. {
  15764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15765. }
  15766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15767. isKnowKey = TRUE;
  15768. }
  15769. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15770. {
  15771. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15772. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15773. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15774. {
  15775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15776. }
  15777. else
  15778. {
  15779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15780. }
  15781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15782. isKnowKey = TRUE;
  15783. }
  15784. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15785. {
  15786. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15787. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15788. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15789. {
  15790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15791. }
  15792. else
  15793. {
  15794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15795. }
  15796. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15797. isKnowKey = TRUE;
  15798. }
  15799. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15800. {
  15801. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15802. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15803. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15804. {
  15805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15806. }
  15807. else
  15808. {
  15809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15810. }
  15811. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15812. isKnowKey = TRUE;
  15813. }
  15814. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  15815. {
  15816. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  15817. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  15818. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15819. {
  15820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  15821. }
  15822. else
  15823. {
  15824. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  15825. }
  15826. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  15827. isKnowKey = TRUE;
  15828. }
  15829. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  15830. {
  15831. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  15832. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  15833. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15834. {
  15835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  15836. }
  15837. else
  15838. {
  15839. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  15840. }
  15841. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  15842. isKnowKey = TRUE;
  15843. }
  15844. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  15845. {
  15846. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  15847. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  15848. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15849. {
  15850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  15851. }
  15852. else
  15853. {
  15854. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  15855. }
  15856. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  15857. isKnowKey = TRUE;
  15858. }
  15859. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15860. {
  15861. struct sysinfo s_info;
  15862. int error = sysinfo(&s_info);
  15863. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15864. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15865. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15866. {
  15867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15868. }
  15869. else
  15870. {
  15871. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15872. }
  15873. if(error != 0)
  15874. {
  15875. DEBUG_WARN("System uptime get error: %d\n", error);
  15876. }
  15877. else
  15878. {
  15879. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15880. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15881. }
  15882. isKnowKey = TRUE;
  15883. }
  15884. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15885. {
  15886. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15887. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15888. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15889. {
  15890. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15891. }
  15892. else
  15893. {
  15894. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15895. }
  15896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  15897. isKnowKey = TRUE;
  15898. }
  15899. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  15900. {
  15901. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  15902. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  15903. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  15904. {
  15905. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  15906. }
  15907. else
  15908. {
  15909. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  15910. }
  15911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15912. isKnowKey = TRUE;
  15913. }
  15914. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15915. {
  15916. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15917. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15918. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15919. {
  15920. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15921. }
  15922. else
  15923. {
  15924. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15925. }
  15926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15927. isKnowKey = TRUE;
  15928. }
  15929. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15930. {
  15931. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15932. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15933. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15934. {
  15935. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15936. }
  15937. else
  15938. {
  15939. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15940. }
  15941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15942. isKnowKey = TRUE;
  15943. }
  15944. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15945. {
  15946. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15948. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15949. {
  15950. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15951. }
  15952. else
  15953. {
  15954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15955. }
  15956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15957. isKnowKey = TRUE;
  15958. }
  15959. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15960. {
  15961. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15962. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15963. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15964. {
  15965. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15966. }
  15967. else
  15968. {
  15969. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15970. }
  15971. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15972. isKnowKey = TRUE;
  15973. }
  15974. if(isEmpty || strcmp(keyReq, "PreAuthAmount") == 0 )
  15975. {
  15976. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PreAuthAmount].Item, "PreAuthAmount");
  15977. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Key, "PreAuthAmount");
  15978. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  15979. {
  15980. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "0"/*"FALSE"*/);
  15981. }
  15982. else
  15983. {
  15984. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "1"/*"TRUE"*/);
  15985. }
  15986. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData );
  15987. isKnowKey = TRUE;
  15988. }
  15989. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15990. {
  15991. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15992. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15993. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15994. {
  15995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15996. }
  15997. else
  15998. {
  15999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  16000. }
  16001. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  16002. isKnowKey = TRUE;
  16003. }
  16004. #if 1
  16005. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  16006. {
  16007. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  16008. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  16009. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16010. {
  16011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  16012. }
  16013. else
  16014. {
  16015. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  16016. }
  16017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  16018. isKnowKey = TRUE;
  16019. }
  16020. #endif
  16021. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  16022. {
  16023. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  16024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  16025. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16026. {
  16027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16028. }
  16029. else
  16030. {
  16031. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16032. }
  16033. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  16034. isKnowKey = TRUE;
  16035. }
  16036. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  16037. {
  16038. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  16039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  16040. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16041. {
  16042. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16043. }
  16044. else
  16045. {
  16046. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16047. }
  16048. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  16049. isKnowKey = TRUE;
  16050. }
  16051. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  16052. {
  16053. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  16054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  16055. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16056. {
  16057. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  16058. }
  16059. else
  16060. {
  16061. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  16062. }
  16063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16064. isKnowKey = TRUE;
  16065. }
  16066. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  16067. {
  16068. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  16069. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  16070. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16071. {
  16072. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  16073. }
  16074. else
  16075. {
  16076. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  16077. }
  16078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16079. isKnowKey = TRUE;
  16080. }
  16081. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  16082. {
  16083. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  16084. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  16085. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16086. {
  16087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  16088. }
  16089. else
  16090. {
  16091. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  16092. }
  16093. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16094. isKnowKey = TRUE;
  16095. }
  16096. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  16097. {
  16098. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  16099. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  16100. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16101. {
  16102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  16103. }
  16104. else
  16105. {
  16106. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  16107. }
  16108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16109. isKnowKey = TRUE;
  16110. }
  16111. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  16112. {
  16113. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  16114. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  16115. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16116. {
  16117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  16118. }
  16119. else
  16120. {
  16121. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  16122. }
  16123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16124. isKnowKey = TRUE;
  16125. }
  16126. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  16127. {
  16128. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  16129. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  16130. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16131. {
  16132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  16133. }
  16134. else
  16135. {
  16136. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  16137. }
  16138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16139. isKnowKey = TRUE;
  16140. }
  16141. //=========================================================
  16142. if(!isEmpty && !isKnowKey)
  16143. {
  16144. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  16145. strcpy(unknownkey[UnknownKeynum], keyReq);
  16146. UnknownKeynum = UnknownKeynum + 1;
  16147. }
  16148. }
  16149. void processUnkownKey(void)
  16150. {
  16151. DEBUG_INFO("processUnkownKey...\n");
  16152. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  16153. for(int index=0; index < UnknownKeynum; index++)
  16154. {
  16155. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  16156. {
  16157. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  16158. }
  16159. }
  16160. }
  16161. int setKeyValue(char *key, char *value)
  16162. {
  16163. int isSuccess = NotSupported;
  16164. int check_ascii=0;
  16165. char str[501]={0};
  16166. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  16167. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  16168. {
  16169. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  16170. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16171. {
  16172. strcpy(str, (const char*)value);
  16173. for(int i = 0; str[i]; i++){
  16174. str[i] = tolower(str[i]);
  16175. }
  16176. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16177. isSuccess = ConfigurationStatus_Accepted;
  16178. }
  16179. else
  16180. {
  16181. isSuccess = ConfigurationStatus_Rejected;
  16182. }
  16183. }
  16184. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  16185. {
  16186. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  16187. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16188. {
  16189. strcpy(str, (const char*)value);
  16190. for(int i = 0; str[i]; i++){
  16191. str[i] = tolower(str[i]);
  16192. }
  16193. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16194. isSuccess = ConfigurationStatus_Accepted;
  16195. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  16196. }
  16197. else
  16198. {
  16199. isSuccess = ConfigurationStatus_Rejected;
  16200. }
  16201. }
  16202. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  16203. {
  16204. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16205. {
  16206. strcpy(str, (const char*)value);
  16207. for(int i = 0; str[i]; i++)
  16208. {
  16209. str[i] = tolower(str[i]);
  16210. }
  16211. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  16212. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16213. isSuccess = ConfigurationStatus_Accepted;
  16214. }
  16215. else
  16216. {
  16217. isSuccess = ConfigurationStatus_Rejected;
  16218. }
  16219. }
  16220. if(strcmp(key, "BlinkRepeat") == 0)
  16221. {
  16222. //Charger.BlinkRepeat = Integer.parseInt(value);
  16223. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16224. {
  16225. check_ascii = value[0];
  16226. if( (check_ascii < 48) || (check_ascii > 57) )
  16227. {
  16228. isSuccess = ConfigurationStatus_Rejected;
  16229. }
  16230. else
  16231. {
  16232. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  16233. isSuccess = ConfigurationStatus_Accepted;
  16234. }
  16235. }
  16236. else
  16237. {
  16238. isSuccess = ConfigurationStatus_Rejected;
  16239. }
  16240. }
  16241. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  16242. {
  16243. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16244. {
  16245. check_ascii = value[0];
  16246. if( (check_ascii < 48) || (check_ascii > 57) )
  16247. {
  16248. isSuccess = ConfigurationStatus_Rejected;
  16249. }
  16250. else
  16251. {
  16252. if((atoi(value) == 0) || (atoi(value) >= 5))
  16253. {
  16254. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  16255. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  16256. isSuccess = ConfigurationStatus_Accepted;
  16257. }
  16258. else
  16259. isSuccess = ConfigurationStatus_Rejected;
  16260. }
  16261. }
  16262. else
  16263. {
  16264. isSuccess = ConfigurationStatus_Rejected;
  16265. }
  16266. }
  16267. if(strcmp(key, "ConnectionTimeOut") == 0 )
  16268. {
  16269. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  16270. {
  16271. check_ascii = value[0];
  16272. if( (check_ascii < 48) || (check_ascii > 57) )
  16273. {
  16274. isSuccess = ConfigurationStatus_Rejected;
  16275. }
  16276. else
  16277. {
  16278. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  16279. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  16280. isSuccess = ConfigurationStatus_Accepted;
  16281. }
  16282. }
  16283. else
  16284. {
  16285. isSuccess = ConfigurationStatus_Rejected;
  16286. }
  16287. }
  16288. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  16289. {
  16290. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  16291. {
  16292. check_ascii = value[0];
  16293. if( (check_ascii < 48) || (check_ascii > 57) )
  16294. {
  16295. isSuccess = ConfigurationStatus_Rejected;
  16296. }
  16297. else
  16298. {
  16299. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16300. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  16301. isSuccess = ConfigurationStatus_Accepted;
  16302. }
  16303. }
  16304. else
  16305. {
  16306. isSuccess = ConfigurationStatus_Rejected;
  16307. }
  16308. }
  16309. if(strcmp(key, "HeartbeatInterval") == 0)
  16310. {
  16311. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  16312. {
  16313. check_ascii = value[0];
  16314. if( (check_ascii < 48) || (check_ascii > 57) )
  16315. {
  16316. isSuccess = ConfigurationStatus_Rejected;
  16317. }
  16318. else
  16319. {
  16320. if((atoi(value) == 0) || (atoi(value) >= 10))
  16321. {
  16322. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16323. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  16324. HeartBeatWaitTime = atoi(value);
  16325. isSuccess = ConfigurationStatus_Accepted;
  16326. }
  16327. else
  16328. {
  16329. isSuccess = ConfigurationStatus_Rejected;
  16330. }
  16331. }
  16332. }
  16333. else
  16334. {
  16335. isSuccess = ConfigurationStatus_Rejected;
  16336. }
  16337. }
  16338. if(strcmp(key, "LightIntensity") == 0)
  16339. {
  16340. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16341. {
  16342. check_ascii = value[0];
  16343. if( (check_ascii < 48) || (check_ascii > 57) )
  16344. {
  16345. isSuccess = ConfigurationStatus_Rejected;
  16346. }
  16347. else
  16348. {
  16349. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  16350. isSuccess = ConfigurationStatus_Accepted;
  16351. }
  16352. }
  16353. else
  16354. {
  16355. isSuccess = ConfigurationStatus_Rejected;
  16356. }
  16357. }
  16358. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  16359. {
  16360. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  16361. {
  16362. strcpy(str, (const char*)value);
  16363. for(int i = 0; str[i]; i++)
  16364. {
  16365. str[i] = tolower(str[i]);
  16366. }
  16367. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16368. isSuccess = ConfigurationStatus_Accepted;
  16369. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16370. }
  16371. else
  16372. {
  16373. isSuccess = ConfigurationStatus_Rejected;
  16374. }
  16375. }
  16376. if(strcmp(key, "LocalPreAuthorize") == 0)
  16377. {
  16378. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16379. {
  16380. strcpy(str, (const char*)value);
  16381. for(int i = 0; str[i]; i++)
  16382. {
  16383. str[i] = tolower(str[i]);
  16384. }
  16385. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16386. isSuccess = ConfigurationStatus_Accepted;
  16387. }
  16388. else
  16389. {
  16390. isSuccess = ConfigurationStatus_Rejected;
  16391. }
  16392. }
  16393. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  16394. {
  16395. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  16396. {
  16397. check_ascii = value[0];
  16398. if( (check_ascii < 48) || (check_ascii > 57) )
  16399. {
  16400. isSuccess = ConfigurationStatus_Rejected;
  16401. }
  16402. else
  16403. {
  16404. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  16405. isSuccess = ConfigurationStatus_Accepted;
  16406. }
  16407. }
  16408. else
  16409. {
  16410. isSuccess = ConfigurationStatus_Rejected;
  16411. }
  16412. }
  16413. if(strcmp(key, "MeterValuesAlignedData") == 0)
  16414. {
  16415. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  16416. {
  16417. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  16418. isSuccess = ConfigurationStatus_Accepted;
  16419. }
  16420. else
  16421. {
  16422. isSuccess = ConfigurationStatus_Rejected;
  16423. }
  16424. }
  16425. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  16426. {
  16427. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  16428. {
  16429. check_ascii = value[0];
  16430. if( (check_ascii < 48) || (check_ascii > 57) )
  16431. {
  16432. isSuccess = ConfigurationStatus_Rejected;
  16433. }
  16434. else
  16435. {
  16436. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16437. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  16438. isSuccess = ConfigurationStatus_Accepted;
  16439. }
  16440. }
  16441. else
  16442. {
  16443. isSuccess = ConfigurationStatus_Rejected;
  16444. }
  16445. }
  16446. if(strcmp(key, "MeterValuesSampledData") == 0 )
  16447. {
  16448. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  16449. {
  16450. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  16451. isSuccess = ConfigurationStatus_Accepted;
  16452. }
  16453. else
  16454. {
  16455. isSuccess = ConfigurationStatus_Rejected;
  16456. }
  16457. }
  16458. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  16459. {
  16460. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16461. {
  16462. check_ascii = value[0];
  16463. if( (check_ascii < 48) || (check_ascii > 57) )
  16464. {
  16465. isSuccess = ConfigurationStatus_Rejected;
  16466. }
  16467. else
  16468. {
  16469. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16470. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  16471. isSuccess = ConfigurationStatus_Accepted;
  16472. }
  16473. }
  16474. else
  16475. {
  16476. isSuccess = ConfigurationStatus_Rejected;
  16477. }
  16478. }
  16479. if(strcmp(key, "MeterValueSampleInterval") == 0)
  16480. {
  16481. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16482. {
  16483. check_ascii = value[0];
  16484. if( (check_ascii < 48) || (check_ascii > 57) )
  16485. {
  16486. isSuccess = ConfigurationStatus_Rejected;
  16487. }
  16488. else
  16489. {
  16490. if((atoi(value) == 0) || (atoi(value) >= 3))
  16491. {
  16492. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16493. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  16494. isSuccess = ConfigurationStatus_Accepted;
  16495. }
  16496. else
  16497. {
  16498. isSuccess = ConfigurationStatus_Rejected;
  16499. }
  16500. }
  16501. }
  16502. else
  16503. {
  16504. isSuccess = ConfigurationStatus_Rejected;
  16505. }
  16506. }
  16507. if(strcmp(key, "MinimumStatusDuration") == 0)
  16508. {
  16509. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16510. {
  16511. check_ascii = value[0];
  16512. if( (check_ascii < 48) || (check_ascii > 57) )
  16513. {
  16514. isSuccess = ConfigurationStatus_Rejected;
  16515. }
  16516. else
  16517. {
  16518. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  16519. {
  16520. isSuccess = ConfigurationStatus_Rejected;
  16521. }
  16522. else
  16523. {
  16524. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16525. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16526. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16527. isSuccess = ConfigurationStatus_Accepted;
  16528. }
  16529. }
  16530. }
  16531. else
  16532. {
  16533. isSuccess = ConfigurationStatus_Rejected;
  16534. }
  16535. }
  16536. if(strcmp(key, "NumberOfConnectors") == 0)
  16537. {
  16538. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16539. {
  16540. check_ascii = value[0];
  16541. if( (check_ascii < 48) || (check_ascii > 57) )
  16542. {
  16543. isSuccess = ConfigurationStatus_Rejected;
  16544. }
  16545. else
  16546. {
  16547. //Charger.ResetRetries = Integer.parseInt(value);
  16548. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16549. isSuccess = ConfigurationStatus_Accepted;
  16550. }
  16551. }
  16552. else
  16553. {
  16554. isSuccess = ConfigurationStatus_Rejected;
  16555. }
  16556. }
  16557. if(strcmp(key, "ResetRetries") == 0)
  16558. {
  16559. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16560. {
  16561. check_ascii = value[0];
  16562. if( (check_ascii < 48) || (check_ascii > 57) )
  16563. {
  16564. isSuccess = ConfigurationStatus_Rejected;
  16565. }
  16566. else
  16567. {
  16568. //Charger.ResetRetries = Integer.parseInt(value);
  16569. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16570. isSuccess = ConfigurationStatus_Accepted;
  16571. }
  16572. }
  16573. else
  16574. {
  16575. isSuccess = ConfigurationStatus_Rejected;
  16576. }
  16577. }
  16578. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16579. {
  16580. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16581. {
  16582. strcpy(str, (const char*)value);
  16583. for(int i = 0; str[i]; i++)
  16584. {
  16585. str[i] = tolower(str[i]);
  16586. }
  16587. if(strcmp(str, "notapplicable")== 0)
  16588. {
  16589. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16590. isSuccess = ConfigurationStatus_Accepted;
  16591. }
  16592. else if(strcmp(str, "unknown")== 0)
  16593. {
  16594. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16595. isSuccess = ConfigurationStatus_Accepted;
  16596. }
  16597. else if(strcmp(str, "rst")== 0)
  16598. {
  16599. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16600. isSuccess = ConfigurationStatus_Accepted;
  16601. }
  16602. else if(strcmp(str, "rts")== 0)
  16603. {
  16604. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16605. isSuccess = ConfigurationStatus_Accepted;
  16606. }
  16607. else if(strcmp(str, "srt")== 0)
  16608. {
  16609. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16610. isSuccess = ConfigurationStatus_Accepted;
  16611. }
  16612. else if(strcmp(str, "str")== 0)
  16613. {
  16614. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16615. isSuccess = ConfigurationStatus_Accepted;
  16616. }
  16617. else if(strcmp(str, "trs")== 0)
  16618. {
  16619. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16620. isSuccess = ConfigurationStatus_Accepted;
  16621. }
  16622. else if(strcmp(str, "tsr")== 0)
  16623. {
  16624. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16625. isSuccess = ConfigurationStatus_Accepted;
  16626. }
  16627. else
  16628. {
  16629. isSuccess = ConfigurationStatus_Rejected;
  16630. }
  16631. }
  16632. else
  16633. {
  16634. isSuccess = ConfigurationStatus_Rejected;
  16635. }
  16636. }
  16637. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16638. {
  16639. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16640. {
  16641. check_ascii = value[0];
  16642. if( (check_ascii < 48) || (check_ascii > 57) )
  16643. {
  16644. isSuccess = ConfigurationStatus_Rejected;
  16645. }
  16646. else
  16647. {
  16648. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16649. isSuccess = ConfigurationStatus_Accepted;
  16650. }
  16651. }
  16652. else
  16653. {
  16654. isSuccess = ConfigurationStatus_Rejected;
  16655. }
  16656. }
  16657. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16658. {
  16659. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16660. {
  16661. strcpy(str, (const char*)value);
  16662. for(int i = 0; str[i]; i++)
  16663. {
  16664. str[i] = tolower(str[i]);
  16665. }
  16666. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16667. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16668. isSuccess = ConfigurationStatus_Accepted;
  16669. }
  16670. else
  16671. {
  16672. isSuccess = ConfigurationStatus_Rejected;
  16673. }
  16674. }
  16675. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16676. {
  16677. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16678. {
  16679. strcpy(str, (const char*)value);
  16680. for(int i = 0; str[i]; i++)
  16681. {
  16682. str[i] = tolower(str[i]);
  16683. }
  16684. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16685. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16686. isSuccess = ConfigurationStatus_Accepted;
  16687. }
  16688. else
  16689. {
  16690. isSuccess = ConfigurationStatus_Rejected;
  16691. }
  16692. }
  16693. if(strcmp(key, "StopTxnAlignedData") == 0)
  16694. {
  16695. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16696. {
  16697. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16698. isSuccess = ConfigurationStatus_Accepted;
  16699. }
  16700. else
  16701. {
  16702. isSuccess = ConfigurationStatus_Rejected;
  16703. }
  16704. }
  16705. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16706. {
  16707. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16708. {
  16709. check_ascii = value[0];
  16710. if( (check_ascii < 48) || (check_ascii > 57) )
  16711. {
  16712. isSuccess = ConfigurationStatus_Rejected;
  16713. }
  16714. else
  16715. {
  16716. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16717. isSuccess = ConfigurationStatus_Accepted;
  16718. }
  16719. }
  16720. else
  16721. {
  16722. isSuccess = ConfigurationStatus_Rejected;
  16723. }
  16724. }
  16725. if(strcmp(key, "StopTxnSampledData") == 0)
  16726. {
  16727. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16728. {
  16729. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16730. isSuccess = ConfigurationStatus_Accepted;
  16731. }
  16732. else
  16733. {
  16734. isSuccess = ConfigurationStatus_Rejected;
  16735. }
  16736. }
  16737. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16738. {
  16739. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16740. {
  16741. check_ascii = value[0];
  16742. if( (check_ascii < 48) || (check_ascii > 57) )
  16743. {
  16744. isSuccess = ConfigurationStatus_Rejected;
  16745. }
  16746. else
  16747. {
  16748. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16749. isSuccess = ConfigurationStatus_Accepted;
  16750. }
  16751. }
  16752. else
  16753. {
  16754. isSuccess = ConfigurationStatus_Rejected;
  16755. }
  16756. }
  16757. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16758. {
  16759. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16760. {
  16761. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16762. isSuccess = ConfigurationStatus_Accepted;
  16763. }
  16764. else
  16765. {
  16766. isSuccess = ConfigurationStatus_Rejected;
  16767. }
  16768. }
  16769. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16770. {
  16771. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16772. {
  16773. check_ascii = value[0];
  16774. if( (check_ascii < 48) || (check_ascii > 57) )
  16775. {
  16776. isSuccess = ConfigurationStatus_Rejected;
  16777. }
  16778. else
  16779. {
  16780. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16781. isSuccess = ConfigurationStatus_Accepted;
  16782. }
  16783. }
  16784. else
  16785. {
  16786. isSuccess = ConfigurationStatus_Rejected;
  16787. }
  16788. }
  16789. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16790. {
  16791. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16792. {
  16793. check_ascii = value[0];
  16794. if( (check_ascii < 48) || (check_ascii > 57) )
  16795. {
  16796. isSuccess = ConfigurationStatus_Rejected;
  16797. }
  16798. else
  16799. {
  16800. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16801. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16802. TransactionMessageAttemptsValue = atoi(value);
  16803. isSuccess = ConfigurationStatus_Accepted;
  16804. }
  16805. }
  16806. else
  16807. {
  16808. isSuccess = ConfigurationStatus_Rejected;
  16809. }
  16810. }
  16811. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16812. {
  16813. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16814. {
  16815. check_ascii = value[0];
  16816. if( (check_ascii < 48) || (check_ascii > 57) )
  16817. {
  16818. isSuccess = ConfigurationStatus_Rejected;
  16819. }
  16820. else
  16821. {
  16822. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16823. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16824. TransactionMessageRetryIntervalValue = atoi(value);
  16825. isSuccess = ConfigurationStatus_Accepted;
  16826. }
  16827. }
  16828. else
  16829. {
  16830. isSuccess = ConfigurationStatus_Rejected;
  16831. }
  16832. }
  16833. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16834. {
  16835. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16836. {
  16837. strcpy(str, (const char*)value);
  16838. for(int i = 0; str[i]; i++)
  16839. {
  16840. str[i] = tolower(str[i]);
  16841. }
  16842. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16843. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16844. isSuccess = ConfigurationStatus_Accepted;
  16845. }
  16846. else
  16847. {
  16848. isSuccess = ConfigurationStatus_Rejected;
  16849. }
  16850. }
  16851. if(strcmp(key, "WebSocketPingInterval") == 0)
  16852. {
  16853. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16854. {
  16855. check_ascii = value[0];
  16856. if( (check_ascii < 48) || (check_ascii > 57) )
  16857. {
  16858. isSuccess = ConfigurationStatus_Rejected;
  16859. }
  16860. else
  16861. {
  16862. if((atoi(value) == 0) || (atoi(value) >= 10))
  16863. {
  16864. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16865. isSuccess = ConfigurationStatus_Accepted;
  16866. }
  16867. else
  16868. isSuccess = ConfigurationStatus_Rejected;
  16869. }
  16870. }
  16871. else
  16872. {
  16873. isSuccess = ConfigurationStatus_Rejected;
  16874. }
  16875. }
  16876. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16877. {
  16878. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16879. {
  16880. strcpy(str, (const char*)value);
  16881. for(int i = 0; str[i]; i++)
  16882. {
  16883. str[i] = tolower(str[i]);
  16884. }
  16885. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16886. isSuccess = ConfigurationStatus_Accepted;
  16887. }
  16888. else
  16889. {
  16890. isSuccess = ConfigurationStatus_Rejected;
  16891. }
  16892. }
  16893. if(strcmp(key, "AuthorizationKey") == 0)
  16894. {
  16895. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16896. {
  16897. strcpy(str, (const char*)value);
  16898. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16899. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16900. isSuccess = ConfigurationStatus_Accepted;
  16901. }
  16902. else
  16903. {
  16904. isSuccess = ConfigurationStatus_Rejected;
  16905. }
  16906. }
  16907. if(strcmp(key, "SecurityProfile") == 0)
  16908. {
  16909. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16910. {
  16911. check_ascii = value[0];
  16912. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16913. {
  16914. isSuccess = ConfigurationStatus_Rejected;
  16915. }
  16916. else if(check_ascii == 0x33)
  16917. {
  16918. isSuccess = NotSupported;
  16919. }
  16920. else
  16921. {
  16922. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16923. {
  16924. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16925. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  16926. isSuccess = ConfigurationStatus_Accepted;
  16927. }
  16928. else
  16929. isSuccess = ConfigurationStatus_Rejected;
  16930. }
  16931. }
  16932. else
  16933. {
  16934. isSuccess = ConfigurationStatus_Rejected;
  16935. }
  16936. }
  16937. if(strcmp(key, "DefaultPrice") == 0)
  16938. {
  16939. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16940. {
  16941. strcpy(str, (const char*)value);
  16942. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16943. isSuccess = ConfigurationStatus_Accepted;
  16944. }
  16945. else
  16946. {
  16947. isSuccess = ConfigurationStatus_Rejected;
  16948. }
  16949. }
  16950. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16951. {
  16952. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16953. {
  16954. strcpy(str, (const char*)value);
  16955. for(int i = 0; str[i]; i++)
  16956. {
  16957. str[i] = tolower(str[i]);
  16958. }
  16959. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16960. isSuccess = ConfigurationStatus_Accepted;
  16961. }
  16962. else
  16963. {
  16964. isSuccess = ConfigurationStatus_Rejected;
  16965. }
  16966. }
  16967. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16968. {
  16969. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16970. {
  16971. strcpy(str, (const char*)value);
  16972. for(int i = 0; str[i]; i++)
  16973. {
  16974. str[i] = tolower(str[i]);
  16975. }
  16976. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16977. isSuccess = ConfigurationStatus_Accepted;
  16978. }
  16979. else
  16980. {
  16981. isSuccess = ConfigurationStatus_Rejected;
  16982. }
  16983. }
  16984. if(strcmp(key, "TimeOffset") == 0)
  16985. {
  16986. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  16987. {
  16988. strcpy(str, (const char*)value);
  16989. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  16990. isSuccess = ConfigurationStatus_Accepted;
  16991. }
  16992. else
  16993. {
  16994. isSuccess = ConfigurationStatus_Rejected;
  16995. }
  16996. }
  16997. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  16998. {
  16999. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  17000. {
  17001. strcpy(str, (const char*)value);
  17002. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  17003. isSuccess = ConfigurationStatus_Accepted;
  17004. }
  17005. else
  17006. {
  17007. isSuccess = ConfigurationStatus_Rejected;
  17008. }
  17009. }
  17010. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  17011. {
  17012. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  17013. {
  17014. strcpy(str, (const char*)value);
  17015. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  17016. isSuccess = ConfigurationStatus_Accepted;
  17017. }
  17018. else
  17019. {
  17020. isSuccess = ConfigurationStatus_Rejected;
  17021. }
  17022. }
  17023. if(strcmp(key, "SystemUptimeSec") == 0)
  17024. {
  17025. isSuccess = NotSupported;
  17026. }
  17027. if(strcmp(key, "FreeVend") == 0)
  17028. {
  17029. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17030. {
  17031. strcpy(str, (const char*)value);
  17032. for(int i = 0; str[i]; i++)
  17033. {
  17034. str[i] = tolower(str[i]);
  17035. }
  17036. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  17037. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17038. isSuccess = ConfigurationStatus_Accepted;
  17039. }
  17040. else
  17041. {
  17042. isSuccess = ConfigurationStatus_Rejected;
  17043. }
  17044. }
  17045. if(strcmp(key, "FreeVendIdtag") == 0)
  17046. {
  17047. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17048. {
  17049. strcpy(str, (const char*)value);
  17050. if(strlen(str) <= 20)
  17051. {
  17052. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  17053. isSuccess = ConfigurationStatus_Accepted;
  17054. }
  17055. else
  17056. {
  17057. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  17058. isSuccess = ConfigurationStatus_Rejected;
  17059. }
  17060. }
  17061. else
  17062. {
  17063. isSuccess = ConfigurationStatus_Rejected;
  17064. }
  17065. }
  17066. if(strcmp(key, "OcppServer") == 0)
  17067. {
  17068. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17069. {
  17070. strcpy(str, (const char*)value);
  17071. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  17072. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  17073. isSuccess = ConfigurationStatus_Accepted;
  17074. }
  17075. else
  17076. {
  17077. isSuccess = ConfigurationStatus_Rejected;
  17078. }
  17079. }
  17080. if(strcmp(key, "MaintainServer") == 0)
  17081. {
  17082. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17083. {
  17084. strcpy(str, (const char*)value);
  17085. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  17086. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  17087. isSuccess = ConfigurationStatus_Accepted;
  17088. }
  17089. else
  17090. {
  17091. isSuccess = ConfigurationStatus_Rejected;
  17092. }
  17093. }
  17094. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  17095. {
  17096. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17097. {
  17098. strcpy(str, (const char*)value);
  17099. for(int i = 0; str[i]; i++)
  17100. {
  17101. str[i] = tolower(str[i]);
  17102. }
  17103. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  17104. isSuccess = ConfigurationStatus_Accepted;
  17105. }
  17106. else
  17107. {
  17108. isSuccess = ConfigurationStatus_Rejected;
  17109. }
  17110. }
  17111. if(strcmp(key, "StatusNotificationInterval") == 0)
  17112. {
  17113. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17114. {
  17115. check_ascii = value[0];
  17116. if( (check_ascii < 48) || (check_ascii > 57) )
  17117. {
  17118. isSuccess = ConfigurationStatus_Rejected;
  17119. }
  17120. else
  17121. {
  17122. if((atoi(value) == 0) || (atoi(value) >= 10))
  17123. {
  17124. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  17125. isSuccess = ConfigurationStatus_Accepted;
  17126. }
  17127. else
  17128. isSuccess = ConfigurationStatus_Rejected;
  17129. }
  17130. }
  17131. else
  17132. {
  17133. isSuccess = ConfigurationStatus_Rejected;
  17134. }
  17135. }
  17136. if(strcmp(key, "PreAuthAmount") == 0)
  17137. {
  17138. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  17139. {
  17140. check_ascii = value[0];
  17141. if( (check_ascii < 48) || (check_ascii > 57) )
  17142. {
  17143. isSuccess = ConfigurationStatus_Rejected;
  17144. }
  17145. else
  17146. {
  17147. if(atof(value) >= 0)
  17148. {
  17149. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(value) );
  17150. isSuccess = ConfigurationStatus_Accepted;
  17151. }
  17152. else
  17153. isSuccess = ConfigurationStatus_Rejected;
  17154. }
  17155. }
  17156. else
  17157. {
  17158. isSuccess = ConfigurationStatus_Rejected;
  17159. }
  17160. }
  17161. #if 0
  17162. //For OCPP Test Case
  17163. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  17164. {
  17165. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17166. {
  17167. strcpy(str, (const char*)value);
  17168. for(int i = 0; str[i]; i++)
  17169. {
  17170. str[i] = tolower(str[i]);
  17171. }
  17172. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17173. isSuccess = ConfigurationStatus_Accepted;
  17174. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17175. }
  17176. else
  17177. {
  17178. isSuccess = ConfigurationStatus_Rejected;
  17179. }
  17180. }
  17181. #endif
  17182. #if 1
  17183. if(strcmp(key, "LocalAuthListEnabled") == 0)
  17184. {
  17185. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17186. {
  17187. strcpy(str, (const char*)value);
  17188. for(int i = 0; str[i]; i++)
  17189. {
  17190. str[i] = tolower(str[i]);
  17191. }
  17192. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17193. isSuccess = ConfigurationStatus_Accepted;
  17194. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17195. }
  17196. else
  17197. {
  17198. isSuccess = ConfigurationStatus_Rejected;
  17199. }
  17200. }
  17201. #endif
  17202. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  17203. {
  17204. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  17205. {
  17206. check_ascii = value[0];
  17207. if( (check_ascii < 48) || (check_ascii > 57) )
  17208. {
  17209. isSuccess = ConfigurationStatus_Rejected;
  17210. }
  17211. else
  17212. {
  17213. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  17214. isSuccess = ConfigurationStatus_Accepted;
  17215. }
  17216. }
  17217. else
  17218. {
  17219. isSuccess = ConfigurationStatus_Rejected;
  17220. }
  17221. }
  17222. if(strcmp(key, "SendLocalListMaxLength") == 0)
  17223. {
  17224. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17225. {
  17226. check_ascii = value[0];
  17227. if( (check_ascii < 48) || (check_ascii > 57) )
  17228. {
  17229. isSuccess = ConfigurationStatus_Rejected;
  17230. }
  17231. else
  17232. {
  17233. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  17234. isSuccess = ConfigurationStatus_Accepted;
  17235. }
  17236. }
  17237. else
  17238. {
  17239. isSuccess = ConfigurationStatus_Rejected;
  17240. }
  17241. }
  17242. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  17243. {
  17244. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17245. {
  17246. strcpy(str, (const char*)value);
  17247. for(int i = 0; str[i]; i++)
  17248. {
  17249. str[i] = tolower(str[i]);
  17250. }
  17251. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17252. isSuccess = ConfigurationStatus_Accepted;
  17253. }
  17254. else
  17255. {
  17256. isSuccess = ConfigurationStatus_Rejected;
  17257. }
  17258. }
  17259. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  17260. {
  17261. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17262. {
  17263. check_ascii = value[0];
  17264. if( (check_ascii < 48) || (check_ascii > 57) )
  17265. {
  17266. isSuccess = ConfigurationStatus_Rejected;
  17267. }
  17268. else
  17269. {
  17270. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  17271. isSuccess = ConfigurationStatus_Accepted;
  17272. }
  17273. }
  17274. else
  17275. {
  17276. isSuccess = ConfigurationStatus_Rejected;
  17277. }
  17278. }
  17279. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  17280. {
  17281. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17282. {
  17283. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  17284. isSuccess = ConfigurationStatus_Accepted;
  17285. }
  17286. else
  17287. {
  17288. isSuccess = ConfigurationStatus_Rejected;
  17289. }
  17290. }
  17291. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  17292. {
  17293. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17294. {
  17295. check_ascii = value[0];
  17296. if( (check_ascii < 48) || (check_ascii > 57) )
  17297. {
  17298. isSuccess = ConfigurationStatus_Rejected;
  17299. }
  17300. else
  17301. {
  17302. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  17303. isSuccess = ConfigurationStatus_Accepted;
  17304. }
  17305. }
  17306. else
  17307. {
  17308. isSuccess = ConfigurationStatus_Rejected;
  17309. }
  17310. }
  17311. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  17312. {
  17313. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17314. {
  17315. strcpy(str, (const char*)value);
  17316. for(int i = 0; str[i]; i++)
  17317. {
  17318. str[i] = tolower(str[i]);
  17319. }
  17320. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17321. isSuccess = ConfigurationStatus_Accepted;
  17322. }
  17323. else
  17324. {
  17325. isSuccess = ConfigurationStatus_Rejected;
  17326. }
  17327. }
  17328. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  17329. {
  17330. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  17331. {
  17332. check_ascii = value[0];
  17333. if( (check_ascii < 48) || (check_ascii > 57) )
  17334. {
  17335. isSuccess = ConfigurationStatus_Rejected;
  17336. }
  17337. else
  17338. {
  17339. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  17340. isSuccess = ConfigurationStatus_Accepted;
  17341. }
  17342. }
  17343. else
  17344. {
  17345. isSuccess = ConfigurationStatus_Rejected;
  17346. }
  17347. }
  17348. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17349. return isSuccess;
  17350. }
  17351. int TransactionMessageAttemptsGet(void)
  17352. {
  17353. return TransactionMessageAttemptsValue;
  17354. }
  17355. int FirstHeartBeatResponse(void)
  17356. {
  17357. return FirstHeartBeat;
  17358. }
  17359. int TransactionMessageRetryIntervalGet(void)
  17360. {
  17361. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17362. }
  17363. int ReadHttpStatus(int sock)
  17364. {
  17365. //char c;
  17366. char buff[1024]="",*ptr=buff+1;
  17367. int bytes_received, status;
  17368. DEBUG_INFO("Begin Response ..\n");
  17369. while((bytes_received = recv(sock, ptr, 1, 0))){
  17370. if(bytes_received==-1){
  17371. perror("ReadHttpStatus");
  17372. exit(1);
  17373. }
  17374. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  17375. ptr++;
  17376. }
  17377. *ptr=0;
  17378. ptr=buff+1;
  17379. sscanf(ptr,"%*s %d ", &status);
  17380. DEBUG_INFO("%s\n",ptr);
  17381. DEBUG_INFO("status=%d\n",status);
  17382. DEBUG_INFO("End Response ..\n");
  17383. return (bytes_received>0)?status:0;
  17384. }
  17385. //the only filed that it parsed is 'Content-Length'
  17386. int ParseHeader(int sock)
  17387. {
  17388. //char c;
  17389. char buff[1024]="",*ptr=buff+4;
  17390. int bytes_received;
  17391. DEBUG_INFO("Begin HEADER ..\n");
  17392. while((bytes_received = recv(sock, ptr, 1, 0))){
  17393. if(bytes_received==-1){
  17394. perror("Parse Header");
  17395. exit(1);
  17396. }
  17397. if(
  17398. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  17399. (ptr[-1]=='\r') && (*ptr=='\n' )
  17400. ) break;
  17401. ptr++;
  17402. }
  17403. *ptr=0;
  17404. ptr=buff+4;
  17405. //printf("%s",ptr);
  17406. if(bytes_received){
  17407. ptr=strstr(ptr,"Content-Length:");
  17408. if(ptr){
  17409. sscanf(ptr,"%*s %d",&bytes_received);
  17410. }else
  17411. bytes_received=-1; //unknown size
  17412. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  17413. }
  17414. DEBUG_INFO("End HEADER ..\n");
  17415. return bytes_received ;
  17416. }
  17417. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  17418. {
  17419. int result = TRUE;
  17420. char rmFileCmd[100]={0};
  17421. char FilePath[100]={0};
  17422. char ftpbuf[200];
  17423. int systemresult;
  17424. sprintf(FilePath,"/mnt/%s",filename);
  17425. system("ping 8.8.8.8 &");
  17426. if((access(FilePath,F_OK))!=-1)
  17427. {
  17428. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17429. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17430. system(rmFileCmd);
  17431. }
  17432. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17433. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  17434. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17435. systemresult = system(ftpbuf);
  17436. if(systemresult != 0)
  17437. {
  17438. DEBUG_INFO("http DownLoad error!\n");
  17439. result = FALSE;
  17440. }
  17441. system("pkill ping");
  17442. return result;
  17443. }
  17444. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  17445. {
  17446. int result = TRUE;
  17447. char rmFileCmd[100]={0};
  17448. char FilePath[100]={0};
  17449. char ftpbuf[200];
  17450. int systemresult;
  17451. sprintf(FilePath,"/mnt/%s",filename);
  17452. system("ping 8.8.8.8 &");
  17453. if((access(FilePath,F_OK))!=-1)
  17454. {
  17455. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17456. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17457. system(rmFileCmd);
  17458. }
  17459. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17460. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  17461. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17462. systemresult = system(ftpbuf);
  17463. if(systemresult != 0)
  17464. {
  17465. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  17466. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17467. systemresult = system(ftpbuf);
  17468. if(systemresult != 0)
  17469. {
  17470. DEBUG_WARN("wget error!\n");
  17471. result = FALSE;
  17472. }
  17473. }
  17474. system("pkill ping");
  17475. return result;
  17476. }
  17477. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17478. {
  17479. char rmFileCmd[100]={0};
  17480. char FilePath[100]={0};
  17481. char buf[512];
  17482. int systemresult = 0;
  17483. //DEBUG_INFO("filename=%s\n",filename);
  17484. //DEBUG_INFO("url=%s\n",url);
  17485. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17486. if((access(FilePath,F_OK))!=-1)
  17487. {
  17488. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17489. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17490. system(rmFileCmd);
  17491. }
  17492. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17493. if(fp == NULL)
  17494. {
  17495. DEBUG_INFO("log is NULL\n");
  17496. return FALSE;
  17497. }
  17498. else
  17499. {
  17500. fprintf(fp, "%s\n", url);
  17501. fprintf(fp, "%s\n", filename);
  17502. fclose(fp);
  17503. }
  17504. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  17505. if(phpFP == NULL)
  17506. {
  17507. DEBUG_INFO("PHP upload fail.\n");
  17508. return FALSE;
  17509. }
  17510. else
  17511. {
  17512. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17513. {
  17514. if(strstr(buf, "result") != NULL)
  17515. {
  17516. sscanf(buf, "result: %d", &systemresult);
  17517. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17518. }
  17519. }
  17520. pclose(phpFP);
  17521. }
  17522. if(systemresult != 1)
  17523. {
  17524. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  17525. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  17526. if(phpFP == NULL)
  17527. {
  17528. DEBUG_WARN("PHP PUT upload fail.\n");
  17529. return FALSE;
  17530. }
  17531. else
  17532. {
  17533. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17534. {
  17535. if(strstr(buf, "result") != NULL)
  17536. {
  17537. sscanf(buf, "result: %d", &systemresult);
  17538. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  17539. }
  17540. }
  17541. pclose(phpFP);
  17542. }
  17543. }
  17544. return TRUE;
  17545. }
  17546. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17547. {
  17548. int result = FALSE;
  17549. char ftpbuf[200];
  17550. int systemresult;
  17551. /*
  17552. // Domaind name transfer to IP address
  17553. struct hostent* server;
  17554. char *IPbuffer;
  17555. server = gethostbyname(location);
  17556. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17557. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17558. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17559. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  17560. systemresult = system(ftpbuf);
  17561. if(systemresult != 0)
  17562. {
  17563. DEBUG_INFO("ftpput error!\n");
  17564. }
  17565. else
  17566. {
  17567. result = TRUE;
  17568. DEBUG_INFO("ftpput OK!\n");
  17569. }
  17570. return result;
  17571. }
  17572. int GetOcppServerURL()
  17573. {
  17574. int result = FALSE;
  17575. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  17576. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  17577. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  17578. struct yuarel url;
  17579. char urlStr[512];
  17580. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  17581. {
  17582. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  17583. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17584. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17585. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  17586. if(yuarel_parse(&url, urlStr) != -1)
  17587. {
  17588. sprintf(OcppProtocol, "%s", url.scheme);
  17589. sprintf(OcppHost, "%s", url.host);
  17590. if(url.path == NULL)
  17591. OcppTempPath[0] = '\0';
  17592. else
  17593. {
  17594. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  17595. {
  17596. sprintf(OcppTempPath, "%s/", url.path);
  17597. }
  17598. else
  17599. {
  17600. sprintf(OcppTempPath, "%s", url.path);
  17601. }
  17602. }
  17603. if(url.port == 0)
  17604. {
  17605. if(strcmp(OcppProtocol, "wss") == 0)
  17606. OcppPort = 443;
  17607. else
  17608. OcppPort = 80;
  17609. }
  17610. else
  17611. OcppPort = url.port;
  17612. result = TRUE;
  17613. }
  17614. }
  17615. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  17616. {
  17617. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  17618. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17619. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17620. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  17621. if(yuarel_parse(&url, urlStr) != -1)
  17622. {
  17623. sprintf(OcppProtocol, "%s", url.scheme);
  17624. sprintf(OcppHost, "%s", url.host);
  17625. if(url.path == NULL)
  17626. OcppTempPath[0] = '\0';
  17627. else
  17628. sprintf(OcppTempPath, "%s", url.path);
  17629. if(url.port == 0)
  17630. {
  17631. if(strcmp(OcppProtocol, "wss") == 0)
  17632. OcppPort = 443;
  17633. else
  17634. OcppPort = 80;
  17635. }
  17636. else
  17637. OcppPort = url.port;
  17638. result = TRUE;
  17639. }
  17640. }
  17641. else
  17642. {
  17643. strcpy(OcppHost,"");
  17644. }
  17645. return result;
  17646. }
  17647. int GetOcppPath()
  17648. {
  17649. int result = FALSE;
  17650. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  17651. {
  17652. if(OcppTempPath == NULL)
  17653. {
  17654. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17655. }
  17656. else
  17657. {
  17658. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17659. }
  17660. result = TRUE;
  17661. goto End;
  17662. }
  17663. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  17664. {
  17665. if(OcppTempPath == NULL)
  17666. {
  17667. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  17668. }
  17669. else
  17670. {
  17671. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  17672. }
  17673. result = TRUE;
  17674. goto End;
  17675. }
  17676. else
  17677. {
  17678. strcpy(OcppPath,"");
  17679. }
  17680. End:
  17681. return result;
  17682. }
  17683. int GetOcppPort()
  17684. {
  17685. return OcppPort;
  17686. }
  17687. int GetOcppConnStatus(void)
  17688. {
  17689. return ShmOCPP16Data->OcppConnStatus;
  17690. }
  17691. void SetOcppConnStatus(uint8_t status)
  17692. {
  17693. ShmOCPP16Data->OcppConnStatus = status;
  17694. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  17695. }
  17696. int GetHeartBeatWithNOResponse(void)
  17697. {
  17698. return HeartBeatWithNOResponse;
  17699. }
  17700. void SetHeartBeatWithNOResponse(void)
  17701. {
  17702. HeartBeatWithNOResponse = 0;
  17703. }
  17704. void GetStartTransactionIdTag(int gun_index)
  17705. {
  17706. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17707. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17708. }
  17709. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17710. {
  17711. char ch;
  17712. FILE *fptr1;
  17713. int temptransactionId;
  17714. char str[100]={0};
  17715. temptransactionId = 0;
  17716. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17717. {
  17718. DEBUG_INFO("IdTag is empty.\n");
  17719. return temptransactionId;
  17720. }
  17721. /*------ Read the file ----------------*/
  17722. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  17723. if (!fptr1)
  17724. {
  17725. DEBUG_INFO("QueueTransactionId file open error.\n");
  17726. //printf(" File not found or unable to open the input file!!\n");
  17727. return temptransactionId;
  17728. }
  17729. ch=fgetc(fptr1);
  17730. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  17731. rewind(fptr1);
  17732. if(ch!=EOF)
  17733. {
  17734. // printf("%c",ch);
  17735. while (fgets(str, 100, fptr1) != NULL)
  17736. {
  17737. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17738. if(str[0]=='\0')
  17739. {
  17740. break;
  17741. }
  17742. char *revbuf[8] = {0}; // Variable store string split
  17743. int num = 0;// Quantity after string split
  17744. DEBUG_INFO("Transaction queue data= %s\n", str);
  17745. splitstring(str,",",revbuf,&num); // String split
  17746. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17747. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17748. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17749. DEBUG_INFO("------------------------------\n");
  17750. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17751. {
  17752. if(isStopTransaction)
  17753. {
  17754. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17755. {
  17756. temptransactionId = atoi(revbuf[2]);
  17757. //break;
  17758. }
  17759. }
  17760. else
  17761. {
  17762. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17763. {
  17764. temptransactionId = atoi(revbuf[2]);
  17765. //break;
  17766. }
  17767. }
  17768. }
  17769. }
  17770. }
  17771. else
  17772. DEBUG_INFO("EOF\n");
  17773. fclose(fptr1);
  17774. /*------- End of reading ---------------*/
  17775. return temptransactionId;
  17776. }
  17777. void SetTransactionIdZero(int transactionId)
  17778. {
  17779. char ch;
  17780. FILE *fptr1, *fptr2;
  17781. int temptransactionId = 0;
  17782. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  17783. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  17784. if (!fptr1)
  17785. {
  17786. //printf(" File not found or unable to open the input file!!\n");
  17787. return ;
  17788. }
  17789. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17790. if (!fptr2)
  17791. {
  17792. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17793. fclose(fptr1);
  17794. return ;
  17795. }
  17796. ch=fgetc(fptr1);
  17797. rewind(fptr1);
  17798. if(ch!=EOF)
  17799. {
  17800. // copy all contents to the temporary file except the specific line
  17801. while (fgets(str, 100, fptr1) != NULL)
  17802. {
  17803. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17804. if(str[0]=='\0')
  17805. {
  17806. break;
  17807. }
  17808. char *revbuf[8] = {0};
  17809. int num = 0;
  17810. strcpy(strtemp, str);
  17811. splitstring(str,",",revbuf,&num);
  17812. if(revbuf[2][0] != '\0')
  17813. {
  17814. temptransactionId = atoi(revbuf[2]);
  17815. if(transactionId != temptransactionId)
  17816. {
  17817. fprintf(fptr2, "%s\n", strtemp);
  17818. }
  17819. }
  17820. }
  17821. }
  17822. fclose(fptr1);
  17823. fclose(fptr2);
  17824. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  17825. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  17826. /*------ Read the file ----------------*/
  17827. }
  17828. int InternetDisconnect(void)
  17829. {
  17830. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  17831. }
  17832. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17833. void storeTempStopTransaction(int gun_index)
  17834. {
  17835. char guid[37]={0};
  17836. int tempIndex = 0;
  17837. char TempStopTransaction[256];
  17838. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  17839. DEBUG_INFO("storeTempStopTransaction...\n");
  17840. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  17841. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  17842. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  17843. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17844. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17845. {
  17846. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17847. {
  17848. tempIndex = ((gun_index==2) ? 1: 0);
  17849. }
  17850. else
  17851. {
  17852. tempIndex = gun_index;
  17853. }
  17854. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17855. {
  17856. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17857. {
  17858. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  17859. }
  17860. }// END OF CHAdeMO_QUANTITY
  17861. }
  17862. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17863. {
  17864. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17865. {
  17866. tempIndex = ((gun_index==2) ? 1: 0);
  17867. }
  17868. else
  17869. {
  17870. tempIndex = gun_index;
  17871. }
  17872. for (int index = 0; index < CCS_QUANTITY; index++)
  17873. {
  17874. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17875. {
  17876. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  17877. }
  17878. }// END OF CCS_QUANTITY
  17879. }
  17880. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17881. {
  17882. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17883. {
  17884. tempIndex = ((gun_index==2) ? 1: 0);
  17885. }
  17886. else
  17887. {
  17888. tempIndex = gun_index;
  17889. }
  17890. for (int index = 0; index < GB_QUANTITY; index++)
  17891. {
  17892. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17893. {
  17894. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17895. }
  17896. }// END OF GB_QUANTITY
  17897. }
  17898. else if(gunType[gun_index] == GUN_TYPE_DO)
  17899. {
  17900. tempIndex = gun_index;
  17901. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17902. {
  17903. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17904. {
  17905. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17906. }
  17907. }
  17908. }
  17909. else
  17910. {
  17911. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17912. {
  17913. tempIndex = 2;
  17914. }
  17915. else
  17916. {
  17917. tempIndex = gun_index;
  17918. }
  17919. for (int index = 0; index < AC_QUANTITY; index++)
  17920. {
  17921. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17922. {
  17923. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17924. }
  17925. }// END OF AC_QUANTITY
  17926. }
  17927. //Stop Transaction Time
  17928. struct timeval tmnow;
  17929. struct tm *tm;
  17930. char buf[28];//, usec_buf[6];
  17931. gettimeofday(&tmnow, NULL);
  17932. time_t t;
  17933. t = time(NULL);
  17934. /*UTC time and date*/
  17935. tm = gmtime(&t);
  17936. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17937. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  17938. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  17939. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17940. random_uuid(guid);
  17941. /***********************************transactionData******************************************************/
  17942. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17943. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17944. //=================================
  17945. //1. Transaction_Begin
  17946. //=================================
  17947. //============================== Energy.Active.Import.Interval ===========================================
  17948. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17949. {
  17950. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  17951. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17952. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  17953. 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*/]);
  17954. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17955. 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))
  17956. {
  17957. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  17958. }
  17959. else
  17960. {
  17961. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  17962. }
  17963. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  17964. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17965. }
  17966. //=================================
  17967. //2. Transaction_End
  17968. //=================================
  17969. //2.1====================================== Current.Import L1 ==============================================
  17970. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17971. {
  17972. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17973. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17974. {
  17975. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17976. {
  17977. tempIndex = ((gun_index==2) ? 1: 0);
  17978. }
  17979. else
  17980. {
  17981. tempIndex = gun_index;
  17982. }
  17983. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17984. {
  17985. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17986. {
  17987. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17988. }
  17989. }// End of for CHAdeMO_QUANTITY
  17990. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17991. }
  17992. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17993. {
  17994. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17995. {
  17996. tempIndex = ((gun_index==2) ? 1: 0);
  17997. }
  17998. else
  17999. {
  18000. tempIndex = gun_index;
  18001. }
  18002. for (int index = 0; index < CCS_QUANTITY; index++)
  18003. {
  18004. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18005. {
  18006. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18007. }
  18008. }// End of for CCS_QUANTITY
  18009. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18010. }
  18011. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18012. {
  18013. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18014. {
  18015. tempIndex = ((gun_index==2) ? 1: 0);
  18016. }
  18017. else
  18018. {
  18019. tempIndex = gun_index;
  18020. }
  18021. for (int index = 0; index < GB_QUANTITY; index++)
  18022. {
  18023. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18024. {
  18025. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18026. }
  18027. }// End of for GB_QUANTITY
  18028. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18029. }
  18030. else if(gunType[gun_index] == GUN_TYPE_DO)
  18031. {
  18032. tempIndex = gun_index;
  18033. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18034. {
  18035. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18036. {
  18037. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18038. }
  18039. }
  18040. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18041. }
  18042. else
  18043. {
  18044. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18045. {
  18046. tempIndex = 2;
  18047. }
  18048. else
  18049. {
  18050. tempIndex = gun_index;
  18051. }
  18052. for (int index = 0; index < AC_QUANTITY; index++)
  18053. {
  18054. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18055. {
  18056. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  18057. }
  18058. }// End of for AC_QUANTITY
  18059. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18060. }
  18061. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18062. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  18063. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  18064. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18065. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  18066. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18067. }
  18068. //2.2===================================== Energy.Active.Import.Interval ==========================================
  18069. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  18070. {
  18071. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18072. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18073. {
  18074. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18075. {
  18076. tempIndex = ((gun_index==2) ? 1: 0);
  18077. }
  18078. else
  18079. {
  18080. tempIndex = gun_index;
  18081. }
  18082. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18083. {
  18084. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18085. {
  18086. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  18087. }
  18088. }// END OF CHAdeMO_QUANTITY
  18089. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18090. }
  18091. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18092. {
  18093. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18094. {
  18095. tempIndex = ((gun_index==2) ? 1: 0);
  18096. }
  18097. else
  18098. {
  18099. tempIndex = gun_index;
  18100. }
  18101. for (int index = 0; index < CCS_QUANTITY; index++)
  18102. {
  18103. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18104. {
  18105. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  18106. }
  18107. }// END OF CCS_QUANTITY
  18108. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18109. }
  18110. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18111. {
  18112. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18113. {
  18114. tempIndex = ((gun_index==2) ? 1: 0);
  18115. }
  18116. else
  18117. {
  18118. tempIndex = gun_index;
  18119. }
  18120. for (int index = 0; index < GB_QUANTITY; index++)
  18121. {
  18122. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18123. {
  18124. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  18125. }
  18126. }// END OF GB_QUANTITY
  18127. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18128. }
  18129. else if(gunType[gun_index] == GUN_TYPE_DO)
  18130. {
  18131. tempIndex = gun_index;
  18132. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18133. {
  18134. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18135. {
  18136. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  18137. }
  18138. }
  18139. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18140. }
  18141. else
  18142. {
  18143. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18144. {
  18145. tempIndex = 2;
  18146. }
  18147. else
  18148. {
  18149. tempIndex = gun_index;
  18150. }
  18151. for (int index = 0; index < AC_QUANTITY; index++)
  18152. {
  18153. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18154. {
  18155. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  18156. }
  18157. }// END OF AC_QUANTITY
  18158. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18159. }
  18160. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18161. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  18162. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  18163. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18164. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  18165. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  18166. }
  18167. //2.3====================================== Power.Active.Import =========================================
  18168. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  18169. {
  18170. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18171. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18172. {
  18173. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18174. {
  18175. tempIndex = ((gun_index==2) ? 1: 0);
  18176. }
  18177. else
  18178. {
  18179. tempIndex = gun_index;
  18180. }
  18181. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18182. {
  18183. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18184. {
  18185. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18186. }
  18187. } // End for CHAdeMO_QUANTITY
  18188. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18189. }
  18190. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18191. {
  18192. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18193. {
  18194. tempIndex = ((gun_index==2) ? 1: 0);
  18195. }
  18196. else
  18197. {
  18198. tempIndex = gun_index;
  18199. }
  18200. for (int index = 0; index < CCS_QUANTITY; index++)
  18201. {
  18202. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18203. {
  18204. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18205. }
  18206. } // END for CCS_QUANTITY
  18207. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18208. }
  18209. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18210. {
  18211. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18212. {
  18213. tempIndex = ((gun_index==2) ? 1: 0);
  18214. }
  18215. else
  18216. {
  18217. tempIndex = gun_index;
  18218. }
  18219. for (int index = 0; index < GB_QUANTITY; index++)
  18220. {
  18221. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18222. {
  18223. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18224. }
  18225. }// END for GB_QUANTITY
  18226. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18227. }
  18228. else if(gunType[gun_index] == GUN_TYPE_DO)
  18229. {
  18230. tempIndex = gun_index;
  18231. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18232. {
  18233. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18234. {
  18235. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18236. }
  18237. }
  18238. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18239. }
  18240. else
  18241. {
  18242. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18243. {
  18244. tempIndex = 2;
  18245. }
  18246. else
  18247. {
  18248. tempIndex = gun_index;
  18249. }
  18250. for (int index = 0; index < AC_QUANTITY; index++)
  18251. {
  18252. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18253. {
  18254. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18255. }
  18256. } // END for AC_QUANTITY
  18257. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18258. }
  18259. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18260. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  18261. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  18262. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18263. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  18264. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  18265. }
  18266. //2.4====================================== Voltage L1 ====================================================
  18267. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18268. {
  18269. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18270. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18271. {
  18272. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18273. {
  18274. tempIndex = ((gun_index==2) ? 1: 0);
  18275. }
  18276. else
  18277. {
  18278. tempIndex = gun_index;
  18279. }
  18280. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18281. {
  18282. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18283. {
  18284. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18285. }
  18286. } // END OF FOR CHAdeMO_QUANTITY
  18287. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18288. }
  18289. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18290. {
  18291. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18292. {
  18293. tempIndex = ((gun_index==2) ? 1: 0);
  18294. }
  18295. else
  18296. {
  18297. tempIndex = gun_index;
  18298. }
  18299. for (int index = 0; index < CCS_QUANTITY; index++)
  18300. {
  18301. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18302. {
  18303. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18304. }
  18305. } // END OF FOR CCS_QUANTITY
  18306. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18307. }
  18308. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18309. {
  18310. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18311. {
  18312. tempIndex = ((gun_index==2) ? 1: 0);
  18313. }
  18314. else
  18315. {
  18316. tempIndex = gun_index;
  18317. }
  18318. for (int index = 0; index < GB_QUANTITY; index++)
  18319. {
  18320. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18321. {
  18322. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18323. }
  18324. } // END OF FOR GB_QUANTITY
  18325. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18326. }
  18327. else if(gunType[gun_index] == GUN_TYPE_DO)
  18328. {
  18329. tempIndex = gun_index;
  18330. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18331. {
  18332. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18333. {
  18334. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18335. }
  18336. }
  18337. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18338. }
  18339. else
  18340. {
  18341. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18342. {
  18343. tempIndex = 2;
  18344. }
  18345. else
  18346. {
  18347. tempIndex = gun_index;
  18348. }
  18349. for (int index = 0; index < AC_QUANTITY; index++)
  18350. {
  18351. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18352. {
  18353. 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
  18354. }
  18355. } // END OF FOR AC_QUANTITY
  18356. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18357. }
  18358. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18359. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  18360. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  18361. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18362. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  18363. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18364. }
  18365. //2.5============================================== End SoC =========================================================
  18366. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18367. {
  18368. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18369. 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))
  18370. {
  18371. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18372. {
  18373. tempIndex = ((gun_index==2) ? 1: 0);
  18374. }
  18375. else
  18376. {
  18377. tempIndex = gun_index;
  18378. }
  18379. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18380. {
  18381. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18382. {
  18383. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18384. {
  18385. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  18386. }
  18387. }
  18388. }
  18389. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18390. {
  18391. for (int index = 0; index < CCS_QUANTITY; index++)
  18392. {
  18393. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18394. {
  18395. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  18396. }
  18397. }
  18398. }
  18399. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18400. {
  18401. for (int index = 0; index < GB_QUANTITY; index++)
  18402. {
  18403. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18404. {
  18405. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  18406. }
  18407. }
  18408. }
  18409. else if(gunType[gun_index] == GUN_TYPE_DO)
  18410. {
  18411. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18412. {
  18413. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18414. {
  18415. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  18416. }
  18417. }
  18418. }
  18419. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18420. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  18421. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18422. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  18423. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  18424. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18425. } // END FOR DC CASE
  18426. }
  18427. //2.6====================================== Current.Import L2 ==============================================
  18428. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18429. {
  18430. // AC 3 phase L2 current
  18431. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18432. {
  18433. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18434. {
  18435. tempIndex = 2;
  18436. }
  18437. else
  18438. {
  18439. tempIndex = gun_index;
  18440. }
  18441. for (int index = 0; index < AC_QUANTITY; index++)
  18442. {
  18443. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18444. {
  18445. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  18446. }
  18447. }// End of for AC_QUANTITY
  18448. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  18449. }
  18450. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18451. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  18452. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  18453. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  18454. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18455. }
  18456. //2.7====================================== Current.Import L3 ==============================================
  18457. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18458. {
  18459. // AC 3 phase L3 current
  18460. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18461. {
  18462. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18463. {
  18464. tempIndex = 2;
  18465. }
  18466. else
  18467. {
  18468. tempIndex = gun_index;
  18469. }
  18470. for (int index = 0; index < AC_QUANTITY; index++)
  18471. {
  18472. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18473. {
  18474. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  18475. }
  18476. }// End of for AC_QUANTITY
  18477. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  18478. }
  18479. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18480. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  18481. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  18482. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  18483. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18484. }
  18485. //2.9====================================== Voltage L2 ====================================================
  18486. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18487. {
  18488. // AC 3 phase L2 volatge
  18489. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18490. {
  18491. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18492. {
  18493. tempIndex = 2;
  18494. }
  18495. else
  18496. {
  18497. tempIndex = gun_index;
  18498. }
  18499. for (int index = 0; index < AC_QUANTITY; index++)
  18500. {
  18501. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18502. {
  18503. 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
  18504. }
  18505. } // END OF FOR AC_QUANTITY
  18506. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  18507. }
  18508. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18509. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  18510. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  18511. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  18512. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18513. }
  18514. //2.10====================================== Voltage L3 ====================================================
  18515. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18516. {
  18517. // AC 3 phase L3 volatge
  18518. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18519. {
  18520. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18521. {
  18522. tempIndex = 2;
  18523. }
  18524. else
  18525. {
  18526. tempIndex = gun_index;
  18527. }
  18528. for (int index = 0; index < AC_QUANTITY; index++)
  18529. {
  18530. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18531. {
  18532. 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
  18533. }
  18534. } // END OF FOR AC_QUANTITY
  18535. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  18536. }
  18537. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18538. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  18539. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  18540. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  18541. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18542. }
  18543. //====================== Start SoC ================================
  18544. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18545. {
  18546. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18547. 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))
  18548. {
  18549. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18550. {
  18551. tempIndex = ((gun_index==2) ? 1: 0);
  18552. }
  18553. else
  18554. {
  18555. tempIndex = gun_index;
  18556. }
  18557. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18558. {
  18559. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18560. {
  18561. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18562. {
  18563. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  18564. }
  18565. }
  18566. }
  18567. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18568. {
  18569. for (int index = 0; index < CCS_QUANTITY; index++)
  18570. {
  18571. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18572. {
  18573. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  18574. }
  18575. }
  18576. }
  18577. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18578. {
  18579. for (int index = 0; index < GB_QUANTITY; index++)
  18580. {
  18581. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18582. {
  18583. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  18584. }
  18585. }
  18586. }
  18587. else if(gunType[gun_index] == GUN_TYPE_DO)
  18588. {
  18589. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18590. {
  18591. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18592. {
  18593. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  18594. }
  18595. }
  18596. }
  18597. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18598. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  18599. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18600. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  18601. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  18602. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18603. } // END FOR DC CASE
  18604. }
  18605. //======================================== Message create ==============================================
  18606. json_object *StopTransaction = json_object_new_object();
  18607. json_object *transactionDatas = json_object_new_array();
  18608. json_object *sampledValues = json_object_new_array();
  18609. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  18610. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  18611. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  18612. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  18613. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  18614. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  18615. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  18616. {
  18617. json_object *transactionData = json_object_new_object();
  18618. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  18619. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  18620. {
  18621. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  18622. {
  18623. json_object *sampledValue = json_object_new_object();
  18624. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  18625. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  18626. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  18627. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  18628. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  18629. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  18630. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  18631. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  18632. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  18633. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  18634. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  18635. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  18636. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  18637. json_object_array_add(sampledValues, sampledValue);
  18638. }
  18639. }
  18640. json_object_object_add(transactionData, "sampledValue", sampledValues);
  18641. json_object_array_add(transactionDatas, transactionData);
  18642. }
  18643. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  18644. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  18645. ,MESSAGE_TYPE_CALL
  18646. ,guid
  18647. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  18648. json_object_put(StopTransaction);
  18649. // Check File "TempStopTransaction" Exist
  18650. if((access(TempStopTransaction,F_OK))!=-1)
  18651. {
  18652. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  18653. fclose(fopen(TempStopTransaction, "w"));
  18654. }
  18655. else
  18656. {
  18657. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  18658. FILE *log = fopen(TempStopTransaction, "w+");
  18659. if(log == NULL)
  18660. {
  18661. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  18662. return ;
  18663. }
  18664. else
  18665. {
  18666. fclose(log);
  18667. }
  18668. }
  18669. //Add TempStopTransaction | Update TempStopTransaction
  18670. // open file for writing
  18671. FILE *outfile;
  18672. outfile = fopen (TempStopTransaction, "a");
  18673. //DEBUG_INFO("data = %s\n", queuedata);
  18674. fputs(queuedata, outfile);
  18675. fputs("\n", outfile);
  18676. fclose (outfile);
  18677. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18678. OCPP_updatePeriodEnergy(gun_index);
  18679. }
  18680. void checkTempStopTransaction(int gun_index)
  18681. {
  18682. FILE *fptr1;
  18683. char ch;
  18684. char str[QUEUE_MESSAGE_LENGTH]={0};
  18685. char guid[37]={0};
  18686. char tempdata[65]={0};
  18687. char connectorStr[2]={0};
  18688. char TempStopTransaction[256];
  18689. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  18690. fptr1 = fopen(TempStopTransaction, "r");
  18691. //TempStopTransaction格式: 槍號,StopTransaction封包
  18692. if (!fptr1)
  18693. {
  18694. //printf(" File not found or unable to open the input file!!\n");
  18695. return ;
  18696. }
  18697. ch=fgetc(fptr1);
  18698. //printf(" Now the content of the file %s is : \n",fname);
  18699. rewind(fptr1);
  18700. if(ch!=EOF)
  18701. {
  18702. // copy all contents to the temporary file except the specific line
  18703. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18704. {
  18705. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18706. if(str[0]=='\0')
  18707. {
  18708. break;
  18709. }
  18710. //TempStopTransaction格式: 槍號,StopTransaction封包
  18711. strncpy(connectorStr, str, 1);
  18712. if(atoi(connectorStr) != (gun_index+1))
  18713. {
  18714. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18715. fclose(fptr1);
  18716. return ;
  18717. }
  18718. //random_uuid(guid);
  18719. strncpy(guid, str+6, 36); //copy guid
  18720. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18721. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18722. {
  18723. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18724. }
  18725. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18726. OCPP_insert_transaction_msg(NO, str);
  18727. memset(str,0,ARRAY_SIZE(str));
  18728. }
  18729. }
  18730. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18731. fclose(fptr1);
  18732. remove(TempStopTransaction); // remove the original file
  18733. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18734. }
  18735. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18736. {
  18737. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18738. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18739. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18740. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18741. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18742. }
  18743. int GetWebSocketPingInterval(void)
  18744. {
  18745. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18746. }
  18747. int GetServerSign(void)
  18748. {
  18749. return server_sign;
  18750. }
  18751. uint8_t GetOcppSecurityProfile()
  18752. {
  18753. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18754. }
  18755. void GetOcppChargerBoxId(uint8_t *data)
  18756. {
  18757. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18758. }
  18759. void GetOcppSecurityPassword(uint8_t *data)
  18760. {
  18761. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18762. }
  18763. void SetOcppVersion(uint8_t *version)
  18764. {
  18765. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18766. DEBUG_INFO("ocpp version: %s\n", version);
  18767. if(strstr((char*)version, "ocpp1.6") != NULL)
  18768. {
  18769. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18770. }
  18771. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18772. {
  18773. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18774. system("pkill OcppBackend");
  18775. }
  18776. }
  18777. void SetServerSign(int value)
  18778. {
  18779. server_sign = value;
  18780. }
  18781. int GetBootNotificationInterval(void)
  18782. {
  18783. return BootNotificationInterval;
  18784. }
  18785. int GetInternetConn(void)
  18786. {
  18787. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18788. }
  18789. int GetBackendConnectionTimeout(void)
  18790. {
  18791. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18792. }
  18793. int isConnectorInitMode(int gun_index)
  18794. {
  18795. int tempIndex = 0;
  18796. int result = TRUE;
  18797. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18798. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18799. {
  18800. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18801. {
  18802. tempIndex = ((gun_index==2) ? 1: 0);
  18803. }
  18804. else
  18805. {
  18806. tempIndex = gun_index;
  18807. }
  18808. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18809. {
  18810. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18811. {
  18812. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18813. } //end of the same index
  18814. }//end of for CHAdeMO_QUANTITY
  18815. }
  18816. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18817. {
  18818. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18819. {
  18820. tempIndex = ((gun_index==2) ? 1: 0);
  18821. }
  18822. else
  18823. {
  18824. tempIndex = gun_index;
  18825. }
  18826. for (int index = 0; index < CCS_QUANTITY; index++)
  18827. {
  18828. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18829. {
  18830. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18831. } //end of the same index
  18832. } // end of for CCS_QUANTITY
  18833. }
  18834. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18835. {
  18836. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18837. {
  18838. tempIndex = ((gun_index==2) ? 1: 0);
  18839. }
  18840. else
  18841. {
  18842. tempIndex = gun_index;
  18843. }
  18844. for (int index = 0; index < GB_QUANTITY; index++)
  18845. {
  18846. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18847. {
  18848. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18849. } //end of the same index
  18850. } // end of for GB_QUANTITY
  18851. }
  18852. else if(gunType[gun_index] == GUN_TYPE_DO)
  18853. {
  18854. tempIndex = gun_index;
  18855. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18856. {
  18857. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18858. {
  18859. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18860. } //end of the same index
  18861. }
  18862. }
  18863. else
  18864. {
  18865. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18866. {
  18867. tempIndex = 2;
  18868. }
  18869. else
  18870. {
  18871. tempIndex = gun_index;
  18872. }
  18873. for (int index = 0; index < AC_QUANTITY; index++)
  18874. {
  18875. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18876. {
  18877. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18878. }//end of the same index
  18879. }//end of for AC_QUANTITY
  18880. }
  18881. return result;
  18882. }
  18883. void refreshProcDogTimer()
  18884. {
  18885. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  18886. }
  18887. void InitialSystemValue(void)
  18888. {
  18889. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  18890. locallistVersion=0;
  18891. BootNotificationInterval = 0;
  18892. authorizeRetryTimes = 0;
  18893. GunStatusInterval = 10;
  18894. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18895. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18896. //Hear Beat
  18897. HeartBeatWithNOResponse = 0;
  18898. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18899. FirstHeartBeat = 0;
  18900. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18901. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18902. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18903. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18904. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18905. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18906. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18907. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18908. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18909. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18910. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18911. //Status && ConnectorPlugIn Setting
  18912. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18913. {
  18914. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18915. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18916. }
  18917. for (int index = 0; index < CCS_QUANTITY; index++)
  18918. {
  18919. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18920. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18921. }
  18922. for (int index = 0; index < GB_QUANTITY; index++)
  18923. {
  18924. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18925. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18926. }
  18927. for (int index = 0; index < AC_QUANTITY; index++)
  18928. {
  18929. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18930. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18931. }
  18932. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18933. {
  18934. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18935. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18936. }
  18937. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18938. {
  18939. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18940. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18941. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18942. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18943. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18944. }
  18945. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18946. refreshStartTimer(&clientTime.Heartbeat);
  18947. sleep(1);
  18948. }
  18949. void LWS_Send(char *str)
  18950. {
  18951. //=====================================================
  18952. // Check InternetConn 0: disconnected, 1: connected
  18953. //====================================================
  18954. if(GetOcppConnStatus() == 0)
  18955. {
  18956. DEBUG_INFO("offline now !!!\n");
  18957. return;
  18958. }
  18959. // Only disable isWebsocketSendable operation initiated by charger
  18960. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18961. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18962. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18963. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18964. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18965. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18966. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18967. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18968. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18969. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18970. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18971. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18972. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18973. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18974. {
  18975. isWebsocketSendable = 0;
  18976. }
  18977. pthread_mutex_lock(&lock_send);
  18978. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18979. sprintf((char *)SendBuffer, "%s", str);
  18980. SendBufLen = strlen(str);
  18981. pthread_mutex_unlock(&lock_send);
  18982. lws_callback_on_writable(wsi_client);
  18983. //lws_service(context, 0);
  18984. //sleep(1);
  18985. }
  18986. void LWS_SendNow(char *str)
  18987. {
  18988. //=====================================================
  18989. // Check InternetConn 0: disconnected, 1: connected
  18990. //====================================================
  18991. if(GetOcppConnStatus() == 0)
  18992. {
  18993. DEBUG_INFO("offline now !!!\n");
  18994. return;
  18995. }
  18996. // Only disable isWebsocketSendable operation initiated by charger
  18997. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18998. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18999. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19000. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  19001. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19002. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19003. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19004. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  19005. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19006. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  19007. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19008. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19009. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19010. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  19011. {
  19012. isWebsocketSendable = 0;
  19013. }
  19014. pthread_mutex_lock(&lock_send);
  19015. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19016. sprintf((char *)SendBuffer, "%s", str);
  19017. SendBufLen = strlen(str);
  19018. pthread_mutex_unlock(&lock_send);
  19019. lws_callback_on_writable(wsi_client);
  19020. lws_service(context, 0);
  19021. //sleep(1);
  19022. }