MessageHandler.c 948 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761
  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. locallistVersion = 0;
  10542. OCPP_getListVerion();
  10543. }
  10544. //from db.OCPP_getListVerion
  10545. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10546. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  10547. sendGetLocalListVersionConfirmation(uuid,"");
  10548. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  10549. return result;
  10550. }
  10551. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10552. {
  10553. mtrace();
  10554. int result = FAIL;
  10555. int connectorIdInt=-1;
  10556. int tempIndex = 0;
  10557. int connectorIdIsNULL, chargingProfileIsNULL;
  10558. char comfirmstr[20]={0};
  10559. char cmdBuf[512];
  10560. json_object *RemoteStartTransaction;
  10561. FILE *fp;
  10562. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10563. if(server_pending == TRUE)
  10564. {
  10565. return 0;
  10566. }
  10567. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10568. RemoteStartTransaction = json_tokener_parse(payload);
  10569. if(!is_error(RemoteStartTransaction))
  10570. {
  10571. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10572. {
  10573. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10574. }
  10575. else
  10576. {
  10577. connectorIdIsNULL = TRUE;
  10578. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10579. {
  10580. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10581. {
  10582. connectorIdIsNULL = FALSE;
  10583. connectorIdInt = (gun_index+1);
  10584. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10585. break;
  10586. }
  10587. }
  10588. }
  10589. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10590. {
  10591. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10592. // Required data
  10593. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10594. // Optional data
  10595. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10596. {
  10597. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10598. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10599. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10600. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10601. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10602. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10603. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10604. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10605. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10606. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10607. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10608. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10609. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10610. {
  10611. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  10612. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10613. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  10614. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10615. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  10616. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10617. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  10618. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10619. {
  10620. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  10621. {
  10622. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  10623. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  10624. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases") != NULL)
  10625. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  10626. }
  10627. }
  10628. }
  10629. }
  10630. else
  10631. {
  10632. chargingProfileIsNULL = TRUE;
  10633. }
  10634. }
  10635. }
  10636. else
  10637. {
  10638. connectorIdIsNULL = TRUE;
  10639. }
  10640. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10641. {
  10642. DEBUG_WARN("Connector id is NULL\n.");
  10643. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10644. goto end;
  10645. }
  10646. /*
  10647. enum _SYSTEM_STATUS
  10648. {
  10649. S_BOOTING = 0,
  10650. S_IDLE, = 1
  10651. S_AUTHORIZING, = 2
  10652. S_REASSIGN_CHECK, = 3
  10653. S_REASSIGN, = 4
  10654. S_PRECHARGE, = 5
  10655. S_PREPARING_FOR_EV, = 6
  10656. S_PREPARING_FOR_EVSE, = 7
  10657. S_CHARGING, = 8
  10658. S_TERMINATING, = 9
  10659. S_COMPLETE, = 10
  10660. S_ALARM, = 11
  10661. S_FAULT = 12
  10662. }
  10663. */
  10664. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10665. {
  10666. //check Transaction active
  10667. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10668. {
  10669. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10670. {
  10671. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10672. }
  10673. else
  10674. {
  10675. tempIndex = connectorIdInt -1;
  10676. }
  10677. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10678. {
  10679. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10680. {
  10681. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10682. {
  10683. //Reserved
  10684. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10685. }
  10686. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10687. {
  10688. //Reserved
  10689. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10690. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10691. goto end;
  10692. }
  10693. else
  10694. {
  10695. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10696. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10697. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10698. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10699. {
  10700. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10701. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10702. goto end;
  10703. }
  10704. }//END FOR ELSE
  10705. }
  10706. }// END FOR CHAdeMO_QUANTITY
  10707. }
  10708. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10709. {
  10710. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10711. {
  10712. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10713. }
  10714. else
  10715. {
  10716. tempIndex = connectorIdInt -1;
  10717. }
  10718. for (int index = 0; index < CCS_QUANTITY; index++)
  10719. {
  10720. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10721. {
  10722. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10723. {
  10724. //Reserved
  10725. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10726. }
  10727. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10728. {
  10729. //Reserved
  10730. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10731. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10732. goto end;
  10733. }
  10734. else
  10735. {
  10736. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10737. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10738. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10739. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10740. {
  10741. DEBUG_WARN("CCS connector not allow start\n.");
  10742. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10743. goto end;
  10744. }
  10745. }// END FOR ELSE
  10746. }
  10747. }// END FOR CCS_QUANTITY
  10748. }
  10749. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10750. {
  10751. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10752. {
  10753. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10754. }
  10755. else
  10756. {
  10757. tempIndex = connectorIdInt -1;
  10758. }
  10759. for (int index = 0; index < GB_QUANTITY; index++)
  10760. {
  10761. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10762. {
  10763. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10764. {
  10765. //Reserved
  10766. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10767. }
  10768. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10769. {
  10770. //Reserved
  10771. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10772. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10773. goto end;
  10774. }
  10775. else
  10776. {
  10777. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10778. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10779. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10780. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10781. {
  10782. DEBUG_WARN("GB connector not allow start\n.");
  10783. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10784. goto end;
  10785. }
  10786. }// END FOR ELSE
  10787. }
  10788. } // END FOR GB_QUANTITY
  10789. }
  10790. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10791. {
  10792. tempIndex = connectorIdInt -1;
  10793. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10794. {
  10795. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10796. {
  10797. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10798. {
  10799. //Reserved
  10800. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10801. }
  10802. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10803. {
  10804. //Reserved
  10805. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10806. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10807. goto end;
  10808. }
  10809. else
  10810. {
  10811. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10812. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10813. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10814. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10815. {
  10816. DEBUG_WARN("GB connector not allow start\n.");
  10817. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10818. goto end;
  10819. }
  10820. }// END FOR ELSE
  10821. }
  10822. } // END FOR GB_QUANTITY
  10823. }
  10824. else
  10825. {
  10826. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10827. {
  10828. tempIndex = 2;
  10829. }
  10830. else
  10831. {
  10832. tempIndex = connectorIdInt -1;
  10833. }
  10834. for (int index = 0; index < AC_QUANTITY; index++)
  10835. {
  10836. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10837. {
  10838. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10839. {
  10840. //Reserved
  10841. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10842. }
  10843. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10844. {
  10845. //Reserved
  10846. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10847. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10848. goto end;
  10849. }
  10850. else
  10851. {
  10852. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10853. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10854. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10855. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10856. {
  10857. DEBUG_WARN("AC connector not allow start\n.");
  10858. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10859. goto end;
  10860. }
  10861. }//END FOR ELSE
  10862. }
  10863. }// END FOR AC_QUANTITY
  10864. }
  10865. if(chargingProfileIsNULL == FALSE)
  10866. {
  10867. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10868. {
  10869. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10870. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10871. //memset idTag
  10872. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10873. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10874. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10875. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10876. // Save profile to file
  10877. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10878. system(cmdBuf);
  10879. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10880. fp = fopen(cmdBuf, "w");
  10881. fprintf(fp, "{\"connectorId\":%d,\"csChargingProfiles\":%s}\n", connectorIdInt, json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10882. fclose(fp);
  10883. }
  10884. else
  10885. {
  10886. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10887. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10888. }
  10889. }
  10890. else
  10891. {
  10892. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10893. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10894. //memset idTag
  10895. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10896. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10897. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10898. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10899. }
  10900. }
  10901. else
  10902. {
  10903. DEBUG_WARN("Connector id over\n.");
  10904. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10905. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10906. }
  10907. end:
  10908. json_object_put(RemoteStartTransaction);
  10909. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10910. {
  10911. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10912. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10913. }
  10914. //OCPP send RemoteStartConfirmation by first.
  10915. sendRemoteStartConfirmation(uuid, comfirmstr);
  10916. return result;
  10917. }
  10918. int handleRemoteStartRequest(char *uuid, char *payload)
  10919. {
  10920. mtrace();
  10921. int result = PASS;
  10922. int connectorIdInt=-1;
  10923. int tempIndex = 0;
  10924. char comfirmstr[20]={0};
  10925. char cmdBuf[512];
  10926. json_object *RemoteStartTransaction;
  10927. FILE *fp;
  10928. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10929. if(server_pending == TRUE)
  10930. {
  10931. result = FAIL;
  10932. }
  10933. RemoteStartTransaction = json_tokener_parse(payload);
  10934. if(!is_error(RemoteStartTransaction))
  10935. {
  10936. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10937. {
  10938. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10939. }
  10940. else
  10941. {
  10942. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10943. {
  10944. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10945. {
  10946. connectorIdInt = (gun_index+1);
  10947. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10948. break;
  10949. }
  10950. }
  10951. }
  10952. if(connectorIdInt == 0)
  10953. {
  10954. DEBUG_WARN("Connector id shall not equal 0.\n");
  10955. result = FAIL;
  10956. }
  10957. else if(connectorIdInt == -1)
  10958. {
  10959. DEBUG_INFO("Connector id does not specific.\n");
  10960. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10961. {
  10962. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10963. // Required data
  10964. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10965. // Optional data
  10966. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10967. {
  10968. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10969. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10970. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10971. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10972. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10973. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10974. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10975. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10976. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10977. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10978. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10979. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10980. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10981. {
  10982. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  10983. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10984. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  10985. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10986. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  10987. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10988. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  10989. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10990. {
  10991. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  10992. {
  10993. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  10994. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  10995. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases") != NULL)
  10996. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  10997. }
  10998. }
  10999. }
  11000. }
  11001. else
  11002. {
  11003. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  11004. }
  11005. }
  11006. }
  11007. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  11008. {
  11009. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  11010. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  11011. // Required data
  11012. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11013. // Optional data
  11014. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11015. {
  11016. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11017. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11018. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11019. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11020. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11021. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11022. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11023. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11024. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11025. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11026. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11027. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11028. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11029. {
  11030. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  11031. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11032. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  11033. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11034. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  11035. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11036. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  11037. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11038. {
  11039. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  11040. {
  11041. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  11042. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  11043. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases") != NULL)
  11044. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  11045. }
  11046. }
  11047. }
  11048. }
  11049. else
  11050. {
  11051. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  11052. }
  11053. }
  11054. else
  11055. {
  11056. DEBUG_WARN("Connector id is over maximun value.\n");
  11057. result = FAIL;
  11058. }
  11059. }
  11060. if(result == PASS)
  11061. {
  11062. if(connectorIdInt > 0)
  11063. {
  11064. //check Transaction active
  11065. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11066. {
  11067. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11068. {
  11069. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11070. }
  11071. else
  11072. {
  11073. tempIndex = connectorIdInt -1;
  11074. }
  11075. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11076. {
  11077. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11078. {
  11079. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11080. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11081. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11082. {
  11083. //Reserved
  11084. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  11085. }
  11086. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11087. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11088. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11089. {
  11090. //Reserved
  11091. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  11092. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11093. goto end;
  11094. }
  11095. else
  11096. {
  11097. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11098. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  11099. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  11100. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  11101. {
  11102. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  11103. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11104. goto end;
  11105. }
  11106. }//END FOR ELSE
  11107. }
  11108. }// END FOR CHAdeMO_QUANTITY
  11109. }
  11110. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11111. {
  11112. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11113. {
  11114. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11115. }
  11116. else
  11117. {
  11118. tempIndex = connectorIdInt -1;
  11119. }
  11120. for (int index = 0; index < CCS_QUANTITY; index++)
  11121. {
  11122. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11123. {
  11124. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11125. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11126. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11127. {
  11128. //Reserved
  11129. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  11130. }
  11131. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11132. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11133. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11134. {
  11135. //Reserved
  11136. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  11137. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11138. goto end;
  11139. }
  11140. else
  11141. {
  11142. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11143. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11144. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11145. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11146. {
  11147. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11148. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11149. goto end;
  11150. }
  11151. }// END FOR ELSE
  11152. }
  11153. }// END FOR CCS_QUANTITY
  11154. }
  11155. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11156. {
  11157. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11158. {
  11159. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11160. }
  11161. else
  11162. {
  11163. tempIndex = connectorIdInt -1;
  11164. }
  11165. for (int index = 0; index < GB_QUANTITY; index++)
  11166. {
  11167. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11168. {
  11169. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11170. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11171. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11172. {
  11173. //Reserved
  11174. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11175. }
  11176. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11177. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11178. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11179. {
  11180. //Reserved
  11181. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11182. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11183. goto end;
  11184. }
  11185. else
  11186. {
  11187. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11188. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11189. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11190. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11191. {
  11192. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11193. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11194. goto end;
  11195. }
  11196. }// END FOR ELSE
  11197. }
  11198. } // END FOR GB_QUANTITY
  11199. }
  11200. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11201. {
  11202. tempIndex = connectorIdInt -1;
  11203. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11204. {
  11205. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11206. {
  11207. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11208. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11209. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11210. {
  11211. //Reserved
  11212. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11213. }
  11214. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11215. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11216. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11217. {
  11218. //Reserved
  11219. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11220. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11221. goto end;
  11222. }
  11223. else
  11224. {
  11225. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11226. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11227. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11228. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11229. {
  11230. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11231. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11232. goto end;
  11233. }
  11234. }// END FOR ELSE
  11235. }
  11236. } // END FOR GB_QUANTITY
  11237. }
  11238. else
  11239. {
  11240. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11241. {
  11242. tempIndex = 2;
  11243. }
  11244. else
  11245. {
  11246. tempIndex = connectorIdInt -1;
  11247. }
  11248. for (int index = 0; index < AC_QUANTITY; index++)
  11249. {
  11250. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11251. {
  11252. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11253. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11254. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11255. {
  11256. //Reserved
  11257. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11258. }
  11259. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11260. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11261. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11262. {
  11263. //Reserved
  11264. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11265. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11266. goto end;
  11267. }
  11268. else
  11269. {
  11270. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11271. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11272. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11273. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11274. {
  11275. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11276. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11277. goto end;
  11278. }
  11279. }//END FOR ELSE
  11280. }
  11281. }// END FOR AC_QUANTITY
  11282. }
  11283. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11284. {
  11285. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11286. {
  11287. // Save profile to file
  11288. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11289. system(cmdBuf);
  11290. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11291. fp = fopen(cmdBuf, "w");
  11292. fprintf(fp, "{\"connectorId\":%d,\"csChargingProfiles\":%s}\n", connectorIdInt, json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11293. fclose(fp);
  11294. }
  11295. else
  11296. {
  11297. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11298. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11299. goto end;
  11300. }
  11301. }
  11302. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11303. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11304. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11305. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11306. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11307. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11308. }
  11309. else
  11310. {
  11311. uint8_t isHasIdleConnector = FALSE;
  11312. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11313. {
  11314. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11315. {
  11316. isHasIdleConnector = TRUE;
  11317. break;
  11318. }
  11319. }
  11320. if(isHasIdleConnector == TRUE)
  11321. {
  11322. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11323. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11324. {
  11325. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11326. {
  11327. // Save profile to file
  11328. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11329. system(cmdBuf);
  11330. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11331. fp = fopen(cmdBuf, "w");
  11332. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11333. fclose(fp);
  11334. refreshStartTimer(&clientTime.RemoteStartWait);
  11335. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11336. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11337. }
  11338. else
  11339. {
  11340. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11341. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11342. }
  11343. }
  11344. else
  11345. {
  11346. refreshStartTimer(&clientTime.RemoteStartWait);
  11347. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11348. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11349. }
  11350. }
  11351. else
  11352. {
  11353. DEBUG_INFO("There is not any connector is idle.\n");
  11354. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11355. }
  11356. }
  11357. }
  11358. else
  11359. {
  11360. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11361. }
  11362. end:
  11363. json_object_put(RemoteStartTransaction);
  11364. sendRemoteStartConfirmation(uuid, comfirmstr);
  11365. return result;
  11366. }
  11367. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11368. {
  11369. mtrace();
  11370. int result = FAIL;
  11371. int match = FALSE;
  11372. int GunNO = 0;
  11373. int tempIndex = 0;
  11374. int transactionIdInt=0;
  11375. int transactionIdIsNULL= TRUE;
  11376. char comfirmstr[20];
  11377. json_object *RemoteStopTransaction;
  11378. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11379. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11380. if(server_pending == TRUE)
  11381. {
  11382. return 0;
  11383. }
  11384. RemoteStopTransaction = json_tokener_parse(payload);
  11385. if(!is_error(RemoteStopTransaction))
  11386. {
  11387. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11388. {
  11389. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11390. transactionIdIsNULL = FALSE;
  11391. }
  11392. }
  11393. json_object_put(RemoteStopTransaction);
  11394. if(transactionIdIsNULL == FALSE)
  11395. {
  11396. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11397. {
  11398. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11399. {
  11400. //check Transaction active
  11401. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11402. {
  11403. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11404. {
  11405. tempIndex = ((gun_index==2) ? 1: 0);
  11406. }
  11407. else
  11408. {
  11409. tempIndex = gun_index;
  11410. }
  11411. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11412. {
  11413. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11414. {
  11415. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11416. {
  11417. match = TRUE;
  11418. GunNO = gun_index;
  11419. }
  11420. }
  11421. }// END FOR CHAdeMO_QUANTITY
  11422. }
  11423. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11424. {
  11425. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11426. {
  11427. tempIndex = ((gun_index==2) ? 1: 0);
  11428. }
  11429. else
  11430. {
  11431. tempIndex = gun_index;
  11432. }
  11433. for (int index = 0; index < CCS_QUANTITY; index++)
  11434. {
  11435. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11436. {
  11437. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11438. {
  11439. match = TRUE;
  11440. GunNO = gun_index;
  11441. }
  11442. }
  11443. }// END FOR CCS_QUANTITY
  11444. }
  11445. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11446. {
  11447. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11448. {
  11449. tempIndex = ((gun_index==2) ? 1: 0);
  11450. }
  11451. else
  11452. {
  11453. tempIndex = gun_index;
  11454. }
  11455. for (int index = 0; index < GB_QUANTITY; index++)
  11456. {
  11457. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11458. {
  11459. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11460. {
  11461. match = TRUE;
  11462. GunNO = gun_index;
  11463. }
  11464. }
  11465. }// END FOR GB_QUANTITY
  11466. }
  11467. else if(gunType[gun_index] == GUN_TYPE_DO)
  11468. {
  11469. tempIndex = gun_index;
  11470. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11471. {
  11472. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11473. {
  11474. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11475. {
  11476. match = TRUE;
  11477. GunNO = gun_index;
  11478. }
  11479. }
  11480. }// END FOR GB_QUANTITY
  11481. }
  11482. else
  11483. {
  11484. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11485. {
  11486. tempIndex = 2;
  11487. }
  11488. else
  11489. {
  11490. tempIndex = gun_index;
  11491. }
  11492. for (int index = 0; index < AC_QUANTITY; index++)
  11493. {
  11494. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11495. {
  11496. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11497. {
  11498. match = TRUE;
  11499. GunNO = gun_index;
  11500. }
  11501. }
  11502. }// END FOR CHAdeMO_QUANTITY
  11503. } // END FOR AC ELSE
  11504. }// CHECK IF ResponseTransactionId == transactionIdInt
  11505. }//END FOR
  11506. if( match == TRUE)
  11507. {
  11508. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11509. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11510. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11511. }
  11512. else
  11513. {
  11514. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11515. }
  11516. }
  11517. else
  11518. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11519. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11520. return result;
  11521. }
  11522. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11523. {
  11524. mtrace();
  11525. int result = FAIL;
  11526. int connectorIdInt=0, reservationIdInt=0;
  11527. int tempIndex = 0;
  11528. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  11529. char comfirmstr[20]={0};
  11530. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11531. int c = 0;
  11532. char *loc;
  11533. //char *ptr;
  11534. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11535. strcpy(sstrtemp, stringtrimspace(payload));
  11536. //***(1)connectorId ****/
  11537. c=0;
  11538. loc = strstr(sstrtemp, "connectorId");
  11539. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11540. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11541. {
  11542. sstr[c] = loc[strlen("connectorId")+2+c];
  11543. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11544. c++;
  11545. }
  11546. sstr[c] = '\0';
  11547. connectorIdInt = atoi(sstr);
  11548. //***(2)expiryDate ****/
  11549. loc = strstr(sstrtemp, "expiryDate");
  11550. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11551. c = 0;
  11552. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11553. {
  11554. sstr[c] = loc[3+strlen("expiryDate")+c];
  11555. c++;
  11556. }
  11557. sstr[c] = '\0';
  11558. strcpy(expiryDatestr, sstr);
  11559. //***(3)idTag ****/
  11560. loc = strstr(sstrtemp, "idTag");
  11561. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11562. c = 0;
  11563. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11564. {
  11565. sstr[c] = loc[3+strlen("idTag")+c];
  11566. c++;
  11567. }
  11568. sstr[c] = '\0';
  11569. strcpy(idTagstr, sstr);
  11570. //***(4)parentIdTag ****/
  11571. loc = strstr(sstrtemp, "parentIdTag");
  11572. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11573. c = 0;
  11574. if(loc == NULL)
  11575. {
  11576. strcpy(parentIdTagstr, "");
  11577. }
  11578. else
  11579. {
  11580. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11581. {
  11582. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11583. c++;
  11584. }
  11585. sstr[c] = '\0';
  11586. strcpy(parentIdTagstr, sstr);
  11587. }
  11588. //***(5)reservationId ****/
  11589. c=0;
  11590. loc = strstr(sstrtemp, "reservationId");
  11591. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11592. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11593. {
  11594. sstr[c] = loc[strlen("reservationId")+2+c];
  11595. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11596. c++;
  11597. }
  11598. sstr[c] = '\0';
  11599. reservationIdInt = atoi(sstr);
  11600. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11601. /*
  11602. enum SYSTEM_STATUS
  11603. {
  11604. SYS_MODE_BOOTING = 0,
  11605. SYS_MODE_IDLE = 1,
  11606. SYS_MODE_AUTHORIZING = 2,
  11607. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11608. SYS_MODE_REASSIGN = 4,
  11609. SYS_MODE_PREPARING = 5,
  11610. SYS_MODE_PREPARE_FOR_EV = 6,
  11611. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11612. SYS_MODE_CHARGING = 8,
  11613. SYS_MODE_TERMINATING = 9,
  11614. SYS_MODE_COMPLETE = 10,
  11615. SYS_MODE_ALARM = 11,
  11616. SYS_MODE_FAULT = 12,
  11617. SYS_MODE_RESERVATION = 13,
  11618. SYS_MODE_BOOKING = 14,
  11619. SYS_MODE_MAINTAIN = 15,
  11620. SYS_MODE_DEBUG = 16,
  11621. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11622. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11623. SYS_MODE_UPDATE = 19
  11624. };
  11625. */
  11626. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11627. {
  11628. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11629. goto end;
  11630. }
  11631. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11632. {
  11633. //check Transaction active
  11634. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11635. {
  11636. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11637. {
  11638. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11639. }
  11640. else
  11641. {
  11642. tempIndex = connectorIdInt -1;
  11643. }
  11644. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11645. {
  11646. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11647. {
  11648. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11649. {
  11650. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11651. {
  11652. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11653. {
  11654. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11655. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11656. }
  11657. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  11658. {
  11659. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11660. }
  11661. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11662. {
  11663. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11664. }
  11665. else
  11666. {
  11667. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11668. }
  11669. }
  11670. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_FAULT, SYS_MODE_ALARM, SYS_MODE_TERMINATING ---> SuspendedEV
  11671. {
  11672. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11673. }
  11674. }
  11675. else
  11676. {
  11677. //replace reservation
  11678. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11679. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11680. }
  11681. }
  11682. } // END FOR CHAdeMO_QUANTITY
  11683. }
  11684. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11685. {
  11686. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11687. {
  11688. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11689. }
  11690. else
  11691. {
  11692. tempIndex = connectorIdInt -1;
  11693. }
  11694. for (int index = 0; index < CCS_QUANTITY; index++)
  11695. {
  11696. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11697. {
  11698. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11699. {
  11700. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11701. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11702. {
  11703. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11704. {
  11705. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11706. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11707. }
  11708. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) ||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  11709. {
  11710. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11711. }
  11712. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11713. {
  11714. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11715. }
  11716. else
  11717. {
  11718. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11719. }
  11720. }
  11721. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_ALARM) ||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAUL, SYS_MODE_TERMINATING ---> SuspendedEV
  11722. {
  11723. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11724. }
  11725. }
  11726. else
  11727. {
  11728. //replace reservation
  11729. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11730. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11731. }
  11732. }
  11733. } // END FOR CCS_QUANTITY
  11734. }
  11735. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11736. {
  11737. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11738. {
  11739. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11740. }
  11741. else
  11742. {
  11743. tempIndex = connectorIdInt -1;
  11744. }
  11745. for (int index = 0; index < GB_QUANTITY; index++)
  11746. {
  11747. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11748. {
  11749. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11750. {
  11751. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11752. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11753. {
  11754. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11755. {
  11756. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11757. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11758. }
  11759. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  11760. {
  11761. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11762. }
  11763. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11764. {
  11765. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11766. }
  11767. else
  11768. {
  11769. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11770. }
  11771. }
  11772. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_ALARM ,SYS_MODE_TERMINATING ---> SuspendedEV
  11773. {
  11774. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11775. }
  11776. }
  11777. else
  11778. {
  11779. //replace reservation
  11780. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11781. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11782. }
  11783. }
  11784. }// END FOR GB_QUANTITY
  11785. }
  11786. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11787. {
  11788. tempIndex = connectorIdInt -1;
  11789. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11790. {
  11791. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11792. {
  11793. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11794. {
  11795. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11796. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11797. {
  11798. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11799. {
  11800. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11801. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11802. }
  11803. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  11804. {
  11805. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11806. }
  11807. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11808. {
  11809. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11810. }
  11811. else
  11812. {
  11813. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11814. }
  11815. }
  11816. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_ALARM ,SYS_MODE_TERMINATING ---> SuspendedEV
  11817. {
  11818. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11819. }
  11820. }
  11821. else
  11822. {
  11823. //replace reservation
  11824. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11825. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11826. }
  11827. }
  11828. }// END FOR GB_QUANTITY
  11829. }
  11830. else
  11831. {
  11832. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11833. {
  11834. tempIndex = 2;
  11835. }
  11836. else
  11837. {
  11838. tempIndex = (connectorIdInt -1);
  11839. }
  11840. for (int index = 0; index < AC_QUANTITY; index++)
  11841. {
  11842. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11843. {
  11844. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11845. {
  11846. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11847. {
  11848. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11849. {
  11850. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  11851. {
  11852. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11853. }
  11854. else
  11855. {
  11856. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11857. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11858. }
  11859. }
  11860. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  11861. {
  11862. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11863. }
  11864. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11865. {
  11866. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11867. }
  11868. else
  11869. {
  11870. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11871. }
  11872. }
  11873. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_ALARM, SYS_MODE_TERMINATING ---> SuspendedEV
  11874. {
  11875. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11876. }
  11877. }
  11878. else
  11879. {
  11880. //replace reservation
  11881. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11882. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11883. }
  11884. }
  11885. } // END FOR AC_QUANTITY
  11886. }
  11887. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11888. }
  11889. else if(connectorIdInt == 0)
  11890. {
  11891. //check Transaction active
  11892. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11893. {
  11894. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11895. {
  11896. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  11897. {
  11898. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11899. goto end;
  11900. }
  11901. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11902. {
  11903. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11904. goto end;
  11905. }
  11906. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  11907. {
  11908. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11909. goto end;
  11910. }
  11911. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11912. {
  11913. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11914. goto end;
  11915. }
  11916. }
  11917. }// END FOR CHAdeMO_QUANTITY
  11918. for (int index = 0; index < CCS_QUANTITY; index++)
  11919. {
  11920. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11921. {
  11922. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  11923. {
  11924. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11925. goto end;
  11926. }
  11927. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11928. {
  11929. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11930. goto end;
  11931. }
  11932. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  11933. {
  11934. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11935. goto end;
  11936. }
  11937. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11938. {
  11939. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11940. goto end;
  11941. }
  11942. }
  11943. } // END FOR CCS_QUANTITY
  11944. for (int index = 0; index < GB_QUANTITY; index++)
  11945. {
  11946. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11947. {
  11948. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  11949. {
  11950. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11951. goto end;
  11952. }
  11953. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11954. {
  11955. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11956. goto end;
  11957. }
  11958. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_TERMINATING) ) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  11959. {
  11960. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11961. goto end;
  11962. }
  11963. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11964. {
  11965. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11966. goto end;
  11967. }
  11968. }
  11969. } // END FOR GB_QUANTITY
  11970. for (int index = 0; index < AC_QUANTITY; index++)
  11971. {
  11972. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11973. {
  11974. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  11975. {
  11976. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11977. goto end;
  11978. }
  11979. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11980. {
  11981. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11982. goto end;
  11983. }
  11984. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  11985. {
  11986. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11987. goto end;
  11988. }
  11989. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11990. {
  11991. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  11992. {
  11993. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11994. goto end;
  11995. }
  11996. }
  11997. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11998. {
  11999. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12000. goto end;
  12001. }
  12002. }
  12003. }// END FOR AC_QUANTITY
  12004. //The connectorId is 0
  12005. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  12006. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12007. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  12008. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  12009. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  12010. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  12011. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  12012. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  12013. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  12014. result = TRUE;
  12015. return result;
  12016. }
  12017. else
  12018. {
  12019. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12020. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12021. }
  12022. if(strcmp(comfirmstr,"Accepted") == 0)
  12023. {
  12024. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  12025. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  12026. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  12027. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  12028. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  12029. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12030. result = TRUE;
  12031. return result;
  12032. }
  12033. end:
  12034. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  12035. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  12036. return result;
  12037. }
  12038. int handleResetRequest(char *uuid, char *payload)
  12039. {
  12040. mtrace();
  12041. int result = FAIL;
  12042. char sstr[10]={0},sstrtemp[30]={ 0 };
  12043. char typestr[10]={0};
  12044. char comfirmstr[20]={0};
  12045. int c = 0;
  12046. char *loc;
  12047. DEBUG_INFO("handleResetRequest...\n");
  12048. strcpy(sstrtemp, stringtrimspace(payload));
  12049. loc = strstr(sstrtemp, "type");
  12050. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12051. c = 0;
  12052. while (loc[3+strlen("type")+c] != '\"')
  12053. {
  12054. sstr[c] = loc[3+strlen("type")+c];
  12055. c++;
  12056. }
  12057. sstr[c] = '\0';
  12058. strcpy(typestr,sstr);
  12059. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  12060. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  12061. {
  12062. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  12063. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  12064. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  12065. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12066. }
  12067. else
  12068. {
  12069. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  12070. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12071. result = PASS;
  12072. }
  12073. sendResetConfirmation(uuid, comfirmstr);
  12074. return result;
  12075. }
  12076. int handleSendLocalListRequest(char *uuid, char *payload)
  12077. {
  12078. mtrace();
  12079. int result = FAIL;
  12080. char comfirmstr[20];
  12081. int checkState_Faulted = FALSE;
  12082. json_object *SendLocalList;
  12083. DEBUG_INFO("handleSendLocalListRequest...\n");
  12084. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  12085. {
  12086. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12087. goto end;
  12088. }
  12089. //check Charge Point state
  12090. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12091. {
  12092. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12093. {
  12094. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12095. }
  12096. }
  12097. for (int index = 0; index < CCS_QUANTITY; index++)
  12098. {
  12099. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12100. {
  12101. checkState_Faulted = TRUE; //OCPP Status
  12102. }
  12103. }
  12104. for (int index = 0; index < GB_QUANTITY; index++)
  12105. {
  12106. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12107. {
  12108. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12109. }
  12110. }
  12111. //check Charge Point state
  12112. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12113. {
  12114. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12115. {
  12116. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12117. }
  12118. }
  12119. //check Charge Point state
  12120. for (int index = 0; index < AC_QUANTITY; index++)
  12121. {
  12122. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12123. {
  12124. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12125. }
  12126. }
  12127. if(checkState_Faulted == TRUE)
  12128. {
  12129. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12130. goto end;
  12131. }
  12132. // Parsing payload
  12133. SendLocalList = json_tokener_parse(payload);
  12134. if(!is_error(SendLocalList))
  12135. {
  12136. // Required data
  12137. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12138. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12139. // Optional data
  12140. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12141. {
  12142. //Check UpdateType
  12143. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12144. {
  12145. //Local list full update
  12146. DEBUG_INFO("Local list full update.\n");
  12147. OCPP_getListVerion();
  12148. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12149. {
  12150. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12151. goto end;
  12152. }
  12153. OCPP_cleanLocalList();
  12154. }
  12155. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12156. {
  12157. //Local list different update
  12158. DEBUG_INFO("Local list different update.\n");
  12159. OCPP_getListVerion();
  12160. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12161. {
  12162. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12163. goto end;
  12164. }
  12165. }
  12166. else
  12167. {
  12168. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12169. goto end;
  12170. }
  12171. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12172. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12173. {
  12174. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag")));
  12175. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12176. {
  12177. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "status")));
  12178. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12179. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate")));
  12180. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12181. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag")));
  12182. }
  12183. // Add to db
  12184. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12185. {
  12186. //Local list full update
  12187. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12188. idx,
  12189. ShmOCPP16Data->SendLocalList.ListVersion,
  12190. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12191. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12192. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12193. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12194. // update list
  12195. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12196. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12197. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12198. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12199. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12200. }
  12201. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12202. {
  12203. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12204. idx,
  12205. ShmOCPP16Data->SendLocalList.ListVersion,
  12206. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12207. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12208. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12209. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12210. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12211. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12212. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12213. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12214. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12215. }
  12216. }
  12217. }
  12218. else
  12219. {
  12220. //Check UpdateType
  12221. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12222. {
  12223. //Local list full update
  12224. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12225. OCPP_cleanLocalList();
  12226. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12227. goto end;
  12228. }
  12229. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12230. {
  12231. //Local list different update
  12232. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12233. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12234. goto end;
  12235. }
  12236. }
  12237. result = PASS;
  12238. }
  12239. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12240. end:
  12241. json_object_put(SendLocalList);
  12242. sendSendLocalListConfirmation(uuid, comfirmstr);
  12243. return result;
  12244. }
  12245. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12246. {
  12247. mtrace();
  12248. int result = FAIL;
  12249. struct StructSetChargingProfile SetProfileReq = {0};
  12250. int tempchargingProfileIdInt;
  12251. int tempstackLevelInt;
  12252. int chargingSchedulePeriodCount = 0;
  12253. char comfirmstr[20]={0};
  12254. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  12255. char rmFileCmd[128]={0};
  12256. int profileQuantity = 0;
  12257. int isReplaceable = FALSE;
  12258. json_object *SetChargingProfile;
  12259. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12260. SetChargingProfile = json_tokener_parse(payload);
  12261. if(!is_error(SetChargingProfile))
  12262. {
  12263. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12264. {
  12265. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12266. }
  12267. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12268. {
  12269. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12270. {
  12271. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12272. }
  12273. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12274. {
  12275. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12276. }
  12277. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12278. {
  12279. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12280. }
  12281. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12282. {
  12283. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12284. }
  12285. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12286. {
  12287. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12288. }
  12289. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12290. {
  12291. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12292. }
  12293. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12294. {
  12295. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12296. }
  12297. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12298. {
  12299. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12300. }
  12301. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12302. {
  12303. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12304. {
  12305. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  12306. }
  12307. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12308. {
  12309. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12310. }
  12311. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12312. {
  12313. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12314. }
  12315. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12316. {
  12317. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.StartSchedule, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  12318. }
  12319. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12320. {
  12321. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12322. if(chargingSchedulePeriodCount <= 10)
  12323. {
  12324. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  12325. {
  12326. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod") != NULL)
  12327. {
  12328. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  12329. }
  12330. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit") != NULL)
  12331. {
  12332. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  12333. }
  12334. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases") != NULL)
  12335. {
  12336. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  12337. }
  12338. }
  12339. }
  12340. }
  12341. }
  12342. }
  12343. }
  12344. // Profile periods quantity check
  12345. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12346. {
  12347. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12348. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12349. goto end;
  12350. }
  12351. // Check invalid limit
  12352. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12353. {
  12354. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12355. {
  12356. if(((0 < SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit) && (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit < (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='A'?6:6*220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)))) ||
  12357. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12358. {
  12359. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12360. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12361. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12362. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12363. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12364. goto end;
  12365. }
  12366. }
  12367. }
  12368. else
  12369. {
  12370. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12371. {
  12372. if((SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?1:220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)) > modelnameInfo.ratedPower) ||
  12373. (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*0.01)))
  12374. {
  12375. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12376. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12377. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12378. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12379. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12380. goto end;
  12381. }
  12382. }
  12383. }
  12384. // Profile purpose info check
  12385. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12386. {
  12387. FILE *fp;
  12388. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12389. if(SetProfileReq.ConnectorId != 0)
  12390. {
  12391. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12392. DEBUG_WARN("Profile connector id is not 0.\n");
  12393. goto end;
  12394. }
  12395. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12396. if (!fp)
  12397. {
  12398. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12399. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12400. }
  12401. else
  12402. {
  12403. char *line = NULL;
  12404. size_t len = 0;
  12405. while(getline(&line, &len, fp) != -1)
  12406. {
  12407. json_object *obj = NULL;
  12408. obj = json_tokener_parse(line);
  12409. if(is_error(obj))
  12410. {
  12411. DEBUG_ERROR("Parse txProfile from file error.\n");
  12412. }
  12413. else
  12414. {
  12415. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12416. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12417. {
  12418. profileQuantity += 1;
  12419. }
  12420. else
  12421. isReplaceable = TRUE;
  12422. }
  12423. }
  12424. }
  12425. fclose(fp);
  12426. }
  12427. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12428. {
  12429. FILE *fp;
  12430. char filename[128]={0};
  12431. int tmpProfileQuantity;
  12432. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12433. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12434. {
  12435. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12436. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12437. goto end;
  12438. }
  12439. if(SetProfileReq.ConnectorId == 0)
  12440. {
  12441. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12442. {
  12443. tmpProfileQuantity = 0;
  12444. memset(filename, 0, ARRAY_SIZE(filename));
  12445. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12446. fp = fopen(filename, "r");
  12447. if (!fp)
  12448. {
  12449. DEBUG_INFO("%s does not create.\n", filename);
  12450. fp = fopen(filename, "w+");
  12451. }
  12452. else
  12453. {
  12454. char *line = NULL;
  12455. size_t len = 0;
  12456. while(getline(&line, &len, fp) != -1)
  12457. {
  12458. json_object *obj = NULL;
  12459. obj = json_tokener_parse(line);
  12460. if(is_error(obj))
  12461. {
  12462. DEBUG_ERROR("Parse txProfile from file error.\n");
  12463. }
  12464. else
  12465. {
  12466. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12467. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12468. {
  12469. tmpProfileQuantity += 1;
  12470. }
  12471. else
  12472. isReplaceable = TRUE;
  12473. }
  12474. }
  12475. }
  12476. fclose(fp);
  12477. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12478. }
  12479. }
  12480. else
  12481. {
  12482. memset(filename, 0, ARRAY_SIZE(filename));
  12483. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12484. fp = fopen(filename, "r");
  12485. if (!fp)
  12486. {
  12487. DEBUG_INFO("%s does not create.\n", filename);
  12488. fp = fopen(filename, "w+");
  12489. }
  12490. else
  12491. {
  12492. char *line = NULL;
  12493. size_t len = 0;
  12494. while(getline(&line, &len, fp) != -1)
  12495. {
  12496. json_object *obj = NULL;
  12497. obj = json_tokener_parse(line);
  12498. if(is_error(obj))
  12499. {
  12500. DEBUG_ERROR("Parse txProfile from file error.\n");
  12501. }
  12502. else
  12503. {
  12504. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12505. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12506. {
  12507. profileQuantity += 1;
  12508. }
  12509. else
  12510. isReplaceable = TRUE;
  12511. }
  12512. }
  12513. }
  12514. fclose(fp);
  12515. }
  12516. }
  12517. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12518. {
  12519. int isMatchTransactiodId= FALSE;
  12520. FILE *fp;
  12521. char filename[128]={0};
  12522. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12523. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12524. if(SetProfileReq.ConnectorId == 0)
  12525. {
  12526. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12527. DEBUG_WARN("Profile connector id is 0.\n");
  12528. goto end;
  12529. }
  12530. int tempIndex = 0;
  12531. //check Transaction active
  12532. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12533. {
  12534. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12535. {
  12536. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12537. }
  12538. else
  12539. {
  12540. tempIndex = SetProfileReq.ConnectorId -1;
  12541. }
  12542. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12543. {
  12544. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12545. {
  12546. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12547. {
  12548. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12549. {
  12550. isMatchTransactiodId = TRUE;
  12551. break;
  12552. }
  12553. }
  12554. }
  12555. }
  12556. }
  12557. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12558. {
  12559. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12560. {
  12561. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12562. }
  12563. else
  12564. {
  12565. tempIndex = SetProfileReq.ConnectorId -1;
  12566. }
  12567. for (int index = 0; index < CCS_QUANTITY; index++)
  12568. {
  12569. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12570. {
  12571. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12572. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12573. {
  12574. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12575. {
  12576. isMatchTransactiodId = TRUE;
  12577. break;
  12578. }
  12579. }
  12580. }
  12581. }
  12582. }
  12583. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12584. {
  12585. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12586. {
  12587. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12588. }
  12589. else
  12590. {
  12591. tempIndex = SetProfileReq.ConnectorId -1;
  12592. }
  12593. for (int index = 0; index < GB_QUANTITY; index++)
  12594. {
  12595. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12596. {
  12597. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12598. {
  12599. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12600. {
  12601. isMatchTransactiodId = TRUE;
  12602. break;
  12603. }
  12604. }
  12605. }
  12606. }
  12607. }
  12608. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12609. {
  12610. tempIndex = SetProfileReq.ConnectorId -1;
  12611. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12612. {
  12613. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12614. {
  12615. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12616. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12617. {
  12618. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12619. {
  12620. isMatchTransactiodId = TRUE;
  12621. break;
  12622. }
  12623. }
  12624. }
  12625. }
  12626. }
  12627. else
  12628. {
  12629. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12630. {
  12631. tempIndex = 2;
  12632. }
  12633. else
  12634. {
  12635. tempIndex = (SetProfileReq.ConnectorId -1);
  12636. }
  12637. for (int index = 0; index < AC_QUANTITY; index++)
  12638. {
  12639. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12640. {
  12641. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12642. {
  12643. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12644. {
  12645. isMatchTransactiodId = TRUE;
  12646. break;
  12647. }
  12648. }
  12649. }
  12650. }
  12651. }
  12652. //check Transaction active
  12653. if(isMatchTransactiodId == FALSE)
  12654. {
  12655. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12656. DEBUG_WARN("Tx profile transaction id is not match.\n");
  12657. goto end;
  12658. }
  12659. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12660. {
  12661. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12662. DEBUG_WARN("Connector id is over max gun number.\n");
  12663. goto end;
  12664. }
  12665. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12666. fp = fopen(filename, "r");
  12667. if (!fp)
  12668. {
  12669. DEBUG_INFO("%s does not create.\n", filename);
  12670. fp = fopen(filename, "w+");
  12671. }
  12672. else
  12673. {
  12674. char *line = NULL;
  12675. size_t len = 0;
  12676. while(getline(&line, &len, fp) != -1)
  12677. {
  12678. json_object *obj = NULL;
  12679. obj = json_tokener_parse(line);
  12680. if(is_error(obj))
  12681. {
  12682. DEBUG_ERROR("Parse txProfile from file error.\n");
  12683. }
  12684. else
  12685. {
  12686. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12687. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12688. {
  12689. profileQuantity += 1;
  12690. }
  12691. else
  12692. isReplaceable = TRUE;
  12693. }
  12694. }
  12695. }
  12696. fclose(fp);
  12697. }
  12698. // Check ChargeProfileMaxStackLevel
  12699. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12700. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12701. {
  12702. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12703. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12704. goto end;
  12705. }
  12706. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12707. {
  12708. FILE *fp;
  12709. char dataLine[4096]={0};
  12710. char fnametemp[128]={0};
  12711. int tmpProfileQuantity;
  12712. //Check ChargePointMaxProfile.json exit
  12713. profileQuantity = 0;
  12714. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12715. {
  12716. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  12717. //Check Charging Profile Count
  12718. tmpProfileQuantity = 0;
  12719. while(fscanf(fp, "%s", dataLine) != EOF)
  12720. {
  12721. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12722. {
  12723. profileQuantity += 1;
  12724. tmpProfileQuantity += 1;
  12725. }
  12726. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12727. }
  12728. fclose(fp);
  12729. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12730. }
  12731. //Check TxDefaultProfile_%d.json
  12732. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12733. {
  12734. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12735. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12736. if((access(fnametemp,F_OK))!=-1)
  12737. {
  12738. fp = fopen(fnametemp, "r");
  12739. //Check Charging Profile Count
  12740. tmpProfileQuantity = 0;
  12741. while(fscanf(fp, "%s", dataLine) != EOF)
  12742. {
  12743. //DEBUG_INFO("word=%s\n",word);
  12744. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12745. {
  12746. profileQuantity += 1;
  12747. tmpProfileQuantity += 1;
  12748. }
  12749. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12750. }
  12751. fclose(fp);
  12752. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12753. }
  12754. }
  12755. //Check TxProfile_%d.json
  12756. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12757. {
  12758. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12759. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  12760. if((access(fnametemp,F_OK))!=-1)
  12761. {
  12762. fp = fopen(fnametemp, "r");
  12763. //Check Charging Profile Count
  12764. tmpProfileQuantity = 0;
  12765. while(fscanf(fp, "%s", dataLine) != EOF)
  12766. {
  12767. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12768. {
  12769. profileQuantity += 1;
  12770. tmpProfileQuantity += 1;
  12771. }
  12772. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12773. }
  12774. fclose(fp);
  12775. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12776. }
  12777. }
  12778. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12779. if((profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData)) && (isReplaceable != TRUE))
  12780. {
  12781. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12782. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12783. goto end;
  12784. }
  12785. }
  12786. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12787. //**********************************Write to File********************************************************/
  12788. {
  12789. FILE *infile;
  12790. FILE *outfile;
  12791. char dataLine[4096]={0};
  12792. char filename[128]={0};
  12793. int chkChar=0;
  12794. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12795. {
  12796. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12797. {
  12798. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12799. }
  12800. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12801. {
  12802. if(SetProfileReq.ConnectorId==0)
  12803. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12804. else
  12805. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12806. }
  12807. else
  12808. {
  12809. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12810. }
  12811. infile = fopen (filename, "r");
  12812. outfile = fopen (tempfile, "w");
  12813. chkChar = fgetc(infile);
  12814. rewind(infile);
  12815. if(chkChar == EOF)
  12816. {
  12817. // Profile is empty
  12818. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12819. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12820. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12821. fclose(infile);
  12822. fclose(outfile);
  12823. sprintf(rmFileCmd,"rm -f %s",filename);
  12824. system(rmFileCmd);
  12825. rename(tempfile, filename);
  12826. }
  12827. else
  12828. {
  12829. // Profile is not empty
  12830. int ChargingProfileAdded = FALSE;
  12831. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12832. {
  12833. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12834. json_object *tmpChargingProfile;
  12835. tmpChargingProfile = json_tokener_parse(dataLine);
  12836. if(!is_error(SetChargingProfile))
  12837. {
  12838. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12839. {
  12840. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12841. {
  12842. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12843. }
  12844. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12845. {
  12846. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  12847. }
  12848. }
  12849. }
  12850. json_object_put(tmpChargingProfile);
  12851. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12852. {
  12853. if(ChargingProfileAdded == FALSE)
  12854. {
  12855. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12856. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12857. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12858. ChargingProfileAdded = TRUE;
  12859. }
  12860. }
  12861. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  12862. {
  12863. if(ChargingProfileAdded == FALSE)
  12864. {
  12865. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12866. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12867. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12868. ChargingProfileAdded = TRUE;
  12869. }
  12870. }
  12871. else
  12872. {
  12873. fprintf(outfile,"%s\n",dataLine);
  12874. if(ChargingProfileAdded == FALSE)
  12875. {
  12876. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12877. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12878. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12879. ChargingProfileAdded = TRUE;
  12880. }
  12881. }
  12882. } // end of while loop
  12883. fclose(infile);
  12884. fclose(outfile);
  12885. sprintf(rmFileCmd,"rm -f %s",filename);
  12886. system(rmFileCmd);
  12887. rename(tempfile, filename);
  12888. }
  12889. }
  12890. sleep(1);
  12891. result = TRUE;
  12892. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12893. }
  12894. end:
  12895. json_object_put(SetChargingProfile);
  12896. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12897. {
  12898. if(SetProfileReq.ConnectorId == 0)
  12899. {
  12900. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12901. {
  12902. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  12903. }
  12904. }
  12905. else
  12906. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12907. }
  12908. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12909. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12910. return result;
  12911. }
  12912. int handleTriggerMessageRequest(char *uuid, char *payload)
  12913. {
  12914. mtrace();
  12915. int result = FAIL;
  12916. int connectorIdIsNULL = FALSE;
  12917. int connectorIdInt =0;
  12918. char sstr[40]={0},sstrtemp[100]={ 0 };
  12919. char requestedMessagestr[40]={0};
  12920. char comfirmstr[20]={0};
  12921. int c = 0;
  12922. char *loc;
  12923. DEBUG_INFO("handleTriggerMessageRequest\n");
  12924. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12925. strcpy(sstrtemp, stringtrimspace(payload));
  12926. c = 0;
  12927. loc = strstr(sstrtemp, "requestedMessage");
  12928. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12929. {
  12930. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12931. c++;
  12932. }
  12933. sstr[c] = '\0';
  12934. strcpy(requestedMessagestr, sstr);
  12935. c = 0;
  12936. loc = strstr(sstrtemp, "connectorId");
  12937. if(loc == NULL)
  12938. {
  12939. connectorIdIsNULL = TRUE;
  12940. }
  12941. else
  12942. {
  12943. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12944. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12945. {
  12946. sstr[c] = loc[strlen("connectorId")+2+c];
  12947. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12948. c++;
  12949. }
  12950. sstr[c] = '\0';
  12951. connectorIdInt = atoi(sstr);
  12952. }
  12953. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12954. {
  12955. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12956. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12957. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12958. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12959. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12960. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12961. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12962. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12963. {
  12964. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12965. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12966. return TRUE;
  12967. }
  12968. else
  12969. {
  12970. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12971. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12972. }
  12973. }
  12974. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12975. {
  12976. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12977. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12978. return TRUE;
  12979. }
  12980. //==========================
  12981. // Trigger message
  12982. //==========================
  12983. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12984. {
  12985. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  12986. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12987. {
  12988. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12989. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12990. }
  12991. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12992. }
  12993. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12994. {
  12995. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  12996. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12997. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12998. }
  12999. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  13000. {
  13001. //sendBootNotificationRequest();
  13002. server_sign = FALSE;
  13003. }
  13004. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  13005. {
  13006. refreshStartTimer(&clientTime.Heartbeat);
  13007. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13008. }
  13009. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  13010. {
  13011. if(connectorIdIsNULL == FALSE)
  13012. {
  13013. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13014. {
  13015. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  13016. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  13017. }
  13018. }
  13019. else
  13020. {
  13021. for(int idx=0;idx< gunTotalNumber;idx++)
  13022. {
  13023. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13024. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13025. }
  13026. }
  13027. }
  13028. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  13029. {
  13030. if(connectorIdIsNULL == FALSE)
  13031. {
  13032. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13033. {
  13034. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  13035. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  13036. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13037. }
  13038. }
  13039. else
  13040. {
  13041. for(int idx=0;idx< gunTotalNumber;idx++)
  13042. {
  13043. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  13044. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13045. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13046. }
  13047. }
  13048. }
  13049. return result;
  13050. }
  13051. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13052. {
  13053. mtrace();
  13054. int result = FAIL;
  13055. int connectorIdInt =0;
  13056. char comfirmstr[20]={0};
  13057. int tempIndex = 0;
  13058. json_object *UnlockConnector;
  13059. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13060. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13061. UnlockConnector = json_tokener_parse(payload);
  13062. if(!is_error(UnlockConnector))
  13063. {
  13064. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13065. {
  13066. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13067. }
  13068. }
  13069. json_object_put(UnlockConnector);
  13070. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13071. if(gunTotalNumber == 0)
  13072. {
  13073. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13074. goto end;
  13075. }
  13076. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13077. {
  13078. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13079. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13080. goto end;
  13081. }
  13082. else
  13083. {
  13084. //check Transaction active
  13085. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13086. {
  13087. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13088. {
  13089. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13090. }
  13091. else
  13092. {
  13093. tempIndex = connectorIdInt -1;
  13094. }
  13095. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13096. {
  13097. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13098. {
  13099. //stop Transaction
  13100. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13101. }
  13102. }
  13103. }
  13104. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13105. {
  13106. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13107. {
  13108. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13109. }
  13110. else
  13111. {
  13112. tempIndex = connectorIdInt -1;
  13113. }
  13114. for (int index = 0; index < CCS_QUANTITY; index++)
  13115. {
  13116. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13117. {
  13118. //stop Transaction
  13119. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13120. }
  13121. }
  13122. }
  13123. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13124. {
  13125. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13126. {
  13127. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13128. }
  13129. else
  13130. {
  13131. tempIndex = connectorIdInt -1;
  13132. }
  13133. for (int index = 0; index < GB_QUANTITY; index++)
  13134. {
  13135. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13136. {
  13137. //stop Transaction
  13138. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13139. }
  13140. }
  13141. }
  13142. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13143. {
  13144. tempIndex = connectorIdInt -1;
  13145. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13146. {
  13147. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13148. {
  13149. //stop Transaction
  13150. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13151. }
  13152. }
  13153. }
  13154. else
  13155. {
  13156. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13157. {
  13158. tempIndex = 2;
  13159. }
  13160. else
  13161. {
  13162. tempIndex = connectorIdInt-1;
  13163. }
  13164. for (int index = 0; index < AC_QUANTITY; index++)
  13165. {
  13166. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  13167. {
  13168. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13169. }
  13170. }
  13171. }
  13172. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  13173. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  13174. result = TRUE;
  13175. return result;
  13176. }
  13177. end:
  13178. //json_object_put(obj); --- remove temporally
  13179. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  13180. return result;
  13181. }
  13182. static char UpdateFirmwarepayloadData[300]={0};
  13183. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13184. {
  13185. mtrace();
  13186. int result = FAIL;
  13187. pthread_t t;
  13188. sendUpdateFirmwareConfirmation(uuid);
  13189. memset(UpdateFirmwarepayloadData, 0, 300);
  13190. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  13191. if(!interLock.isUpdateFirmwareGoing)
  13192. {
  13193. interLock.isUpdateFirmwareGoing = 1;
  13194. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  13195. sleep(1);
  13196. }
  13197. else
  13198. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13199. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  13200. return result;
  13201. }
  13202. void *UpdateFirmwareProcess(void *data)
  13203. {
  13204. pthread_detach(pthread_self());
  13205. mtrace();
  13206. int retriesInt =0, retryIntervalInt=0;
  13207. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  13208. int port=0;
  13209. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  13210. int isSuccess = 0;
  13211. char ftpbuf[1024];
  13212. char temp[1024];
  13213. char * pch;
  13214. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13215. json_object *UpdateFirmware;
  13216. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  13217. if(!is_error(UpdateFirmware))
  13218. {
  13219. // Required data
  13220. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13221. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13222. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13223. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13224. // Optional data
  13225. if(json_object_object_get(UpdateFirmware, "retries"))
  13226. {
  13227. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13228. }
  13229. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13230. {
  13231. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13232. }
  13233. }
  13234. json_object_put(UpdateFirmware);
  13235. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13236. memset(path, 0, ARRAY_SIZE(path));
  13237. // Wait retrieveData
  13238. if(strlen(retrieveDatestr) > 10)
  13239. {
  13240. do
  13241. {
  13242. sleep(1);
  13243. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13244. }
  13245. // Ready to download
  13246. system("rm -f /mnt/*");
  13247. if(strncmp(locationstr,"http", 4) == 0)
  13248. {
  13249. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13250. sprintf(ftppath,"/%s", path);
  13251. DEBUG_INFO("locationstr: %s\n", locationstr);
  13252. DEBUG_INFO("protocol: %s\n",protocol);
  13253. DEBUG_INFO("host: %s\n",host);
  13254. DEBUG_INFO("path: %s\n",path);
  13255. DEBUG_INFO("ftppath: %s\n",ftppath);
  13256. int ftppathlen=strlen(ftppath);
  13257. int i=1;
  13258. char filenametemp[50];
  13259. while(i < ftppathlen)
  13260. {
  13261. int len=ftppathlen-i;
  13262. if(ftppath[len]== 47) // '/' ascll code: 47
  13263. {
  13264. DEBUG_INFO("compare '/' all right\n");
  13265. break;
  13266. }
  13267. i=i+1;
  13268. }
  13269. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13270. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13271. filenametemp[i+1] = 0;
  13272. do
  13273. {
  13274. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13275. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13276. sleep(1);
  13277. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13278. if(!isSuccess)
  13279. {
  13280. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13281. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13282. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13283. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13284. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13285. }
  13286. else
  13287. {
  13288. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13289. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13290. }
  13291. retriesInt--;
  13292. }while((isSuccess == 0)&&(retriesInt >= 0));
  13293. }
  13294. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13295. {
  13296. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13297. memset(temp, 0, ARRAY_SIZE(temp));
  13298. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13299. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13300. int ftppathlen=strlen(ftpbuf);
  13301. int i=1;
  13302. char filenametemp[50];
  13303. while(i < ftppathlen)
  13304. {
  13305. int len=ftppathlen-i;
  13306. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13307. {
  13308. DEBUG_INFO(" compare '/' all right\n");
  13309. break;
  13310. }
  13311. i=i+1;
  13312. }
  13313. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13314. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13315. filenametemp[i+1] = 0;
  13316. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13317. pch=strchr(temp,'@');
  13318. if(pch==NULL)
  13319. {
  13320. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13321. protocol, host, &port, path);
  13322. strcpy(user,"anonymous");
  13323. strcpy(password,"");
  13324. }
  13325. else
  13326. {
  13327. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13328. protocol, user, password, host, &port, path);
  13329. }
  13330. sscanf(host,"%[^/]%s",host1, path1);
  13331. sprintf(ftppath,"%s", path1);
  13332. //DEBUG_INFO("protocol =%s\n",protocol);
  13333. //DEBUG_INFO("user =%s\n",user);
  13334. //DEBUG_INFO("password =%s\n",password);
  13335. //DEBUG_INFO("host1 =%s\n",host1);
  13336. //DEBUG_INFO("port =%d\n",port);
  13337. //DEBUG_INFO("path1 =%s\n",path1);
  13338. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13339. //ftpFile(host, user, password, port, ftppath, fname);
  13340. //download firmware pthred
  13341. if(port == 0)
  13342. {
  13343. port = 21;
  13344. }
  13345. do
  13346. {
  13347. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13348. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13349. sleep(1);
  13350. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13351. if(!isSuccess)
  13352. {
  13353. //BulldogUtil.sleepMs(interval*1000);
  13354. DEBUG_INFO("Update firmware request and download file fail.\n");
  13355. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13356. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13357. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13358. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13359. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13360. }
  13361. else
  13362. {
  13363. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13364. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13365. }
  13366. retriesInt--;
  13367. }while((!isSuccess)&&(retriesInt >= 0));
  13368. }
  13369. else
  13370. {
  13371. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13372. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13373. sleep(1);
  13374. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13375. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13376. }
  13377. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13378. interLock.isUpdateFirmwareGoing = 0;
  13379. pthread_exit(NULL);
  13380. }
  13381. int handleCertificateSignedRequest(char *uuid, char *payload)
  13382. {
  13383. mtrace();
  13384. int result = PASS;
  13385. json_object *CertificateSigned;
  13386. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13387. CertificateSigned = json_tokener_parse(payload);
  13388. if(!is_error(CertificateSigned))
  13389. {
  13390. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13391. }
  13392. json_object_put(CertificateSigned);
  13393. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  13394. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  13395. fclose(fp);
  13396. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13397. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  13398. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  13399. sendCertificateSignedConfirmation(uuid);
  13400. return result;
  13401. }
  13402. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13403. {
  13404. mtrace();
  13405. int result = PASS;
  13406. json_object *DeleteCertificate;
  13407. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13408. DeleteCertificate = json_tokener_parse(payload);
  13409. if(!is_error(DeleteCertificate))
  13410. {
  13411. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13412. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13413. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13414. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13415. }
  13416. json_object_put(DeleteCertificate);
  13417. /*
  13418. * TODO: Delete certificateSigned process
  13419. */
  13420. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  13421. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  13422. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  13423. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  13424. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  13425. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  13426. sendDeleteCertificateConfirmation(uuid);
  13427. return result;
  13428. }
  13429. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13430. {
  13431. mtrace();
  13432. int result = PASS;
  13433. json_object *ExtendedTriggerMessage;
  13434. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13435. ExtendedTriggerMessage = json_tokener_parse(payload);
  13436. if(!is_error(ExtendedTriggerMessage))
  13437. {
  13438. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13439. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13440. {
  13441. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13442. }
  13443. else
  13444. {
  13445. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  13446. }
  13447. }
  13448. json_object_put(ExtendedTriggerMessage);
  13449. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  13450. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  13451. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13452. {
  13453. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13454. }
  13455. else
  13456. {
  13457. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13458. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13459. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13460. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13461. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13462. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13463. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13464. {
  13465. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13466. }
  13467. else
  13468. {
  13469. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13470. }
  13471. }
  13472. sendExtendedTriggerMessageConfirmation(uuid);
  13473. //==========================
  13474. // Trigger message
  13475. //==========================
  13476. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13477. {
  13478. //sendBootNotificationRequest();
  13479. server_sign = FALSE;
  13480. }
  13481. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13482. {
  13483. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  13484. }
  13485. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13486. {
  13487. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13488. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13489. {
  13490. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13491. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13492. }
  13493. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13494. }
  13495. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13496. {
  13497. refreshStartTimer(&clientTime.Heartbeat);
  13498. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13499. }
  13500. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13501. {
  13502. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13503. {
  13504. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13505. }
  13506. else
  13507. {
  13508. for(int idx=0;idx< gunTotalNumber;idx++)
  13509. {
  13510. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13511. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13512. }
  13513. }
  13514. }
  13515. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13516. {
  13517. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  13518. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  13519. {
  13520. 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\" &");
  13521. }
  13522. }
  13523. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13524. {
  13525. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13526. {
  13527. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13528. }
  13529. else
  13530. {
  13531. for(int idx=0;idx< gunTotalNumber;idx++)
  13532. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13533. }
  13534. }
  13535. return result;
  13536. }
  13537. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13538. {
  13539. mtrace();
  13540. int result = PASS;
  13541. json_object *GetInstalledCertificateIds;
  13542. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13543. GetInstalledCertificateIds = json_tokener_parse(payload);
  13544. if(!is_error(GetInstalledCertificateIds))
  13545. {
  13546. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13547. }
  13548. json_object_put(GetInstalledCertificateIds);
  13549. /*
  13550. * TODO: Return installed certificate process
  13551. */
  13552. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13553. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  13554. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13555. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13556. sendGetInstalledCertificateIdsConfirmation(uuid);
  13557. return result;
  13558. }
  13559. int handleGetLogRequest(char *uuid, char *payload)
  13560. {
  13561. mtrace();
  13562. int result = PASS;
  13563. json_object *GetLog;
  13564. DEBUG_INFO("handleGetLogRequest...\n");
  13565. GetLog = json_tokener_parse(payload);
  13566. if(!is_error(GetLog))
  13567. {
  13568. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13569. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13570. if(json_object_object_get(GetLog, "retries") != NULL)
  13571. {
  13572. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13573. }
  13574. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13575. {
  13576. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13577. }
  13578. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13579. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13580. {
  13581. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13582. }
  13583. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13584. {
  13585. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13586. }
  13587. }
  13588. json_object_put(GetLog);
  13589. /*
  13590. * TODO: Upload log process
  13591. */
  13592. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  13593. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  13594. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  13595. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  13596. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  13597. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  13598. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  13599. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  13600. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  13601. sendGetLogConfirmation(uuid);
  13602. return result;
  13603. }
  13604. int handleInstallCertificateRequest(char *uuid, char *payload)
  13605. {
  13606. mtrace();
  13607. int result = PASS;
  13608. json_object *InstallCertificate;
  13609. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13610. InstallCertificate = json_tokener_parse(payload);
  13611. if(!is_error(InstallCertificate))
  13612. {
  13613. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13614. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13615. /*
  13616. * TODO: Install certificate process
  13617. */
  13618. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  13619. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  13620. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  13621. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  13622. sendInstallCertificateConfirmation(uuid);
  13623. }
  13624. json_object_put(InstallCertificate);
  13625. return result;
  13626. }
  13627. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13628. {
  13629. mtrace();
  13630. int result = PASS;
  13631. json_object *SignedUpdateFirmware;
  13632. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13633. SignedUpdateFirmware = json_tokener_parse(payload);
  13634. if(!is_error(SignedUpdateFirmware))
  13635. {
  13636. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13637. {
  13638. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13639. }
  13640. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13641. {
  13642. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13643. }
  13644. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13645. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13646. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13647. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13648. {
  13649. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13650. }
  13651. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13652. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13653. }
  13654. json_object_put(SignedUpdateFirmware);
  13655. /*
  13656. * TODO: Upgrade firmware process
  13657. */
  13658. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13659. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  13660. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  13661. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  13662. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  13663. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  13664. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  13665. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  13666. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  13667. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  13668. sendInstallCertificateConfirmation(uuid);
  13669. return result;
  13670. }
  13671. int handleUnknownRequest(char *uuid, char *payload)
  13672. {
  13673. mtrace();
  13674. int result = PASS;
  13675. DEBUG_INFO("handleUnknownRequest...\n");
  13676. sendUnknownConfirmation(uuid);
  13677. result = PASS;
  13678. return result;
  13679. }
  13680. //==========================================
  13681. // Handle server response routine
  13682. //==========================================
  13683. void handleAuthorizeResponse(char *payload, int gun_index)
  13684. {
  13685. mtrace();
  13686. char expiryDatestr[30]={0};
  13687. char parentIdTagstr[20]={0};
  13688. char statusstr[20]={0};
  13689. int expiryDateISNULL=FALSE;
  13690. int parentIdTagISNULL=FALSE;
  13691. DEBUG_INFO("handleAuthorizeResponse...\n");
  13692. json_object *Authorize;
  13693. Authorize = json_tokener_parse(payload);
  13694. if(!is_error(Authorize))
  13695. {
  13696. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13697. {
  13698. // Required data
  13699. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13700. // Optional data
  13701. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13702. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13703. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13704. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13705. }
  13706. }
  13707. json_object_put(Authorize);
  13708. if(expiryDateISNULL == FALSE)
  13709. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13710. if(parentIdTagISNULL == FALSE)
  13711. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13712. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  13713. //Update idTag information to authorization cache if supproted
  13714. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13715. {
  13716. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13717. }
  13718. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  13719. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13720. authorizeRetryTimes = 0;
  13721. }
  13722. void handleBootNotificationResponse(char *payload, int gun_index)
  13723. {
  13724. mtrace();
  13725. char statusStr[12]={0};
  13726. char currentTimeStr[30]={0};
  13727. int intervalInt = 0;
  13728. DEBUG_INFO("handleBootNotificationResponse...\n");
  13729. json_object *BootNotification;
  13730. BootNotification = json_tokener_parse(payload);
  13731. if(!is_error(BootNotification))
  13732. {
  13733. // Required data
  13734. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13735. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13736. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13737. }
  13738. json_object_put(BootNotification);
  13739. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13740. BootNotificationInterval = intervalInt;
  13741. //write back to ShmOCPP16Data->BootNotification
  13742. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  13743. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13744. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  13745. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13746. {
  13747. BootNotificationInterval = 0;
  13748. if((intervalInt == 0) || (intervalInt >= 10))
  13749. {
  13750. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13751. HeartBeatWaitTime = intervalInt;
  13752. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13753. }
  13754. server_sign = TRUE;
  13755. server_pending =FALSE;
  13756. }
  13757. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13758. {
  13759. server_pending = TRUE;
  13760. }
  13761. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  13762. srand(time(NULL));
  13763. refreshStartTimer(&clientTime.Heartbeat);
  13764. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13765. SetOcppConnStatus(TRUE);
  13766. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  13767. }
  13768. void handleDataTransferResponse(char *payload, int gun_index)
  13769. {
  13770. json_object *DataTransfer = json_tokener_parse(payload);
  13771. if(!is_error(DataTransfer))
  13772. {
  13773. // Required data
  13774. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13775. // Optional data
  13776. if(json_object_object_get(DataTransfer, "data") != NULL)
  13777. {
  13778. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13779. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13780. if(!is_error(Data))
  13781. {
  13782. if(json_object_object_get(Data, "msgId") != NULL)
  13783. {
  13784. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13785. {
  13786. 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")));
  13787. }
  13788. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_ReaderStatus") != NULL)
  13789. {
  13790. if(json_object_object_get(Data, "ConnectorId") != NULL)
  13791. ShmOCPP16Data->TcciCustomData.ReaderStatus[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].ReportReaderStatusReq = 0;
  13792. }
  13793. }
  13794. }
  13795. json_object_put(Data);
  13796. }
  13797. }
  13798. json_object_put(DataTransfer);
  13799. }
  13800. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13801. {
  13802. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13803. //struct json_object *obj;
  13804. // obj = json_tokener_parse(payload);
  13805. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13806. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13807. //No fields are defined.
  13808. }
  13809. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13810. {
  13811. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13812. //struct json_object *obj;
  13813. // obj = json_tokener_parse(payload);
  13814. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13815. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13816. //No fields are defined.
  13817. }
  13818. void handleHeartbeatResponse(char *payload, int gun_index)
  13819. {
  13820. mtrace();
  13821. DEBUG_INFO("handleHeartbeatResponse...\n");
  13822. json_object *Heartbeat;
  13823. Heartbeat = json_tokener_parse(payload);
  13824. if(!is_error(Heartbeat))
  13825. {
  13826. // Required data
  13827. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13828. }
  13829. json_object_put(Heartbeat);
  13830. if(FirstHeartBeat == 0)
  13831. {
  13832. FirstHeartBeat = 1;
  13833. DEBUG_INFO("FirstHeartBeat \n");
  13834. }
  13835. HeartBeatWithNOResponse = 0;
  13836. refreshStartTimer(&clientTime.Heartbeat);
  13837. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  13838. }
  13839. void handleMeterValuesResponse(char *payload, int gun_index)
  13840. {
  13841. mtrace();
  13842. DEBUG_INFO("handleMeterValuesResponse...\n");
  13843. isQueueSendable = 1;
  13844. }
  13845. void handleStartTransactionResponse(char *payload, int gun_index)
  13846. {
  13847. mtrace();
  13848. //int transactionIdInt = 0;
  13849. FILE *outfile;
  13850. char data[100]={0};
  13851. DEBUG_INFO("handleStartTransactionResponse...\n");
  13852. json_object *StartTransaction;
  13853. StartTransaction = json_tokener_parse(payload);
  13854. if(!is_error(StartTransaction))
  13855. {
  13856. // Required data
  13857. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13858. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13859. // Optional data
  13860. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13861. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13862. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13863. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13864. }
  13865. json_object_put(StartTransaction);
  13866. isQueueSendable = 1;
  13867. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13868. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13869. //-----------Start : write to the Queue TransactionId file -----------------//
  13870. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  13871. {}
  13872. else
  13873. {
  13874. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  13875. if(log == NULL)
  13876. {
  13877. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13878. return ;
  13879. }
  13880. else
  13881. {
  13882. fclose(log);
  13883. }
  13884. }
  13885. // open file for writing
  13886. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13887. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  13888. {
  13889. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  13890. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13891. fputs(data, outfile);
  13892. fclose (outfile);
  13893. }
  13894. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13895. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13896. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13897. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  13898. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13899. }
  13900. void handleStatusNotificationResponse(char *payload, int gun_index)
  13901. {
  13902. mtrace();
  13903. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13904. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13905. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13906. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13907. }
  13908. void handleStopTransactionnResponse(char *payload, int gun_index)
  13909. {
  13910. mtrace();
  13911. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13912. json_object *StopTransaction;
  13913. StopTransaction = json_tokener_parse(payload);
  13914. if(!is_error(StopTransaction))
  13915. {
  13916. // Optional data
  13917. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13918. {
  13919. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13920. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13921. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13922. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13923. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13924. }
  13925. }
  13926. json_object_put(StopTransaction);
  13927. isQueueSendable = 1;
  13928. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13929. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13930. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13931. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13932. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13933. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13934. }
  13935. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13936. {
  13937. mtrace();
  13938. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13939. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  13940. }
  13941. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13942. {
  13943. mtrace();
  13944. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13945. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  13946. }
  13947. void handleSignCertificateResponse(char *payload, int gun_index)
  13948. {
  13949. mtrace();
  13950. DEBUG_INFO("handleSignCertificateResponse...\n");
  13951. json_object *SignCertificate;
  13952. SignCertificate = json_tokener_parse(payload);
  13953. if(!is_error(SignCertificate))
  13954. {
  13955. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13956. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  13957. }
  13958. json_object_put(SignCertificate);
  13959. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  13960. }
  13961. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13962. {
  13963. mtrace();
  13964. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13965. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13966. }
  13967. //==========================================
  13968. // Handle Error routine
  13969. //==========================================
  13970. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13971. {
  13972. mtrace();
  13973. #ifdef SystemLogMessage
  13974. DEBUG_INFO("errorCode: %s\n", errorCode);
  13975. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13976. DEBUG_INFO("errorDetails: %s\n", payload);
  13977. #endif
  13978. }
  13979. //===============================================
  13980. // Common routine
  13981. //===============================================
  13982. int initialConfigurationTable(void)
  13983. {
  13984. //clock_t start_t, end_t, total_t;
  13985. FILE *fp;
  13986. FILE *outfile;
  13987. char str[512]={0};
  13988. char sstr[256]={0};
  13989. int c = 0;
  13990. char *loc;
  13991. int confVersion = 14;
  13992. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13993. //start_t = clock();
  13994. //printf("Starting of the program, start_t = %ld\n", start_t);
  13995. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13996. // Check configuration file size is correct
  13997. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  13998. {
  13999. struct stat st;
  14000. stat("/Storage/OCPP/OCPPConfiguration", &st);
  14001. if(st.st_size < 3100)
  14002. {
  14003. system("rm -f /Storage/OCPP/OCPPConfiguration");
  14004. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  14005. }
  14006. }
  14007. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  14008. {
  14009. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14010. if(outfile == NULL)
  14011. {
  14012. DEBUG_INFO("Error opening file\n");
  14013. return FALSE;
  14014. }
  14015. /*Core Profile*/
  14016. //AllowOfflineTxForUnknownId
  14017. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14018. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14019. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  14020. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14021. //AuthorizationCacheEnabled
  14022. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14023. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14024. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14025. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14026. //AuthorizeRemoteTxRequests
  14027. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  14030. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14031. //BlinkRepeat
  14032. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14033. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14035. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14036. //ClockAlignedDataInterval
  14037. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14038. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14039. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14040. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14041. //ConnectionTimeOut
  14042. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14044. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14045. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14046. //GetConfigurationMaxKeys
  14047. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14049. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  14050. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14051. // HeartbeatInterval
  14052. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  14055. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14056. // LightIntensity
  14057. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14060. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14061. // LocalAuthorizeOffline
  14062. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  14063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14065. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14066. // LocalPreAuthorize
  14067. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  14068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14070. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14071. // MaxEnergyOnInvalidId
  14072. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14075. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14076. // MeterValuesAlignedData
  14077. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14079. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14080. 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" );
  14081. else
  14082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14083. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14084. // MeterValuesAlignedDataMaxLength
  14085. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14086. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14087. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  14089. else
  14090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  14091. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14092. // MeterValuesSampledData
  14093. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14095. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14096. 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" );
  14097. else
  14098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14099. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14100. // MeterValuesSampledDataMaxLength
  14101. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14103. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  14105. else
  14106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  14107. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14108. // MeterValueSampleInterval
  14109. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  14112. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14113. // MinimumStatusDuration
  14114. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14116. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  14117. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  14118. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14119. // NumberOfConnectors
  14120. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14122. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14123. {
  14124. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14125. }
  14126. else
  14127. {
  14128. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14129. }
  14130. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14131. // ResetRetries
  14132. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14135. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14136. // ConnectorPhaseRotation
  14137. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14138. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14140. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14141. // ConnectorPhaseRotationMaxLength
  14142. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14143. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14144. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14145. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14146. // StopTransactionOnEVSideDisconnect
  14147. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14149. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14150. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14151. // StopTransactionOnInvalidId
  14152. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  14153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14155. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14156. // StopTxnAlignedData
  14157. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  14158. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14159. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  14160. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14161. // StopTxnAlignedDataMaxLength
  14162. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14164. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14165. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14166. // StopTxnSampledData
  14167. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14169. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14170. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  14171. else
  14172. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  14173. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14174. // StopTxnSampledDataMaxLength
  14175. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14177. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14178. {
  14179. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  14180. }
  14181. else
  14182. {
  14183. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  14184. }
  14185. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14186. // SupportedFeatureProfiles
  14187. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14188. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14190. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14191. // SupportedFeatureProfilesMaxLength
  14192. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14193. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14194. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14195. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14196. // TransactionMessageAttempts
  14197. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14198. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14200. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14202. // TransactionMessageRetryInterval
  14203. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14205. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14206. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14207. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14208. // UnlockConnectorOnEVSideDisconnect
  14209. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14211. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14212. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14213. // WebSocketPingInterval
  14214. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14215. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14216. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14217. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14218. // QueueOffLineMeterValues
  14219. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  14220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14221. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  14222. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14223. // AuthorizationKey
  14224. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14225. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14226. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14227. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14228. // SecurityProfile
  14229. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14230. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14231. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14232. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14233. // DefaultPrice
  14234. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14236. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14237. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14238. // CustomDisplayCostAndPrice
  14239. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14241. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14242. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14243. // CustomIdleFeeAfterStop
  14244. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14246. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14247. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14248. // TimeOffset
  14249. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14250. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  14252. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14253. // NextTimeOffsetTransitionDateTime
  14254. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14256. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  14257. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14258. // TimeOffsetNextTransition
  14259. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14260. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  14262. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14263. // SystemUptimeSec
  14264. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14267. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14268. // FreeVend
  14269. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14271. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14272. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14273. // FreeVendIdtag
  14274. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14277. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14278. // OcppServer
  14279. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14281. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14282. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14283. // MaintainServer
  14284. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14286. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  14287. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14288. // StatusNotificationPeriodically
  14289. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  14290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14293. // StatusNotificationInterval
  14294. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14297. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14298. // PreAuthAmount
  14299. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  14300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  14301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "888" );
  14302. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  14303. // Configuration Version
  14304. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  14305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14306. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  14307. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14308. //* Local Auth List Management Profile*/
  14309. #if 0
  14310. //For OCTT Test Case
  14311. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14312. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  14313. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14314. #endif
  14315. #if 1
  14316. //LocalAuthListEnabled
  14317. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14318. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14319. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14320. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14321. #endif
  14322. //LocalAuthListMaxLength
  14323. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  14326. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14327. //SendLocalListMaxLength
  14328. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14331. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14332. //ReserveConnectorZeroSupported
  14333. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14336. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14337. //* Smart Charging Profile */
  14338. //ChargeProfileMaxStackLevel
  14339. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14340. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14341. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14342. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14343. // ChargingScheduleAllowedChargingRateUnit
  14344. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14345. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14346. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  14347. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14348. // ChargingScheduleMaxPeriods
  14349. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14351. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14352. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14353. // ConnectorSwitch3to1PhaseSupported
  14354. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  14357. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14358. // MaxChargingProfilesInstalled
  14359. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14361. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14362. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14363. fclose(outfile);
  14364. }
  14365. else
  14366. {
  14367. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  14368. char keystr[60]={0};
  14369. char readonlystr[10]={0};
  14370. char valuestr[256]={0};
  14371. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  14372. if(fp == NULL) {
  14373. DEBUG_INFO("Error opening file");
  14374. return FALSE;
  14375. }
  14376. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  14377. {
  14378. //DEBUG_INFO("Get Configuration \n");
  14379. if(strlen(str) > 0)
  14380. {
  14381. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14382. //*************************key*********************************/
  14383. if(strstr(str, "key") != NULL)
  14384. {
  14385. loc = strstr(str, "key");
  14386. c = 0;
  14387. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14388. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14389. {
  14390. sstr[c] = loc[strlen("key")+3+c];
  14391. c++;
  14392. }
  14393. sstr[c] = '\0';
  14394. strcpy(keystr,sstr);
  14395. }
  14396. //*************************readonly*********************************/
  14397. if(strstr(str, "readonly") != NULL)
  14398. {
  14399. loc = strstr(str, "readonly");
  14400. c = 0;
  14401. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14402. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  14403. {
  14404. sstr[c] = loc[strlen("readonly")+2+c];
  14405. c++;
  14406. }
  14407. sstr[c] = '\0';
  14408. strcpy(readonlystr,sstr);
  14409. }
  14410. //*************************value*********************************/
  14411. if(strstr(str, "value") != NULL)
  14412. {
  14413. loc = strstr(str, "value");
  14414. c = 0;
  14415. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14416. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14417. {
  14418. sstr[c] = loc[strlen("value")+3+c];
  14419. c++;
  14420. }
  14421. sstr[c] = '\0';
  14422. strcpy(valuestr,sstr);
  14423. }
  14424. // DEBUG_INFO("keystr=%s\n",keystr);
  14425. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  14426. // DEBUG_INFO("valuestr=%s\n",valuestr);
  14427. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  14428. {
  14429. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14430. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14431. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14432. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14433. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14434. }
  14435. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14436. {
  14437. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14438. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14439. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14440. }
  14441. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14442. {
  14443. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14444. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14445. }
  14446. if(strcmp(keystr, "BlinkRepeat") == 0)
  14447. {
  14448. //Charger.BlinkRepeat = Integer.parseInt(value);
  14449. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14450. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14451. }
  14452. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14453. {
  14454. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14455. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14456. }
  14457. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14458. {
  14459. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14460. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14461. }
  14462. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14463. {
  14464. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14465. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14466. }
  14467. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14468. {
  14469. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14470. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14471. HeartBeatWaitTime = atoi(valuestr);
  14472. }
  14473. if(strcmp(keystr, "LightIntensity") == 0)
  14474. {
  14475. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14476. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14477. }
  14478. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14479. {
  14480. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14481. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14482. }
  14483. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14484. {
  14485. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14486. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14487. }
  14488. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14489. {
  14490. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14491. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14492. }
  14493. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14494. {
  14495. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14496. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14497. }
  14498. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14499. {
  14500. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14501. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14502. }
  14503. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14504. {
  14505. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14506. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14507. }
  14508. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14509. {
  14510. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14511. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14512. }
  14513. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14514. {
  14515. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14516. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14517. }
  14518. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14519. {
  14520. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14521. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14522. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14523. }
  14524. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14525. {
  14526. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14527. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14528. }
  14529. if(strcmp(keystr, "ResetRetries") == 0)
  14530. {
  14531. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14532. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14533. }
  14534. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14535. {
  14536. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14537. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14538. }
  14539. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14540. {
  14541. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14542. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14543. }
  14544. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14545. {
  14546. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14547. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14548. }
  14549. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14550. {
  14551. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14552. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14553. }
  14554. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14555. {
  14556. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14557. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14558. }
  14559. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14560. {
  14561. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14562. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14563. }
  14564. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14565. {
  14566. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14567. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14568. }
  14569. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14570. {
  14571. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14572. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14573. }
  14574. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14575. {
  14576. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14577. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14578. }
  14579. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14580. {
  14581. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14582. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14583. }
  14584. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14585. {
  14586. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14587. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14588. TransactionMessageAttemptsValue = atoi(valuestr);
  14589. }
  14590. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14591. {
  14592. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14593. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14594. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14595. }
  14596. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14597. {
  14598. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14599. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14600. }
  14601. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14602. {
  14603. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14604. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14605. }
  14606. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14607. {
  14608. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14609. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14610. }
  14611. if(strcmp(keystr, "AuthorizationKey") == 0)
  14612. {
  14613. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14614. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14615. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  14616. }
  14617. if(strcmp(keystr, "SecurityProfile") == 0)
  14618. {
  14619. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14620. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  14621. }
  14622. if(strcmp(keystr, "DefaultPrice") == 0)
  14623. {
  14624. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14625. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14626. }
  14627. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14628. {
  14629. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14630. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14631. }
  14632. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14633. {
  14634. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14635. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14636. }
  14637. if(strcmp(keystr, "TimeOffset") == 0)
  14638. {
  14639. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14640. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  14641. }
  14642. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  14643. {
  14644. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14645. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  14646. }
  14647. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  14648. {
  14649. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14650. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  14651. }
  14652. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14653. {
  14654. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14655. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  14656. }
  14657. if(strcmp(keystr, "FreeVend") == 0)
  14658. {
  14659. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14660. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14661. }
  14662. if(strcmp(keystr, "FreeVendIdtag") == 0)
  14663. {
  14664. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14665. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  14666. }
  14667. if(strcmp(keystr, "OcppServer") == 0)
  14668. {
  14669. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14670. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14671. }
  14672. if(strcmp(keystr, "MaintainServer") == 0)
  14673. {
  14674. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14675. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14676. }
  14677. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14678. {
  14679. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14680. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14681. }
  14682. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14683. {
  14684. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14685. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14686. }
  14687. if(strcmp(keystr, "PreAuthAmount") == 0)
  14688. {
  14689. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14690. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(valuestr));
  14691. }
  14692. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14693. {
  14694. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14695. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14696. }
  14697. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14698. {
  14699. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14700. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14701. }
  14702. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14703. {
  14704. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14705. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14706. }
  14707. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14708. {
  14709. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14710. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14711. }
  14712. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14713. {
  14714. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14715. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14716. }
  14717. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14718. {
  14719. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14720. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14721. }
  14722. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14723. {
  14724. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14725. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14726. }
  14727. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14728. {
  14729. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14730. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14731. }
  14732. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14733. {
  14734. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14735. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14736. }
  14737. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14738. {
  14739. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14740. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14741. }
  14742. }
  14743. }
  14744. fclose(fp);
  14745. }
  14746. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14747. {
  14748. return PASS;
  14749. }
  14750. else
  14751. {
  14752. return FAIL;
  14753. }
  14754. }
  14755. void StoreConfigurationTable(void)
  14756. {
  14757. FILE *outfile;
  14758. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  14759. if(outfile == NULL)
  14760. {
  14761. DEBUG_INFO("Error opening file");
  14762. return ;
  14763. }
  14764. /*Core Profile*/
  14765. //AllowOfflineTxForUnknownId
  14766. /*
  14767. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14768. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14769. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14771. */
  14772. //DEBUG_INFO("data=%s\n",data);
  14773. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14774. //AuthorizationCacheEnabled
  14775. /*
  14776. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14777. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14779. */
  14780. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14781. //AuthorizeRemoteTxRequests
  14782. /*
  14783. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14784. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14786. */
  14787. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14788. //BlinkRepeat
  14789. /*
  14790. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14791. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14793. */
  14794. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14795. //ClockAlignedDataInterval
  14796. /*
  14797. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14798. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14800. */
  14801. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14802. //ConnectionTimeOut
  14803. /*
  14804. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14805. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14806. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14807. */
  14808. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14809. //GetConfigurationMaxKeys
  14810. /*
  14811. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14814. */
  14815. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14816. // HeartbeatInterval
  14817. /*
  14818. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14819. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14820. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14821. */
  14822. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14823. // LightIntensity
  14824. /*
  14825. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14826. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14827. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14828. */
  14829. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14830. // LocalAuthorizeOffline
  14831. /*
  14832. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14834. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14835. */
  14836. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14837. // LocalPreAuthorize
  14838. /*
  14839. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14840. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14842. */
  14843. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14844. // MaxEnergyOnInvalidId
  14845. /*
  14846. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14847. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14849. */
  14850. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14851. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14852. // MeterValuesAlignedData
  14853. /*
  14854. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14855. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14857. */
  14858. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14859. // MeterValuesAlignedDataMaxLength
  14860. /*
  14861. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14864. */
  14865. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14866. // MeterValuesSampledData
  14867. /*
  14868. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14869. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14870. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14871. */
  14872. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14873. // MeterValuesSampledDataMaxLength
  14874. /*
  14875. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14876. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14878. */
  14879. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14880. // MeterValueSampleInterval
  14881. /*
  14882. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14884. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14885. */
  14886. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14887. // MinimumStatusDuration
  14888. /*
  14889. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14890. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14891. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14892. */
  14893. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14894. // NumberOfConnectors
  14895. /*
  14896. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14897. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14898. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14899. {
  14900. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14901. }
  14902. else
  14903. {
  14904. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14905. }
  14906. */
  14907. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14908. // ResetRetries
  14909. /*
  14910. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14911. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14912. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14913. */
  14914. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14915. // ConnectorPhaseRotation
  14916. /*
  14917. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14918. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14919. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14920. */
  14921. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14922. // ConnectorPhaseRotationMaxLength
  14923. /*
  14924. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14925. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14926. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14927. */
  14928. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14929. // StopTransactionOnEVSideDisconnect
  14930. /*
  14931. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14932. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14933. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14934. */
  14935. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14936. // StopTransactionOnInvalidId
  14937. /*
  14938. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14939. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14940. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14941. */
  14942. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14943. // StopTxnAlignedData
  14944. /*
  14945. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14946. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14947. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14948. */
  14949. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14950. // StopTxnAlignedDataMaxLength
  14951. /*
  14952. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14953. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14954. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14955. */
  14956. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14957. // StopTxnSampledData
  14958. /*
  14959. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14960. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14961. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14962. */
  14963. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14964. // StopTxnSampledDataMaxLength
  14965. /*
  14966. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14967. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14968. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14969. */
  14970. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14971. // SupportedFeatureProfiles
  14972. /*
  14973. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14974. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14975. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14976. */
  14977. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14978. // SupportedFeatureProfilesMaxLength
  14979. /*
  14980. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14981. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14982. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14983. */
  14984. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14985. // TransactionMessageAttempts
  14986. /*
  14987. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14988. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14989. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14990. */
  14991. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14992. // TransactionMessageRetryInterval
  14993. /*
  14994. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14995. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14996. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14997. */
  14998. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14999. // UnlockConnectorOnEVSideDisconnect
  15000. /*
  15001. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  15002. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  15003. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  15004. */
  15005. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15006. // WebSocketPingInterval
  15007. /*
  15008. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15009. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15010. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15011. */
  15012. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15013. // QueueOffLineMeterValues
  15014. /*
  15015. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  15016. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15017. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  15018. */
  15019. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15020. // AuthorizationKey
  15021. /*
  15022. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15023. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15024. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  15025. */
  15026. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15027. // SecurityProfile
  15028. /*
  15029. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15030. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15031. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  15032. */
  15033. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15034. // DefaultPrice
  15035. /*
  15036. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15037. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15038. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15039. */
  15040. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15041. // CustomDisplayCostAndPrice
  15042. /*
  15043. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15044. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15045. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15046. */
  15047. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15048. // CustomIdleFeeAfterStop
  15049. /*
  15050. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15053. */
  15054. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15055. // TimeOffset
  15056. /*
  15057. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  15058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  15059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  15060. */
  15061. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  15062. // NextTimeOffsetTransitionDateTime
  15063. /*
  15064. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  15065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  15066. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  15067. */
  15068. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  15069. // TimeOffsetNextTransition
  15070. /*
  15071. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  15072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  15073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  15074. */
  15075. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  15076. // SystemUptimeSec
  15077. /*
  15078. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15080. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15081. */
  15082. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15083. // FreeVend
  15084. /*
  15085. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15086. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  15088. */
  15089. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15090. // FreeVendIdtag
  15091. /*
  15092. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15095. */
  15096. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15097. // OcppServer
  15098. /*
  15099. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  15102. */
  15103. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15104. // MaintainServer
  15105. /*
  15106. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  15109. */
  15110. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15111. // StatusNotificationPeriodically
  15112. /*
  15113. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  15114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15116. */
  15117. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15118. // StatusNotificationInterval
  15119. /*
  15120. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15123. */
  15124. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15125. // PreAuthAmount
  15126. /*
  15127. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  15128. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  15129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "120" );
  15130. */
  15131. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  15132. // ConfigurationVersion
  15133. /*
  15134. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  15135. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  15137. */
  15138. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15139. //* Local Auth List Management Profile*/
  15140. //LocalAuthListEnabled
  15141. /*
  15142. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15143. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15144. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15145. */
  15146. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15147. //LocalAuthListMaxLength
  15148. /*
  15149. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15150. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15151. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  15152. */
  15153. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15154. //SendLocalListMaxLength
  15155. /*
  15156. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15158. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  15159. */
  15160. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15161. //ReserveConnectorZeroSupported
  15162. /*
  15163. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15164. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15165. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15166. */
  15167. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15168. //* Smart Charging Profile */
  15169. //ChargeProfileMaxStackLevel
  15170. /*
  15171. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  15172. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  15173. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  15174. */
  15175. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15176. // ChargingScheduleAllowedChargingRateUnit
  15177. /*
  15178. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  15179. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  15180. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  15181. */
  15182. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15183. // ChargingScheduleMaxPeriods
  15184. /*
  15185. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  15186. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  15187. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  15188. */
  15189. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15190. // ConnectorSwitch3to1PhaseSupported
  15191. /*
  15192. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  15193. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  15194. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  15195. */
  15196. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15197. // MaxChargingProfilesInstalled
  15198. /*
  15199. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  15200. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  15201. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  15202. */
  15203. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15204. fclose(outfile);
  15205. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15206. }
  15207. void getKeyValue(char *keyReq)
  15208. {
  15209. int isEmpty = FALSE;
  15210. int isKnowKey = FALSE;
  15211. DEBUG_INFO("keyReq = %s\n", keyReq);
  15212. if((keyReq == NULL) || (strlen(keyReq) == 0))
  15213. isEmpty = TRUE;
  15214. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  15215. {
  15216. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  15217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  15218. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15219. {
  15220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  15221. }
  15222. else
  15223. {
  15224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  15225. }
  15226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  15227. isKnowKey = TRUE;
  15228. }
  15229. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  15230. {
  15231. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  15232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  15233. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15234. {
  15235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  15236. }
  15237. else
  15238. {
  15239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  15240. }
  15241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  15242. isKnowKey = TRUE;
  15243. }
  15244. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  15245. {
  15246. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  15247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  15248. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15249. {
  15250. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  15251. }
  15252. else
  15253. {
  15254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  15255. }
  15256. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  15257. isKnowKey = TRUE;
  15258. }
  15259. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  15260. {
  15261. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  15262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  15263. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15264. {
  15265. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  15266. }
  15267. else
  15268. {
  15269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  15270. }
  15271. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  15272. isKnowKey = TRUE;
  15273. }
  15274. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  15275. {
  15276. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  15277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  15278. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15279. {
  15280. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  15281. }
  15282. else
  15283. {
  15284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  15285. }
  15286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  15287. isKnowKey = TRUE;
  15288. }
  15289. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  15290. {
  15291. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  15292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  15293. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15294. {
  15295. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  15296. }
  15297. else
  15298. {
  15299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  15300. }
  15301. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  15302. isKnowKey = TRUE;
  15303. }
  15304. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  15305. {
  15306. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  15307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  15308. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15309. {
  15310. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  15311. }
  15312. else
  15313. {
  15314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  15315. }
  15316. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  15317. isKnowKey = TRUE;
  15318. }
  15319. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  15320. {
  15321. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  15322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  15323. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15324. {
  15325. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  15326. }
  15327. else
  15328. {
  15329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  15330. }
  15331. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  15332. isKnowKey = TRUE;
  15333. }
  15334. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  15335. {
  15336. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  15337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  15338. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15339. {
  15340. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  15341. }
  15342. else
  15343. {
  15344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  15345. }
  15346. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  15347. isKnowKey = TRUE;
  15348. }
  15349. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  15350. {
  15351. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  15352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  15353. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15354. {
  15355. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  15356. }
  15357. else
  15358. {
  15359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  15360. }
  15361. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  15362. isKnowKey = TRUE;
  15363. }
  15364. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  15365. {
  15366. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  15367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  15368. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15369. {
  15370. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  15371. }
  15372. else
  15373. {
  15374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  15375. }
  15376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  15377. isKnowKey = TRUE;
  15378. }
  15379. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  15380. {
  15381. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  15382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  15383. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15384. {
  15385. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15386. }
  15387. else
  15388. {
  15389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15390. }
  15391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  15392. isKnowKey = TRUE;
  15393. }
  15394. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  15395. {
  15396. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  15397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  15398. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15399. {
  15400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15401. }
  15402. else
  15403. {
  15404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15405. }
  15406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  15407. isKnowKey = TRUE;
  15408. }
  15409. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  15410. {
  15411. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  15412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  15413. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15414. {
  15415. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15416. }
  15417. else
  15418. {
  15419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15420. }
  15421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  15422. isKnowKey = TRUE;
  15423. }
  15424. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  15425. {
  15426. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  15427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  15428. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15429. {
  15430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  15431. }
  15432. else
  15433. {
  15434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  15435. }
  15436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  15437. isKnowKey = TRUE;
  15438. }
  15439. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  15440. {
  15441. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  15442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  15443. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15444. {
  15445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15446. }
  15447. else
  15448. {
  15449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15450. }
  15451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  15452. isKnowKey = TRUE;
  15453. }
  15454. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  15455. {
  15456. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  15457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  15458. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15459. {
  15460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  15461. }
  15462. else
  15463. {
  15464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  15465. }
  15466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  15467. isKnowKey = TRUE;
  15468. }
  15469. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  15470. {
  15471. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  15472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  15473. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15474. {
  15475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  15476. }
  15477. else
  15478. {
  15479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  15480. }
  15481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  15482. isKnowKey = TRUE;
  15483. }
  15484. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  15485. {
  15486. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  15487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  15488. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15489. {
  15490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  15491. }
  15492. else
  15493. {
  15494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15495. }
  15496. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15498. isKnowKey = TRUE;
  15499. }
  15500. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15501. {
  15502. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15504. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15505. {
  15506. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15507. }
  15508. else
  15509. {
  15510. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15511. }
  15512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15513. isKnowKey = TRUE;
  15514. }
  15515. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15516. {
  15517. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15519. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15520. {
  15521. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15522. }
  15523. else
  15524. {
  15525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15526. }
  15527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15528. isKnowKey = TRUE;
  15529. }
  15530. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15531. {
  15532. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15534. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15535. {
  15536. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15537. }
  15538. else
  15539. {
  15540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15541. }
  15542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15543. isKnowKey = TRUE;
  15544. }
  15545. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15546. {
  15547. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15549. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15550. {
  15551. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15552. }
  15553. else
  15554. {
  15555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15556. }
  15557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15558. isKnowKey = TRUE;
  15559. }
  15560. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15561. {
  15562. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15564. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15565. {
  15566. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15567. }
  15568. else
  15569. {
  15570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15571. }
  15572. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15573. isKnowKey = TRUE;
  15574. }
  15575. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15576. {
  15577. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15579. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15580. {
  15581. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15582. }
  15583. else
  15584. {
  15585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15586. }
  15587. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15588. isKnowKey = TRUE;
  15589. }
  15590. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15591. {
  15592. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15594. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15595. {
  15596. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15597. }
  15598. else
  15599. {
  15600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15601. }
  15602. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15603. isKnowKey = TRUE;
  15604. }
  15605. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15606. {
  15607. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15609. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15610. {
  15611. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15612. }
  15613. else
  15614. {
  15615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15616. }
  15617. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15618. isKnowKey = TRUE;
  15619. }
  15620. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15621. {
  15622. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15624. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15625. {
  15626. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15627. }
  15628. else
  15629. {
  15630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15631. }
  15632. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15633. isKnowKey = TRUE;
  15634. }
  15635. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15636. {
  15637. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15639. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15640. {
  15641. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15642. }
  15643. else
  15644. {
  15645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15646. }
  15647. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15648. isKnowKey = TRUE;
  15649. }
  15650. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15651. {
  15652. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15654. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15655. {
  15656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15657. }
  15658. else
  15659. {
  15660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15661. }
  15662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15663. isKnowKey = TRUE;
  15664. }
  15665. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15666. {
  15667. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15669. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15670. {
  15671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15672. }
  15673. else
  15674. {
  15675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15676. }
  15677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15678. isKnowKey = TRUE;
  15679. }
  15680. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15681. {
  15682. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15684. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15685. {
  15686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15687. }
  15688. else
  15689. {
  15690. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15691. }
  15692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15693. isKnowKey = TRUE;
  15694. }
  15695. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15696. {
  15697. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15699. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15700. {
  15701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15702. }
  15703. else
  15704. {
  15705. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15706. }
  15707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15708. isKnowKey = TRUE;
  15709. }
  15710. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15711. {
  15712. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15714. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15715. {
  15716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15717. }
  15718. else
  15719. {
  15720. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15721. }
  15722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15723. isKnowKey = TRUE;
  15724. }
  15725. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15726. {
  15727. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15729. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15730. {
  15731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15732. }
  15733. else
  15734. {
  15735. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15736. }
  15737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15738. isKnowKey = TRUE;
  15739. }
  15740. /*
  15741. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15742. {
  15743. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15745. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15746. {
  15747. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15748. }
  15749. else
  15750. {
  15751. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15752. }
  15753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15754. isKnowKey = TRUE;
  15755. }*/
  15756. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15757. {
  15758. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15760. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15761. {
  15762. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15763. }
  15764. else
  15765. {
  15766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15767. }
  15768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15769. isKnowKey = TRUE;
  15770. }
  15771. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15772. {
  15773. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15775. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15776. {
  15777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15778. }
  15779. else
  15780. {
  15781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15782. }
  15783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15784. isKnowKey = TRUE;
  15785. }
  15786. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15787. {
  15788. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15789. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15790. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15791. {
  15792. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15793. }
  15794. else
  15795. {
  15796. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15797. }
  15798. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15799. isKnowKey = TRUE;
  15800. }
  15801. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15802. {
  15803. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15804. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15805. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15806. {
  15807. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15808. }
  15809. else
  15810. {
  15811. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15812. }
  15813. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15814. isKnowKey = TRUE;
  15815. }
  15816. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  15817. {
  15818. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  15819. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  15820. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15821. {
  15822. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  15823. }
  15824. else
  15825. {
  15826. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  15827. }
  15828. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  15829. isKnowKey = TRUE;
  15830. }
  15831. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  15832. {
  15833. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  15834. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  15835. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15836. {
  15837. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  15838. }
  15839. else
  15840. {
  15841. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  15842. }
  15843. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  15844. isKnowKey = TRUE;
  15845. }
  15846. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  15847. {
  15848. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  15849. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  15850. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15851. {
  15852. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  15853. }
  15854. else
  15855. {
  15856. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  15857. }
  15858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  15859. isKnowKey = TRUE;
  15860. }
  15861. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15862. {
  15863. struct sysinfo s_info;
  15864. int error = sysinfo(&s_info);
  15865. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15867. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15868. {
  15869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15870. }
  15871. else
  15872. {
  15873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15874. }
  15875. if(error != 0)
  15876. {
  15877. DEBUG_WARN("System uptime get error: %d\n", error);
  15878. }
  15879. else
  15880. {
  15881. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15882. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15883. }
  15884. isKnowKey = TRUE;
  15885. }
  15886. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15887. {
  15888. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15889. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15890. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15891. {
  15892. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15893. }
  15894. else
  15895. {
  15896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15897. }
  15898. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  15899. isKnowKey = TRUE;
  15900. }
  15901. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  15902. {
  15903. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  15904. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  15905. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  15906. {
  15907. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  15908. }
  15909. else
  15910. {
  15911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  15912. }
  15913. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15914. isKnowKey = TRUE;
  15915. }
  15916. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15917. {
  15918. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15920. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15921. {
  15922. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15923. }
  15924. else
  15925. {
  15926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15927. }
  15928. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15929. isKnowKey = TRUE;
  15930. }
  15931. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15932. {
  15933. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15935. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15936. {
  15937. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15938. }
  15939. else
  15940. {
  15941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15942. }
  15943. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15944. isKnowKey = TRUE;
  15945. }
  15946. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15947. {
  15948. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15950. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15951. {
  15952. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15953. }
  15954. else
  15955. {
  15956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15957. }
  15958. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15959. isKnowKey = TRUE;
  15960. }
  15961. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15962. {
  15963. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15965. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15966. {
  15967. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15968. }
  15969. else
  15970. {
  15971. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15972. }
  15973. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15974. isKnowKey = TRUE;
  15975. }
  15976. if(isEmpty || strcmp(keyReq, "PreAuthAmount") == 0 )
  15977. {
  15978. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PreAuthAmount].Item, "PreAuthAmount");
  15979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Key, "PreAuthAmount");
  15980. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  15981. {
  15982. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "0"/*"FALSE"*/);
  15983. }
  15984. else
  15985. {
  15986. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "1"/*"TRUE"*/);
  15987. }
  15988. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData );
  15989. isKnowKey = TRUE;
  15990. }
  15991. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15992. {
  15993. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15995. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15996. {
  15997. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15998. }
  15999. else
  16000. {
  16001. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  16002. }
  16003. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  16004. isKnowKey = TRUE;
  16005. }
  16006. #if 1
  16007. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  16008. {
  16009. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  16010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  16011. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16012. {
  16013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  16014. }
  16015. else
  16016. {
  16017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  16018. }
  16019. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  16020. isKnowKey = TRUE;
  16021. }
  16022. #endif
  16023. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  16024. {
  16025. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  16026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  16027. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16028. {
  16029. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16030. }
  16031. else
  16032. {
  16033. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16034. }
  16035. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  16036. isKnowKey = TRUE;
  16037. }
  16038. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  16039. {
  16040. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  16041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  16042. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16043. {
  16044. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16045. }
  16046. else
  16047. {
  16048. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16049. }
  16050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  16051. isKnowKey = TRUE;
  16052. }
  16053. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  16054. {
  16055. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  16056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  16057. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16058. {
  16059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  16060. }
  16061. else
  16062. {
  16063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  16064. }
  16065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16066. isKnowKey = TRUE;
  16067. }
  16068. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  16069. {
  16070. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  16071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  16072. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16073. {
  16074. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  16075. }
  16076. else
  16077. {
  16078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  16079. }
  16080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16081. isKnowKey = TRUE;
  16082. }
  16083. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  16084. {
  16085. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  16086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  16087. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16088. {
  16089. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  16090. }
  16091. else
  16092. {
  16093. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  16094. }
  16095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16096. isKnowKey = TRUE;
  16097. }
  16098. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  16099. {
  16100. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  16101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  16102. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16103. {
  16104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  16105. }
  16106. else
  16107. {
  16108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  16109. }
  16110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16111. isKnowKey = TRUE;
  16112. }
  16113. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  16114. {
  16115. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  16116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  16117. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16118. {
  16119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  16120. }
  16121. else
  16122. {
  16123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  16124. }
  16125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16126. isKnowKey = TRUE;
  16127. }
  16128. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  16129. {
  16130. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  16131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  16132. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16133. {
  16134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  16135. }
  16136. else
  16137. {
  16138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  16139. }
  16140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16141. isKnowKey = TRUE;
  16142. }
  16143. //=========================================================
  16144. if(!isEmpty && !isKnowKey)
  16145. {
  16146. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  16147. strcpy(unknownkey[UnknownKeynum], keyReq);
  16148. UnknownKeynum = UnknownKeynum + 1;
  16149. }
  16150. }
  16151. void processUnkownKey(void)
  16152. {
  16153. DEBUG_INFO("processUnkownKey...\n");
  16154. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  16155. for(int index=0; index < UnknownKeynum; index++)
  16156. {
  16157. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  16158. {
  16159. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  16160. }
  16161. }
  16162. }
  16163. int setKeyValue(char *key, char *value)
  16164. {
  16165. int isSuccess = NotSupported;
  16166. int check_ascii=0;
  16167. char str[501]={0};
  16168. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  16169. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  16170. {
  16171. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  16172. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16173. {
  16174. strcpy(str, (const char*)value);
  16175. for(int i = 0; str[i]; i++){
  16176. str[i] = tolower(str[i]);
  16177. }
  16178. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16179. isSuccess = ConfigurationStatus_Accepted;
  16180. }
  16181. else
  16182. {
  16183. isSuccess = ConfigurationStatus_Rejected;
  16184. }
  16185. }
  16186. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  16187. {
  16188. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  16189. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16190. {
  16191. strcpy(str, (const char*)value);
  16192. for(int i = 0; str[i]; i++){
  16193. str[i] = tolower(str[i]);
  16194. }
  16195. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16196. isSuccess = ConfigurationStatus_Accepted;
  16197. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  16198. }
  16199. else
  16200. {
  16201. isSuccess = ConfigurationStatus_Rejected;
  16202. }
  16203. }
  16204. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  16205. {
  16206. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16207. {
  16208. strcpy(str, (const char*)value);
  16209. for(int i = 0; str[i]; i++)
  16210. {
  16211. str[i] = tolower(str[i]);
  16212. }
  16213. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  16214. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16215. isSuccess = ConfigurationStatus_Accepted;
  16216. }
  16217. else
  16218. {
  16219. isSuccess = ConfigurationStatus_Rejected;
  16220. }
  16221. }
  16222. if(strcmp(key, "BlinkRepeat") == 0)
  16223. {
  16224. //Charger.BlinkRepeat = Integer.parseInt(value);
  16225. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16226. {
  16227. check_ascii = value[0];
  16228. if( (check_ascii < 48) || (check_ascii > 57) )
  16229. {
  16230. isSuccess = ConfigurationStatus_Rejected;
  16231. }
  16232. else
  16233. {
  16234. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  16235. isSuccess = ConfigurationStatus_Accepted;
  16236. }
  16237. }
  16238. else
  16239. {
  16240. isSuccess = ConfigurationStatus_Rejected;
  16241. }
  16242. }
  16243. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  16244. {
  16245. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16246. {
  16247. check_ascii = value[0];
  16248. if( (check_ascii < 48) || (check_ascii > 57) )
  16249. {
  16250. isSuccess = ConfigurationStatus_Rejected;
  16251. }
  16252. else
  16253. {
  16254. if((atoi(value) == 0) || (atoi(value) >= 5))
  16255. {
  16256. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  16257. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  16258. isSuccess = ConfigurationStatus_Accepted;
  16259. }
  16260. else
  16261. isSuccess = ConfigurationStatus_Rejected;
  16262. }
  16263. }
  16264. else
  16265. {
  16266. isSuccess = ConfigurationStatus_Rejected;
  16267. }
  16268. }
  16269. if(strcmp(key, "ConnectionTimeOut") == 0 )
  16270. {
  16271. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  16272. {
  16273. check_ascii = value[0];
  16274. if( (check_ascii < 48) || (check_ascii > 57) )
  16275. {
  16276. isSuccess = ConfigurationStatus_Rejected;
  16277. }
  16278. else
  16279. {
  16280. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  16281. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  16282. isSuccess = ConfigurationStatus_Accepted;
  16283. }
  16284. }
  16285. else
  16286. {
  16287. isSuccess = ConfigurationStatus_Rejected;
  16288. }
  16289. }
  16290. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  16291. {
  16292. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  16293. {
  16294. check_ascii = value[0];
  16295. if( (check_ascii < 48) || (check_ascii > 57) )
  16296. {
  16297. isSuccess = ConfigurationStatus_Rejected;
  16298. }
  16299. else
  16300. {
  16301. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16302. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  16303. isSuccess = ConfigurationStatus_Accepted;
  16304. }
  16305. }
  16306. else
  16307. {
  16308. isSuccess = ConfigurationStatus_Rejected;
  16309. }
  16310. }
  16311. if(strcmp(key, "HeartbeatInterval") == 0)
  16312. {
  16313. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  16314. {
  16315. check_ascii = value[0];
  16316. if( (check_ascii < 48) || (check_ascii > 57) )
  16317. {
  16318. isSuccess = ConfigurationStatus_Rejected;
  16319. }
  16320. else
  16321. {
  16322. if((atoi(value) == 0) || (atoi(value) >= 10))
  16323. {
  16324. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16325. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  16326. HeartBeatWaitTime = atoi(value);
  16327. isSuccess = ConfigurationStatus_Accepted;
  16328. }
  16329. else
  16330. {
  16331. isSuccess = ConfigurationStatus_Rejected;
  16332. }
  16333. }
  16334. }
  16335. else
  16336. {
  16337. isSuccess = ConfigurationStatus_Rejected;
  16338. }
  16339. }
  16340. if(strcmp(key, "LightIntensity") == 0)
  16341. {
  16342. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16343. {
  16344. check_ascii = value[0];
  16345. if( (check_ascii < 48) || (check_ascii > 57) )
  16346. {
  16347. isSuccess = ConfigurationStatus_Rejected;
  16348. }
  16349. else
  16350. {
  16351. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  16352. isSuccess = ConfigurationStatus_Accepted;
  16353. }
  16354. }
  16355. else
  16356. {
  16357. isSuccess = ConfigurationStatus_Rejected;
  16358. }
  16359. }
  16360. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  16361. {
  16362. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  16363. {
  16364. strcpy(str, (const char*)value);
  16365. for(int i = 0; str[i]; i++)
  16366. {
  16367. str[i] = tolower(str[i]);
  16368. }
  16369. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16370. isSuccess = ConfigurationStatus_Accepted;
  16371. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16372. }
  16373. else
  16374. {
  16375. isSuccess = ConfigurationStatus_Rejected;
  16376. }
  16377. }
  16378. if(strcmp(key, "LocalPreAuthorize") == 0)
  16379. {
  16380. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16381. {
  16382. strcpy(str, (const char*)value);
  16383. for(int i = 0; str[i]; i++)
  16384. {
  16385. str[i] = tolower(str[i]);
  16386. }
  16387. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16388. isSuccess = ConfigurationStatus_Accepted;
  16389. }
  16390. else
  16391. {
  16392. isSuccess = ConfigurationStatus_Rejected;
  16393. }
  16394. }
  16395. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  16396. {
  16397. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  16398. {
  16399. check_ascii = value[0];
  16400. if( (check_ascii < 48) || (check_ascii > 57) )
  16401. {
  16402. isSuccess = ConfigurationStatus_Rejected;
  16403. }
  16404. else
  16405. {
  16406. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  16407. isSuccess = ConfigurationStatus_Accepted;
  16408. }
  16409. }
  16410. else
  16411. {
  16412. isSuccess = ConfigurationStatus_Rejected;
  16413. }
  16414. }
  16415. if(strcmp(key, "MeterValuesAlignedData") == 0)
  16416. {
  16417. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  16418. {
  16419. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  16420. isSuccess = ConfigurationStatus_Accepted;
  16421. }
  16422. else
  16423. {
  16424. isSuccess = ConfigurationStatus_Rejected;
  16425. }
  16426. }
  16427. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  16428. {
  16429. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  16430. {
  16431. check_ascii = value[0];
  16432. if( (check_ascii < 48) || (check_ascii > 57) )
  16433. {
  16434. isSuccess = ConfigurationStatus_Rejected;
  16435. }
  16436. else
  16437. {
  16438. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16439. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  16440. isSuccess = ConfigurationStatus_Accepted;
  16441. }
  16442. }
  16443. else
  16444. {
  16445. isSuccess = ConfigurationStatus_Rejected;
  16446. }
  16447. }
  16448. if(strcmp(key, "MeterValuesSampledData") == 0 )
  16449. {
  16450. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  16451. {
  16452. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  16453. isSuccess = ConfigurationStatus_Accepted;
  16454. }
  16455. else
  16456. {
  16457. isSuccess = ConfigurationStatus_Rejected;
  16458. }
  16459. }
  16460. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  16461. {
  16462. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16463. {
  16464. check_ascii = value[0];
  16465. if( (check_ascii < 48) || (check_ascii > 57) )
  16466. {
  16467. isSuccess = ConfigurationStatus_Rejected;
  16468. }
  16469. else
  16470. {
  16471. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16472. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  16473. isSuccess = ConfigurationStatus_Accepted;
  16474. }
  16475. }
  16476. else
  16477. {
  16478. isSuccess = ConfigurationStatus_Rejected;
  16479. }
  16480. }
  16481. if(strcmp(key, "MeterValueSampleInterval") == 0)
  16482. {
  16483. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16484. {
  16485. check_ascii = value[0];
  16486. if( (check_ascii < 48) || (check_ascii > 57) )
  16487. {
  16488. isSuccess = ConfigurationStatus_Rejected;
  16489. }
  16490. else
  16491. {
  16492. if((atoi(value) == 0) || (atoi(value) >= 3))
  16493. {
  16494. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16495. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  16496. isSuccess = ConfigurationStatus_Accepted;
  16497. }
  16498. else
  16499. {
  16500. isSuccess = ConfigurationStatus_Rejected;
  16501. }
  16502. }
  16503. }
  16504. else
  16505. {
  16506. isSuccess = ConfigurationStatus_Rejected;
  16507. }
  16508. }
  16509. if(strcmp(key, "MinimumStatusDuration") == 0)
  16510. {
  16511. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16512. {
  16513. check_ascii = value[0];
  16514. if( (check_ascii < 48) || (check_ascii > 57) )
  16515. {
  16516. isSuccess = ConfigurationStatus_Rejected;
  16517. }
  16518. else
  16519. {
  16520. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  16521. {
  16522. isSuccess = ConfigurationStatus_Rejected;
  16523. }
  16524. else
  16525. {
  16526. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16527. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16528. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16529. isSuccess = ConfigurationStatus_Accepted;
  16530. }
  16531. }
  16532. }
  16533. else
  16534. {
  16535. isSuccess = ConfigurationStatus_Rejected;
  16536. }
  16537. }
  16538. if(strcmp(key, "NumberOfConnectors") == 0)
  16539. {
  16540. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16541. {
  16542. check_ascii = value[0];
  16543. if( (check_ascii < 48) || (check_ascii > 57) )
  16544. {
  16545. isSuccess = ConfigurationStatus_Rejected;
  16546. }
  16547. else
  16548. {
  16549. //Charger.ResetRetries = Integer.parseInt(value);
  16550. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16551. isSuccess = ConfigurationStatus_Accepted;
  16552. }
  16553. }
  16554. else
  16555. {
  16556. isSuccess = ConfigurationStatus_Rejected;
  16557. }
  16558. }
  16559. if(strcmp(key, "ResetRetries") == 0)
  16560. {
  16561. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16562. {
  16563. check_ascii = value[0];
  16564. if( (check_ascii < 48) || (check_ascii > 57) )
  16565. {
  16566. isSuccess = ConfigurationStatus_Rejected;
  16567. }
  16568. else
  16569. {
  16570. //Charger.ResetRetries = Integer.parseInt(value);
  16571. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16572. isSuccess = ConfigurationStatus_Accepted;
  16573. }
  16574. }
  16575. else
  16576. {
  16577. isSuccess = ConfigurationStatus_Rejected;
  16578. }
  16579. }
  16580. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16581. {
  16582. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16583. {
  16584. strcpy(str, (const char*)value);
  16585. for(int i = 0; str[i]; i++)
  16586. {
  16587. str[i] = tolower(str[i]);
  16588. }
  16589. if(strcmp(str, "notapplicable")== 0)
  16590. {
  16591. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16592. isSuccess = ConfigurationStatus_Accepted;
  16593. }
  16594. else if(strcmp(str, "unknown")== 0)
  16595. {
  16596. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16597. isSuccess = ConfigurationStatus_Accepted;
  16598. }
  16599. else if(strcmp(str, "rst")== 0)
  16600. {
  16601. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16602. isSuccess = ConfigurationStatus_Accepted;
  16603. }
  16604. else if(strcmp(str, "rts")== 0)
  16605. {
  16606. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16607. isSuccess = ConfigurationStatus_Accepted;
  16608. }
  16609. else if(strcmp(str, "srt")== 0)
  16610. {
  16611. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16612. isSuccess = ConfigurationStatus_Accepted;
  16613. }
  16614. else if(strcmp(str, "str")== 0)
  16615. {
  16616. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16617. isSuccess = ConfigurationStatus_Accepted;
  16618. }
  16619. else if(strcmp(str, "trs")== 0)
  16620. {
  16621. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16622. isSuccess = ConfigurationStatus_Accepted;
  16623. }
  16624. else if(strcmp(str, "tsr")== 0)
  16625. {
  16626. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16627. isSuccess = ConfigurationStatus_Accepted;
  16628. }
  16629. else
  16630. {
  16631. isSuccess = ConfigurationStatus_Rejected;
  16632. }
  16633. }
  16634. else
  16635. {
  16636. isSuccess = ConfigurationStatus_Rejected;
  16637. }
  16638. }
  16639. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16640. {
  16641. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16642. {
  16643. check_ascii = value[0];
  16644. if( (check_ascii < 48) || (check_ascii > 57) )
  16645. {
  16646. isSuccess = ConfigurationStatus_Rejected;
  16647. }
  16648. else
  16649. {
  16650. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16651. isSuccess = ConfigurationStatus_Accepted;
  16652. }
  16653. }
  16654. else
  16655. {
  16656. isSuccess = ConfigurationStatus_Rejected;
  16657. }
  16658. }
  16659. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16660. {
  16661. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16662. {
  16663. strcpy(str, (const char*)value);
  16664. for(int i = 0; str[i]; i++)
  16665. {
  16666. str[i] = tolower(str[i]);
  16667. }
  16668. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16669. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16670. isSuccess = ConfigurationStatus_Accepted;
  16671. }
  16672. else
  16673. {
  16674. isSuccess = ConfigurationStatus_Rejected;
  16675. }
  16676. }
  16677. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16678. {
  16679. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16680. {
  16681. strcpy(str, (const char*)value);
  16682. for(int i = 0; str[i]; i++)
  16683. {
  16684. str[i] = tolower(str[i]);
  16685. }
  16686. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16687. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16688. isSuccess = ConfigurationStatus_Accepted;
  16689. }
  16690. else
  16691. {
  16692. isSuccess = ConfigurationStatus_Rejected;
  16693. }
  16694. }
  16695. if(strcmp(key, "StopTxnAlignedData") == 0)
  16696. {
  16697. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16698. {
  16699. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16700. isSuccess = ConfigurationStatus_Accepted;
  16701. }
  16702. else
  16703. {
  16704. isSuccess = ConfigurationStatus_Rejected;
  16705. }
  16706. }
  16707. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16708. {
  16709. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16710. {
  16711. check_ascii = value[0];
  16712. if( (check_ascii < 48) || (check_ascii > 57) )
  16713. {
  16714. isSuccess = ConfigurationStatus_Rejected;
  16715. }
  16716. else
  16717. {
  16718. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16719. isSuccess = ConfigurationStatus_Accepted;
  16720. }
  16721. }
  16722. else
  16723. {
  16724. isSuccess = ConfigurationStatus_Rejected;
  16725. }
  16726. }
  16727. if(strcmp(key, "StopTxnSampledData") == 0)
  16728. {
  16729. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16730. {
  16731. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16732. isSuccess = ConfigurationStatus_Accepted;
  16733. }
  16734. else
  16735. {
  16736. isSuccess = ConfigurationStatus_Rejected;
  16737. }
  16738. }
  16739. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16740. {
  16741. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16742. {
  16743. check_ascii = value[0];
  16744. if( (check_ascii < 48) || (check_ascii > 57) )
  16745. {
  16746. isSuccess = ConfigurationStatus_Rejected;
  16747. }
  16748. else
  16749. {
  16750. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16751. isSuccess = ConfigurationStatus_Accepted;
  16752. }
  16753. }
  16754. else
  16755. {
  16756. isSuccess = ConfigurationStatus_Rejected;
  16757. }
  16758. }
  16759. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16760. {
  16761. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16762. {
  16763. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16764. isSuccess = ConfigurationStatus_Accepted;
  16765. }
  16766. else
  16767. {
  16768. isSuccess = ConfigurationStatus_Rejected;
  16769. }
  16770. }
  16771. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16772. {
  16773. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16774. {
  16775. check_ascii = value[0];
  16776. if( (check_ascii < 48) || (check_ascii > 57) )
  16777. {
  16778. isSuccess = ConfigurationStatus_Rejected;
  16779. }
  16780. else
  16781. {
  16782. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16783. isSuccess = ConfigurationStatus_Accepted;
  16784. }
  16785. }
  16786. else
  16787. {
  16788. isSuccess = ConfigurationStatus_Rejected;
  16789. }
  16790. }
  16791. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16792. {
  16793. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16794. {
  16795. check_ascii = value[0];
  16796. if( (check_ascii < 48) || (check_ascii > 57) )
  16797. {
  16798. isSuccess = ConfigurationStatus_Rejected;
  16799. }
  16800. else
  16801. {
  16802. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16803. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16804. TransactionMessageAttemptsValue = atoi(value);
  16805. isSuccess = ConfigurationStatus_Accepted;
  16806. }
  16807. }
  16808. else
  16809. {
  16810. isSuccess = ConfigurationStatus_Rejected;
  16811. }
  16812. }
  16813. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16814. {
  16815. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16816. {
  16817. check_ascii = value[0];
  16818. if( (check_ascii < 48) || (check_ascii > 57) )
  16819. {
  16820. isSuccess = ConfigurationStatus_Rejected;
  16821. }
  16822. else
  16823. {
  16824. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16825. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16826. TransactionMessageRetryIntervalValue = atoi(value);
  16827. isSuccess = ConfigurationStatus_Accepted;
  16828. }
  16829. }
  16830. else
  16831. {
  16832. isSuccess = ConfigurationStatus_Rejected;
  16833. }
  16834. }
  16835. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16836. {
  16837. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16838. {
  16839. strcpy(str, (const char*)value);
  16840. for(int i = 0; str[i]; i++)
  16841. {
  16842. str[i] = tolower(str[i]);
  16843. }
  16844. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16845. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16846. isSuccess = ConfigurationStatus_Accepted;
  16847. }
  16848. else
  16849. {
  16850. isSuccess = ConfigurationStatus_Rejected;
  16851. }
  16852. }
  16853. if(strcmp(key, "WebSocketPingInterval") == 0)
  16854. {
  16855. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16856. {
  16857. check_ascii = value[0];
  16858. if( (check_ascii < 48) || (check_ascii > 57) )
  16859. {
  16860. isSuccess = ConfigurationStatus_Rejected;
  16861. }
  16862. else
  16863. {
  16864. if((atoi(value) == 0) || (atoi(value) >= 10))
  16865. {
  16866. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16867. isSuccess = ConfigurationStatus_Accepted;
  16868. }
  16869. else
  16870. isSuccess = ConfigurationStatus_Rejected;
  16871. }
  16872. }
  16873. else
  16874. {
  16875. isSuccess = ConfigurationStatus_Rejected;
  16876. }
  16877. }
  16878. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16879. {
  16880. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16881. {
  16882. strcpy(str, (const char*)value);
  16883. for(int i = 0; str[i]; i++)
  16884. {
  16885. str[i] = tolower(str[i]);
  16886. }
  16887. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16888. isSuccess = ConfigurationStatus_Accepted;
  16889. }
  16890. else
  16891. {
  16892. isSuccess = ConfigurationStatus_Rejected;
  16893. }
  16894. }
  16895. if(strcmp(key, "AuthorizationKey") == 0)
  16896. {
  16897. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16898. {
  16899. strcpy(str, (const char*)value);
  16900. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16901. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16902. isSuccess = ConfigurationStatus_Accepted;
  16903. }
  16904. else
  16905. {
  16906. isSuccess = ConfigurationStatus_Rejected;
  16907. }
  16908. }
  16909. if(strcmp(key, "SecurityProfile") == 0)
  16910. {
  16911. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16912. {
  16913. check_ascii = value[0];
  16914. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16915. {
  16916. isSuccess = ConfigurationStatus_Rejected;
  16917. }
  16918. else if(check_ascii == 0x33)
  16919. {
  16920. isSuccess = NotSupported;
  16921. }
  16922. else
  16923. {
  16924. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16925. {
  16926. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16927. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  16928. isSuccess = ConfigurationStatus_Accepted;
  16929. }
  16930. else
  16931. isSuccess = ConfigurationStatus_Rejected;
  16932. }
  16933. }
  16934. else
  16935. {
  16936. isSuccess = ConfigurationStatus_Rejected;
  16937. }
  16938. }
  16939. if(strcmp(key, "DefaultPrice") == 0)
  16940. {
  16941. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16942. {
  16943. strcpy(str, (const char*)value);
  16944. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16945. isSuccess = ConfigurationStatus_Accepted;
  16946. }
  16947. else
  16948. {
  16949. isSuccess = ConfigurationStatus_Rejected;
  16950. }
  16951. }
  16952. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16953. {
  16954. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16955. {
  16956. strcpy(str, (const char*)value);
  16957. for(int i = 0; str[i]; i++)
  16958. {
  16959. str[i] = tolower(str[i]);
  16960. }
  16961. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16962. isSuccess = ConfigurationStatus_Accepted;
  16963. }
  16964. else
  16965. {
  16966. isSuccess = ConfigurationStatus_Rejected;
  16967. }
  16968. }
  16969. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16970. {
  16971. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16972. {
  16973. strcpy(str, (const char*)value);
  16974. for(int i = 0; str[i]; i++)
  16975. {
  16976. str[i] = tolower(str[i]);
  16977. }
  16978. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16979. isSuccess = ConfigurationStatus_Accepted;
  16980. }
  16981. else
  16982. {
  16983. isSuccess = ConfigurationStatus_Rejected;
  16984. }
  16985. }
  16986. if(strcmp(key, "TimeOffset") == 0)
  16987. {
  16988. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  16989. {
  16990. strcpy(str, (const char*)value);
  16991. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  16992. isSuccess = ConfigurationStatus_Accepted;
  16993. }
  16994. else
  16995. {
  16996. isSuccess = ConfigurationStatus_Rejected;
  16997. }
  16998. }
  16999. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  17000. {
  17001. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  17002. {
  17003. strcpy(str, (const char*)value);
  17004. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  17005. isSuccess = ConfigurationStatus_Accepted;
  17006. }
  17007. else
  17008. {
  17009. isSuccess = ConfigurationStatus_Rejected;
  17010. }
  17011. }
  17012. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  17013. {
  17014. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  17015. {
  17016. strcpy(str, (const char*)value);
  17017. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  17018. isSuccess = ConfigurationStatus_Accepted;
  17019. }
  17020. else
  17021. {
  17022. isSuccess = ConfigurationStatus_Rejected;
  17023. }
  17024. }
  17025. if(strcmp(key, "SystemUptimeSec") == 0)
  17026. {
  17027. isSuccess = NotSupported;
  17028. }
  17029. if(strcmp(key, "FreeVend") == 0)
  17030. {
  17031. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17032. {
  17033. strcpy(str, (const char*)value);
  17034. for(int i = 0; str[i]; i++)
  17035. {
  17036. str[i] = tolower(str[i]);
  17037. }
  17038. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  17039. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17040. isSuccess = ConfigurationStatus_Accepted;
  17041. }
  17042. else
  17043. {
  17044. isSuccess = ConfigurationStatus_Rejected;
  17045. }
  17046. }
  17047. if(strcmp(key, "FreeVendIdtag") == 0)
  17048. {
  17049. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17050. {
  17051. strcpy(str, (const char*)value);
  17052. if(strlen(str) <= 20)
  17053. {
  17054. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  17055. isSuccess = ConfigurationStatus_Accepted;
  17056. }
  17057. else
  17058. {
  17059. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  17060. isSuccess = ConfigurationStatus_Rejected;
  17061. }
  17062. }
  17063. else
  17064. {
  17065. isSuccess = ConfigurationStatus_Rejected;
  17066. }
  17067. }
  17068. if(strcmp(key, "OcppServer") == 0)
  17069. {
  17070. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17071. {
  17072. strcpy(str, (const char*)value);
  17073. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  17074. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  17075. isSuccess = ConfigurationStatus_Accepted;
  17076. }
  17077. else
  17078. {
  17079. isSuccess = ConfigurationStatus_Rejected;
  17080. }
  17081. }
  17082. if(strcmp(key, "MaintainServer") == 0)
  17083. {
  17084. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17085. {
  17086. strcpy(str, (const char*)value);
  17087. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  17088. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  17089. isSuccess = ConfigurationStatus_Accepted;
  17090. }
  17091. else
  17092. {
  17093. isSuccess = ConfigurationStatus_Rejected;
  17094. }
  17095. }
  17096. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  17097. {
  17098. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17099. {
  17100. strcpy(str, (const char*)value);
  17101. for(int i = 0; str[i]; i++)
  17102. {
  17103. str[i] = tolower(str[i]);
  17104. }
  17105. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  17106. isSuccess = ConfigurationStatus_Accepted;
  17107. }
  17108. else
  17109. {
  17110. isSuccess = ConfigurationStatus_Rejected;
  17111. }
  17112. }
  17113. if(strcmp(key, "StatusNotificationInterval") == 0)
  17114. {
  17115. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17116. {
  17117. check_ascii = value[0];
  17118. if( (check_ascii < 48) || (check_ascii > 57) )
  17119. {
  17120. isSuccess = ConfigurationStatus_Rejected;
  17121. }
  17122. else
  17123. {
  17124. if((atoi(value) == 0) || (atoi(value) >= 10))
  17125. {
  17126. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  17127. isSuccess = ConfigurationStatus_Accepted;
  17128. }
  17129. else
  17130. isSuccess = ConfigurationStatus_Rejected;
  17131. }
  17132. }
  17133. else
  17134. {
  17135. isSuccess = ConfigurationStatus_Rejected;
  17136. }
  17137. }
  17138. if(strcmp(key, "PreAuthAmount") == 0)
  17139. {
  17140. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  17141. {
  17142. check_ascii = value[0];
  17143. if( (check_ascii < 48) || (check_ascii > 57) )
  17144. {
  17145. isSuccess = ConfigurationStatus_Rejected;
  17146. }
  17147. else
  17148. {
  17149. if(atof(value) >= 0)
  17150. {
  17151. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(value) );
  17152. isSuccess = ConfigurationStatus_Accepted;
  17153. }
  17154. else
  17155. isSuccess = ConfigurationStatus_Rejected;
  17156. }
  17157. }
  17158. else
  17159. {
  17160. isSuccess = ConfigurationStatus_Rejected;
  17161. }
  17162. }
  17163. #if 0
  17164. //For OCPP Test Case
  17165. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  17166. {
  17167. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17168. {
  17169. strcpy(str, (const char*)value);
  17170. for(int i = 0; str[i]; i++)
  17171. {
  17172. str[i] = tolower(str[i]);
  17173. }
  17174. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17175. isSuccess = ConfigurationStatus_Accepted;
  17176. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17177. }
  17178. else
  17179. {
  17180. isSuccess = ConfigurationStatus_Rejected;
  17181. }
  17182. }
  17183. #endif
  17184. #if 1
  17185. if(strcmp(key, "LocalAuthListEnabled") == 0)
  17186. {
  17187. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17188. {
  17189. strcpy(str, (const char*)value);
  17190. for(int i = 0; str[i]; i++)
  17191. {
  17192. str[i] = tolower(str[i]);
  17193. }
  17194. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17195. isSuccess = ConfigurationStatus_Accepted;
  17196. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17197. }
  17198. else
  17199. {
  17200. isSuccess = ConfigurationStatus_Rejected;
  17201. }
  17202. }
  17203. #endif
  17204. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  17205. {
  17206. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  17207. {
  17208. check_ascii = value[0];
  17209. if( (check_ascii < 48) || (check_ascii > 57) )
  17210. {
  17211. isSuccess = ConfigurationStatus_Rejected;
  17212. }
  17213. else
  17214. {
  17215. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  17216. isSuccess = ConfigurationStatus_Accepted;
  17217. }
  17218. }
  17219. else
  17220. {
  17221. isSuccess = ConfigurationStatus_Rejected;
  17222. }
  17223. }
  17224. if(strcmp(key, "SendLocalListMaxLength") == 0)
  17225. {
  17226. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17227. {
  17228. check_ascii = value[0];
  17229. if( (check_ascii < 48) || (check_ascii > 57) )
  17230. {
  17231. isSuccess = ConfigurationStatus_Rejected;
  17232. }
  17233. else
  17234. {
  17235. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  17236. isSuccess = ConfigurationStatus_Accepted;
  17237. }
  17238. }
  17239. else
  17240. {
  17241. isSuccess = ConfigurationStatus_Rejected;
  17242. }
  17243. }
  17244. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  17245. {
  17246. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17247. {
  17248. strcpy(str, (const char*)value);
  17249. for(int i = 0; str[i]; i++)
  17250. {
  17251. str[i] = tolower(str[i]);
  17252. }
  17253. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17254. isSuccess = ConfigurationStatus_Accepted;
  17255. }
  17256. else
  17257. {
  17258. isSuccess = ConfigurationStatus_Rejected;
  17259. }
  17260. }
  17261. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  17262. {
  17263. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17264. {
  17265. check_ascii = value[0];
  17266. if( (check_ascii < 48) || (check_ascii > 57) )
  17267. {
  17268. isSuccess = ConfigurationStatus_Rejected;
  17269. }
  17270. else
  17271. {
  17272. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  17273. isSuccess = ConfigurationStatus_Accepted;
  17274. }
  17275. }
  17276. else
  17277. {
  17278. isSuccess = ConfigurationStatus_Rejected;
  17279. }
  17280. }
  17281. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  17282. {
  17283. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17284. {
  17285. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  17286. isSuccess = ConfigurationStatus_Accepted;
  17287. }
  17288. else
  17289. {
  17290. isSuccess = ConfigurationStatus_Rejected;
  17291. }
  17292. }
  17293. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  17294. {
  17295. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17296. {
  17297. check_ascii = value[0];
  17298. if( (check_ascii < 48) || (check_ascii > 57) )
  17299. {
  17300. isSuccess = ConfigurationStatus_Rejected;
  17301. }
  17302. else
  17303. {
  17304. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  17305. isSuccess = ConfigurationStatus_Accepted;
  17306. }
  17307. }
  17308. else
  17309. {
  17310. isSuccess = ConfigurationStatus_Rejected;
  17311. }
  17312. }
  17313. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  17314. {
  17315. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17316. {
  17317. strcpy(str, (const char*)value);
  17318. for(int i = 0; str[i]; i++)
  17319. {
  17320. str[i] = tolower(str[i]);
  17321. }
  17322. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17323. isSuccess = ConfigurationStatus_Accepted;
  17324. }
  17325. else
  17326. {
  17327. isSuccess = ConfigurationStatus_Rejected;
  17328. }
  17329. }
  17330. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  17331. {
  17332. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  17333. {
  17334. check_ascii = value[0];
  17335. if( (check_ascii < 48) || (check_ascii > 57) )
  17336. {
  17337. isSuccess = ConfigurationStatus_Rejected;
  17338. }
  17339. else
  17340. {
  17341. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  17342. isSuccess = ConfigurationStatus_Accepted;
  17343. }
  17344. }
  17345. else
  17346. {
  17347. isSuccess = ConfigurationStatus_Rejected;
  17348. }
  17349. }
  17350. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17351. return isSuccess;
  17352. }
  17353. int TransactionMessageAttemptsGet(void)
  17354. {
  17355. return TransactionMessageAttemptsValue;
  17356. }
  17357. int FirstHeartBeatResponse(void)
  17358. {
  17359. return FirstHeartBeat;
  17360. }
  17361. int TransactionMessageRetryIntervalGet(void)
  17362. {
  17363. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17364. }
  17365. int ReadHttpStatus(int sock)
  17366. {
  17367. //char c;
  17368. char buff[1024]="",*ptr=buff+1;
  17369. int bytes_received, status;
  17370. DEBUG_INFO("Begin Response ..\n");
  17371. while((bytes_received = recv(sock, ptr, 1, 0))){
  17372. if(bytes_received==-1){
  17373. perror("ReadHttpStatus");
  17374. exit(1);
  17375. }
  17376. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  17377. ptr++;
  17378. }
  17379. *ptr=0;
  17380. ptr=buff+1;
  17381. sscanf(ptr,"%*s %d ", &status);
  17382. DEBUG_INFO("%s\n",ptr);
  17383. DEBUG_INFO("status=%d\n",status);
  17384. DEBUG_INFO("End Response ..\n");
  17385. return (bytes_received>0)?status:0;
  17386. }
  17387. //the only filed that it parsed is 'Content-Length'
  17388. int ParseHeader(int sock)
  17389. {
  17390. //char c;
  17391. char buff[1024]="",*ptr=buff+4;
  17392. int bytes_received;
  17393. DEBUG_INFO("Begin HEADER ..\n");
  17394. while((bytes_received = recv(sock, ptr, 1, 0))){
  17395. if(bytes_received==-1){
  17396. perror("Parse Header");
  17397. exit(1);
  17398. }
  17399. if(
  17400. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  17401. (ptr[-1]=='\r') && (*ptr=='\n' )
  17402. ) break;
  17403. ptr++;
  17404. }
  17405. *ptr=0;
  17406. ptr=buff+4;
  17407. //printf("%s",ptr);
  17408. if(bytes_received){
  17409. ptr=strstr(ptr,"Content-Length:");
  17410. if(ptr){
  17411. sscanf(ptr,"%*s %d",&bytes_received);
  17412. }else
  17413. bytes_received=-1; //unknown size
  17414. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  17415. }
  17416. DEBUG_INFO("End HEADER ..\n");
  17417. return bytes_received ;
  17418. }
  17419. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  17420. {
  17421. int result = TRUE;
  17422. char rmFileCmd[100]={0};
  17423. char FilePath[100]={0};
  17424. char ftpbuf[200];
  17425. int systemresult;
  17426. sprintf(FilePath,"/mnt/%s",filename);
  17427. system("ping 8.8.8.8 &");
  17428. if((access(FilePath,F_OK))!=-1)
  17429. {
  17430. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17431. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17432. system(rmFileCmd);
  17433. }
  17434. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17435. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  17436. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17437. systemresult = system(ftpbuf);
  17438. if(systemresult != 0)
  17439. {
  17440. DEBUG_INFO("http DownLoad error!\n");
  17441. result = FALSE;
  17442. }
  17443. system("pkill ping");
  17444. return result;
  17445. }
  17446. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  17447. {
  17448. int result = TRUE;
  17449. char rmFileCmd[100]={0};
  17450. char FilePath[100]={0};
  17451. char ftpbuf[200];
  17452. int systemresult;
  17453. sprintf(FilePath,"/mnt/%s",filename);
  17454. system("ping 8.8.8.8 &");
  17455. if((access(FilePath,F_OK))!=-1)
  17456. {
  17457. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17458. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17459. system(rmFileCmd);
  17460. }
  17461. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17462. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  17463. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17464. systemresult = system(ftpbuf);
  17465. if(systemresult != 0)
  17466. {
  17467. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  17468. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17469. systemresult = system(ftpbuf);
  17470. if(systemresult != 0)
  17471. {
  17472. DEBUG_WARN("wget error!\n");
  17473. result = FALSE;
  17474. }
  17475. }
  17476. system("pkill ping");
  17477. return result;
  17478. }
  17479. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17480. {
  17481. char rmFileCmd[100]={0};
  17482. char FilePath[100]={0};
  17483. char buf[512];
  17484. int systemresult = 0;
  17485. //DEBUG_INFO("filename=%s\n",filename);
  17486. //DEBUG_INFO("url=%s\n",url);
  17487. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17488. if((access(FilePath,F_OK))!=-1)
  17489. {
  17490. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17491. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17492. system(rmFileCmd);
  17493. }
  17494. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17495. if(fp == NULL)
  17496. {
  17497. DEBUG_INFO("log is NULL\n");
  17498. return FALSE;
  17499. }
  17500. else
  17501. {
  17502. fprintf(fp, "%s\n", url);
  17503. fprintf(fp, "%s\n", filename);
  17504. fclose(fp);
  17505. }
  17506. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  17507. if(phpFP == NULL)
  17508. {
  17509. DEBUG_INFO("PHP upload fail.\n");
  17510. return FALSE;
  17511. }
  17512. else
  17513. {
  17514. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17515. {
  17516. if(strstr(buf, "result") != NULL)
  17517. {
  17518. sscanf(buf, "result: %d", &systemresult);
  17519. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17520. }
  17521. }
  17522. pclose(phpFP);
  17523. }
  17524. if(systemresult != 1)
  17525. {
  17526. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  17527. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  17528. if(phpFP == NULL)
  17529. {
  17530. DEBUG_WARN("PHP PUT upload fail.\n");
  17531. return FALSE;
  17532. }
  17533. else
  17534. {
  17535. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17536. {
  17537. if(strstr(buf, "result") != NULL)
  17538. {
  17539. sscanf(buf, "result: %d", &systemresult);
  17540. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  17541. }
  17542. }
  17543. pclose(phpFP);
  17544. }
  17545. }
  17546. return TRUE;
  17547. }
  17548. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17549. {
  17550. int result = FALSE;
  17551. char ftpbuf[200];
  17552. int systemresult;
  17553. /*
  17554. // Domaind name transfer to IP address
  17555. struct hostent* server;
  17556. char *IPbuffer;
  17557. server = gethostbyname(location);
  17558. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17559. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17560. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17561. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  17562. systemresult = system(ftpbuf);
  17563. if(systemresult != 0)
  17564. {
  17565. DEBUG_INFO("ftpput error!\n");
  17566. }
  17567. else
  17568. {
  17569. result = TRUE;
  17570. DEBUG_INFO("ftpput OK!\n");
  17571. }
  17572. return result;
  17573. }
  17574. int GetOcppServerURL()
  17575. {
  17576. int result = FALSE;
  17577. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  17578. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  17579. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  17580. struct yuarel url;
  17581. char urlStr[512];
  17582. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  17583. {
  17584. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  17585. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17586. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17587. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  17588. if(yuarel_parse(&url, urlStr) != -1)
  17589. {
  17590. sprintf(OcppProtocol, "%s", url.scheme);
  17591. sprintf(OcppHost, "%s", url.host);
  17592. if(url.path == NULL)
  17593. OcppTempPath[0] = '\0';
  17594. else
  17595. {
  17596. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  17597. {
  17598. sprintf(OcppTempPath, "%s/", url.path);
  17599. }
  17600. else
  17601. {
  17602. sprintf(OcppTempPath, "%s", url.path);
  17603. }
  17604. }
  17605. if(url.port == 0)
  17606. {
  17607. if(strcmp(OcppProtocol, "wss") == 0)
  17608. OcppPort = 443;
  17609. else
  17610. OcppPort = 80;
  17611. }
  17612. else
  17613. OcppPort = url.port;
  17614. result = TRUE;
  17615. }
  17616. }
  17617. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  17618. {
  17619. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  17620. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17621. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17622. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  17623. if(yuarel_parse(&url, urlStr) != -1)
  17624. {
  17625. sprintf(OcppProtocol, "%s", url.scheme);
  17626. sprintf(OcppHost, "%s", url.host);
  17627. if(url.path == NULL)
  17628. OcppTempPath[0] = '\0';
  17629. else
  17630. sprintf(OcppTempPath, "%s", url.path);
  17631. if(url.port == 0)
  17632. {
  17633. if(strcmp(OcppProtocol, "wss") == 0)
  17634. OcppPort = 443;
  17635. else
  17636. OcppPort = 80;
  17637. }
  17638. else
  17639. OcppPort = url.port;
  17640. result = TRUE;
  17641. }
  17642. }
  17643. else
  17644. {
  17645. strcpy(OcppHost,"");
  17646. }
  17647. return result;
  17648. }
  17649. int GetOcppPath()
  17650. {
  17651. int result = FALSE;
  17652. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  17653. {
  17654. if(OcppTempPath == NULL)
  17655. {
  17656. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17657. }
  17658. else
  17659. {
  17660. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17661. }
  17662. result = TRUE;
  17663. goto End;
  17664. }
  17665. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  17666. {
  17667. if(OcppTempPath == NULL)
  17668. {
  17669. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  17670. }
  17671. else
  17672. {
  17673. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  17674. }
  17675. result = TRUE;
  17676. goto End;
  17677. }
  17678. else
  17679. {
  17680. strcpy(OcppPath,"");
  17681. }
  17682. End:
  17683. return result;
  17684. }
  17685. int GetOcppPort()
  17686. {
  17687. return OcppPort;
  17688. }
  17689. int GetOcppConnStatus(void)
  17690. {
  17691. return ShmOCPP16Data->OcppConnStatus;
  17692. }
  17693. void SetOcppConnStatus(uint8_t status)
  17694. {
  17695. ShmOCPP16Data->OcppConnStatus = status;
  17696. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  17697. }
  17698. int GetHeartBeatWithNOResponse(void)
  17699. {
  17700. return HeartBeatWithNOResponse;
  17701. }
  17702. void SetHeartBeatWithNOResponse(void)
  17703. {
  17704. HeartBeatWithNOResponse = 0;
  17705. }
  17706. void GetStartTransactionIdTag(int gun_index)
  17707. {
  17708. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17709. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17710. }
  17711. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17712. {
  17713. char ch;
  17714. FILE *fptr1;
  17715. int temptransactionId;
  17716. char str[100]={0};
  17717. temptransactionId = 0;
  17718. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17719. {
  17720. DEBUG_INFO("IdTag is empty.\n");
  17721. return temptransactionId;
  17722. }
  17723. /*------ Read the file ----------------*/
  17724. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  17725. if (!fptr1)
  17726. {
  17727. DEBUG_INFO("QueueTransactionId file open error.\n");
  17728. //printf(" File not found or unable to open the input file!!\n");
  17729. return temptransactionId;
  17730. }
  17731. ch=fgetc(fptr1);
  17732. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  17733. rewind(fptr1);
  17734. if(ch!=EOF)
  17735. {
  17736. // printf("%c",ch);
  17737. while (fgets(str, 100, fptr1) != NULL)
  17738. {
  17739. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17740. if(str[0]=='\0')
  17741. {
  17742. break;
  17743. }
  17744. char *revbuf[8] = {0}; // Variable store string split
  17745. int num = 0;// Quantity after string split
  17746. DEBUG_INFO("Transaction queue data= %s\n", str);
  17747. splitstring(str,",",revbuf,&num); // String split
  17748. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17749. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17750. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17751. DEBUG_INFO("------------------------------\n");
  17752. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17753. {
  17754. if(isStopTransaction)
  17755. {
  17756. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17757. {
  17758. temptransactionId = atoi(revbuf[2]);
  17759. //break;
  17760. }
  17761. }
  17762. else
  17763. {
  17764. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17765. {
  17766. temptransactionId = atoi(revbuf[2]);
  17767. //break;
  17768. }
  17769. }
  17770. }
  17771. }
  17772. }
  17773. else
  17774. DEBUG_INFO("EOF\n");
  17775. fclose(fptr1);
  17776. /*------- End of reading ---------------*/
  17777. return temptransactionId;
  17778. }
  17779. void SetTransactionIdZero(int transactionId)
  17780. {
  17781. char ch;
  17782. FILE *fptr1, *fptr2;
  17783. int temptransactionId = 0;
  17784. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  17785. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  17786. if (!fptr1)
  17787. {
  17788. //printf(" File not found or unable to open the input file!!\n");
  17789. return ;
  17790. }
  17791. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17792. if (!fptr2)
  17793. {
  17794. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17795. fclose(fptr1);
  17796. return ;
  17797. }
  17798. ch=fgetc(fptr1);
  17799. rewind(fptr1);
  17800. if(ch!=EOF)
  17801. {
  17802. // copy all contents to the temporary file except the specific line
  17803. while (fgets(str, 100, fptr1) != NULL)
  17804. {
  17805. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17806. if(str[0]=='\0')
  17807. {
  17808. break;
  17809. }
  17810. char *revbuf[8] = {0};
  17811. int num = 0;
  17812. strcpy(strtemp, str);
  17813. splitstring(str,",",revbuf,&num);
  17814. if(revbuf[2][0] != '\0')
  17815. {
  17816. temptransactionId = atoi(revbuf[2]);
  17817. if(transactionId != temptransactionId)
  17818. {
  17819. fprintf(fptr2, "%s\n", strtemp);
  17820. }
  17821. }
  17822. }
  17823. }
  17824. fclose(fptr1);
  17825. fclose(fptr2);
  17826. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  17827. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  17828. /*------ Read the file ----------------*/
  17829. }
  17830. int InternetDisconnect(void)
  17831. {
  17832. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  17833. }
  17834. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17835. void storeTempStopTransaction(int gun_index)
  17836. {
  17837. char guid[37]={0};
  17838. int tempIndex = 0;
  17839. char TempStopTransaction[256];
  17840. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  17841. DEBUG_INFO("storeTempStopTransaction...\n");
  17842. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  17843. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  17844. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  17845. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17846. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17847. {
  17848. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17849. {
  17850. tempIndex = ((gun_index==2) ? 1: 0);
  17851. }
  17852. else
  17853. {
  17854. tempIndex = gun_index;
  17855. }
  17856. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17857. {
  17858. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17859. {
  17860. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  17861. }
  17862. }// END OF CHAdeMO_QUANTITY
  17863. }
  17864. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17865. {
  17866. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17867. {
  17868. tempIndex = ((gun_index==2) ? 1: 0);
  17869. }
  17870. else
  17871. {
  17872. tempIndex = gun_index;
  17873. }
  17874. for (int index = 0; index < CCS_QUANTITY; index++)
  17875. {
  17876. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17877. {
  17878. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  17879. }
  17880. }// END OF CCS_QUANTITY
  17881. }
  17882. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17883. {
  17884. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17885. {
  17886. tempIndex = ((gun_index==2) ? 1: 0);
  17887. }
  17888. else
  17889. {
  17890. tempIndex = gun_index;
  17891. }
  17892. for (int index = 0; index < GB_QUANTITY; index++)
  17893. {
  17894. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17895. {
  17896. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17897. }
  17898. }// END OF GB_QUANTITY
  17899. }
  17900. else if(gunType[gun_index] == GUN_TYPE_DO)
  17901. {
  17902. tempIndex = gun_index;
  17903. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17904. {
  17905. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17906. {
  17907. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17908. }
  17909. }
  17910. }
  17911. else
  17912. {
  17913. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17914. {
  17915. tempIndex = 2;
  17916. }
  17917. else
  17918. {
  17919. tempIndex = gun_index;
  17920. }
  17921. for (int index = 0; index < AC_QUANTITY; index++)
  17922. {
  17923. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17924. {
  17925. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17926. }
  17927. }// END OF AC_QUANTITY
  17928. }
  17929. //Stop Transaction Time
  17930. struct timeval tmnow;
  17931. struct tm *tm;
  17932. char buf[28];//, usec_buf[6];
  17933. gettimeofday(&tmnow, NULL);
  17934. time_t t;
  17935. t = time(NULL);
  17936. /*UTC time and date*/
  17937. tm = gmtime(&t);
  17938. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17939. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  17940. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  17941. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  17942. random_uuid(guid);
  17943. /***********************************transactionData******************************************************/
  17944. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17945. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17946. //=================================
  17947. //1. Transaction_Begin
  17948. //=================================
  17949. //============================== Energy.Active.Import.Interval ===========================================
  17950. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17951. {
  17952. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  17953. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17954. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  17955. 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*/]);
  17956. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17957. 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))
  17958. {
  17959. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  17960. }
  17961. else
  17962. {
  17963. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  17964. }
  17965. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  17966. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17967. }
  17968. //=================================
  17969. //2. Transaction_End
  17970. //=================================
  17971. //2.1====================================== Current.Import L1 ==============================================
  17972. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17973. {
  17974. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17975. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17976. {
  17977. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17978. {
  17979. tempIndex = ((gun_index==2) ? 1: 0);
  17980. }
  17981. else
  17982. {
  17983. tempIndex = gun_index;
  17984. }
  17985. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17986. {
  17987. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17988. {
  17989. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17990. }
  17991. }// End of for CHAdeMO_QUANTITY
  17992. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17993. }
  17994. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17995. {
  17996. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17997. {
  17998. tempIndex = ((gun_index==2) ? 1: 0);
  17999. }
  18000. else
  18001. {
  18002. tempIndex = gun_index;
  18003. }
  18004. for (int index = 0; index < CCS_QUANTITY; index++)
  18005. {
  18006. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18007. {
  18008. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18009. }
  18010. }// End of for CCS_QUANTITY
  18011. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18012. }
  18013. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18014. {
  18015. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18016. {
  18017. tempIndex = ((gun_index==2) ? 1: 0);
  18018. }
  18019. else
  18020. {
  18021. tempIndex = gun_index;
  18022. }
  18023. for (int index = 0; index < GB_QUANTITY; index++)
  18024. {
  18025. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18026. {
  18027. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18028. }
  18029. }// End of for GB_QUANTITY
  18030. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18031. }
  18032. else if(gunType[gun_index] == GUN_TYPE_DO)
  18033. {
  18034. tempIndex = gun_index;
  18035. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18036. {
  18037. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18038. {
  18039. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18040. }
  18041. }
  18042. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18043. }
  18044. else
  18045. {
  18046. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18047. {
  18048. tempIndex = 2;
  18049. }
  18050. else
  18051. {
  18052. tempIndex = gun_index;
  18053. }
  18054. for (int index = 0; index < AC_QUANTITY; index++)
  18055. {
  18056. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18057. {
  18058. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  18059. }
  18060. }// End of for AC_QUANTITY
  18061. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18062. }
  18063. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18064. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  18065. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  18066. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18067. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  18068. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18069. }
  18070. //2.2===================================== Energy.Active.Import.Interval ==========================================
  18071. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  18072. {
  18073. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18074. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18075. {
  18076. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18077. {
  18078. tempIndex = ((gun_index==2) ? 1: 0);
  18079. }
  18080. else
  18081. {
  18082. tempIndex = gun_index;
  18083. }
  18084. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18085. {
  18086. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18087. {
  18088. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  18089. }
  18090. }// END OF CHAdeMO_QUANTITY
  18091. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18092. }
  18093. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18094. {
  18095. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18096. {
  18097. tempIndex = ((gun_index==2) ? 1: 0);
  18098. }
  18099. else
  18100. {
  18101. tempIndex = gun_index;
  18102. }
  18103. for (int index = 0; index < CCS_QUANTITY; index++)
  18104. {
  18105. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18106. {
  18107. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  18108. }
  18109. }// END OF CCS_QUANTITY
  18110. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18111. }
  18112. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18113. {
  18114. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18115. {
  18116. tempIndex = ((gun_index==2) ? 1: 0);
  18117. }
  18118. else
  18119. {
  18120. tempIndex = gun_index;
  18121. }
  18122. for (int index = 0; index < GB_QUANTITY; index++)
  18123. {
  18124. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18125. {
  18126. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  18127. }
  18128. }// END OF GB_QUANTITY
  18129. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18130. }
  18131. else if(gunType[gun_index] == GUN_TYPE_DO)
  18132. {
  18133. tempIndex = gun_index;
  18134. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18135. {
  18136. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18137. {
  18138. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  18139. }
  18140. }
  18141. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18142. }
  18143. else
  18144. {
  18145. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18146. {
  18147. tempIndex = 2;
  18148. }
  18149. else
  18150. {
  18151. tempIndex = gun_index;
  18152. }
  18153. for (int index = 0; index < AC_QUANTITY; index++)
  18154. {
  18155. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18156. {
  18157. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  18158. }
  18159. }// END OF AC_QUANTITY
  18160. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18161. }
  18162. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18163. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  18164. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  18165. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18166. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  18167. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  18168. }
  18169. //2.3====================================== Power.Active.Import =========================================
  18170. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  18171. {
  18172. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18173. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18174. {
  18175. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18176. {
  18177. tempIndex = ((gun_index==2) ? 1: 0);
  18178. }
  18179. else
  18180. {
  18181. tempIndex = gun_index;
  18182. }
  18183. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18184. {
  18185. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18186. {
  18187. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18188. }
  18189. } // End for CHAdeMO_QUANTITY
  18190. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18191. }
  18192. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18193. {
  18194. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18195. {
  18196. tempIndex = ((gun_index==2) ? 1: 0);
  18197. }
  18198. else
  18199. {
  18200. tempIndex = gun_index;
  18201. }
  18202. for (int index = 0; index < CCS_QUANTITY; index++)
  18203. {
  18204. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18205. {
  18206. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18207. }
  18208. } // END for CCS_QUANTITY
  18209. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18210. }
  18211. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18212. {
  18213. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18214. {
  18215. tempIndex = ((gun_index==2) ? 1: 0);
  18216. }
  18217. else
  18218. {
  18219. tempIndex = gun_index;
  18220. }
  18221. for (int index = 0; index < GB_QUANTITY; index++)
  18222. {
  18223. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18224. {
  18225. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18226. }
  18227. }// END for GB_QUANTITY
  18228. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18229. }
  18230. else if(gunType[gun_index] == GUN_TYPE_DO)
  18231. {
  18232. tempIndex = gun_index;
  18233. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18234. {
  18235. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18236. {
  18237. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18238. }
  18239. }
  18240. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18241. }
  18242. else
  18243. {
  18244. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18245. {
  18246. tempIndex = 2;
  18247. }
  18248. else
  18249. {
  18250. tempIndex = gun_index;
  18251. }
  18252. for (int index = 0; index < AC_QUANTITY; index++)
  18253. {
  18254. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18255. {
  18256. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18257. }
  18258. } // END for AC_QUANTITY
  18259. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18260. }
  18261. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18262. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  18263. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  18264. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18265. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  18266. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  18267. }
  18268. //2.4====================================== Voltage L1 ====================================================
  18269. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18270. {
  18271. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18272. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18273. {
  18274. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18275. {
  18276. tempIndex = ((gun_index==2) ? 1: 0);
  18277. }
  18278. else
  18279. {
  18280. tempIndex = gun_index;
  18281. }
  18282. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18283. {
  18284. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18285. {
  18286. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18287. }
  18288. } // END OF FOR CHAdeMO_QUANTITY
  18289. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18290. }
  18291. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18292. {
  18293. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18294. {
  18295. tempIndex = ((gun_index==2) ? 1: 0);
  18296. }
  18297. else
  18298. {
  18299. tempIndex = gun_index;
  18300. }
  18301. for (int index = 0; index < CCS_QUANTITY; index++)
  18302. {
  18303. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18304. {
  18305. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18306. }
  18307. } // END OF FOR CCS_QUANTITY
  18308. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18309. }
  18310. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18311. {
  18312. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18313. {
  18314. tempIndex = ((gun_index==2) ? 1: 0);
  18315. }
  18316. else
  18317. {
  18318. tempIndex = gun_index;
  18319. }
  18320. for (int index = 0; index < GB_QUANTITY; index++)
  18321. {
  18322. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18323. {
  18324. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18325. }
  18326. } // END OF FOR GB_QUANTITY
  18327. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18328. }
  18329. else if(gunType[gun_index] == GUN_TYPE_DO)
  18330. {
  18331. tempIndex = gun_index;
  18332. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18333. {
  18334. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18335. {
  18336. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18337. }
  18338. }
  18339. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18340. }
  18341. else
  18342. {
  18343. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18344. {
  18345. tempIndex = 2;
  18346. }
  18347. else
  18348. {
  18349. tempIndex = gun_index;
  18350. }
  18351. for (int index = 0; index < AC_QUANTITY; index++)
  18352. {
  18353. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18354. {
  18355. 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
  18356. }
  18357. } // END OF FOR AC_QUANTITY
  18358. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18359. }
  18360. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18361. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  18362. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  18363. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18364. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  18365. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18366. }
  18367. //2.5============================================== End SoC =========================================================
  18368. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18369. {
  18370. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18371. 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))
  18372. {
  18373. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18374. {
  18375. tempIndex = ((gun_index==2) ? 1: 0);
  18376. }
  18377. else
  18378. {
  18379. tempIndex = gun_index;
  18380. }
  18381. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18382. {
  18383. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18384. {
  18385. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18386. {
  18387. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  18388. }
  18389. }
  18390. }
  18391. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18392. {
  18393. for (int index = 0; index < CCS_QUANTITY; index++)
  18394. {
  18395. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18396. {
  18397. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  18398. }
  18399. }
  18400. }
  18401. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18402. {
  18403. for (int index = 0; index < GB_QUANTITY; index++)
  18404. {
  18405. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18406. {
  18407. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  18408. }
  18409. }
  18410. }
  18411. else if(gunType[gun_index] == GUN_TYPE_DO)
  18412. {
  18413. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18414. {
  18415. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18416. {
  18417. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  18418. }
  18419. }
  18420. }
  18421. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18422. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  18423. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18424. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  18425. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  18426. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18427. } // END FOR DC CASE
  18428. }
  18429. //2.6====================================== Current.Import L2 ==============================================
  18430. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18431. {
  18432. // AC 3 phase L2 current
  18433. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18434. {
  18435. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18436. {
  18437. tempIndex = 2;
  18438. }
  18439. else
  18440. {
  18441. tempIndex = gun_index;
  18442. }
  18443. for (int index = 0; index < AC_QUANTITY; index++)
  18444. {
  18445. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18446. {
  18447. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  18448. }
  18449. }// End of for AC_QUANTITY
  18450. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  18451. }
  18452. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18453. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  18454. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  18455. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  18456. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18457. }
  18458. //2.7====================================== Current.Import L3 ==============================================
  18459. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18460. {
  18461. // AC 3 phase L3 current
  18462. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18463. {
  18464. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18465. {
  18466. tempIndex = 2;
  18467. }
  18468. else
  18469. {
  18470. tempIndex = gun_index;
  18471. }
  18472. for (int index = 0; index < AC_QUANTITY; index++)
  18473. {
  18474. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18475. {
  18476. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  18477. }
  18478. }// End of for AC_QUANTITY
  18479. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  18480. }
  18481. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18482. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  18483. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  18484. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  18485. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18486. }
  18487. //2.9====================================== Voltage L2 ====================================================
  18488. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18489. {
  18490. // AC 3 phase L2 volatge
  18491. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18492. {
  18493. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18494. {
  18495. tempIndex = 2;
  18496. }
  18497. else
  18498. {
  18499. tempIndex = gun_index;
  18500. }
  18501. for (int index = 0; index < AC_QUANTITY; index++)
  18502. {
  18503. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18504. {
  18505. 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
  18506. }
  18507. } // END OF FOR AC_QUANTITY
  18508. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  18509. }
  18510. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18511. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  18512. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  18513. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  18514. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18515. }
  18516. //2.10====================================== Voltage L3 ====================================================
  18517. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18518. {
  18519. // AC 3 phase L3 volatge
  18520. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18521. {
  18522. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18523. {
  18524. tempIndex = 2;
  18525. }
  18526. else
  18527. {
  18528. tempIndex = gun_index;
  18529. }
  18530. for (int index = 0; index < AC_QUANTITY; index++)
  18531. {
  18532. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18533. {
  18534. 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
  18535. }
  18536. } // END OF FOR AC_QUANTITY
  18537. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  18538. }
  18539. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18540. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  18541. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  18542. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  18543. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18544. }
  18545. //====================== Start SoC ================================
  18546. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18547. {
  18548. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18549. 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))
  18550. {
  18551. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18552. {
  18553. tempIndex = ((gun_index==2) ? 1: 0);
  18554. }
  18555. else
  18556. {
  18557. tempIndex = gun_index;
  18558. }
  18559. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18560. {
  18561. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18562. {
  18563. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18564. {
  18565. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  18566. }
  18567. }
  18568. }
  18569. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18570. {
  18571. for (int index = 0; index < CCS_QUANTITY; index++)
  18572. {
  18573. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18574. {
  18575. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  18576. }
  18577. }
  18578. }
  18579. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18580. {
  18581. for (int index = 0; index < GB_QUANTITY; index++)
  18582. {
  18583. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18584. {
  18585. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  18586. }
  18587. }
  18588. }
  18589. else if(gunType[gun_index] == GUN_TYPE_DO)
  18590. {
  18591. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18592. {
  18593. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18594. {
  18595. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  18596. }
  18597. }
  18598. }
  18599. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18600. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  18601. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18602. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  18603. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  18604. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18605. } // END FOR DC CASE
  18606. }
  18607. //======================================== Message create ==============================================
  18608. json_object *StopTransaction = json_object_new_object();
  18609. json_object *transactionDatas = json_object_new_array();
  18610. json_object *sampledValues = json_object_new_array();
  18611. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  18612. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  18613. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  18614. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  18615. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  18616. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  18617. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  18618. {
  18619. json_object *transactionData = json_object_new_object();
  18620. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  18621. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  18622. {
  18623. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  18624. {
  18625. json_object *sampledValue = json_object_new_object();
  18626. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  18627. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  18628. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  18629. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  18630. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  18631. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  18632. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  18633. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  18634. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  18635. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  18636. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  18637. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  18638. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  18639. json_object_array_add(sampledValues, sampledValue);
  18640. }
  18641. }
  18642. json_object_object_add(transactionData, "sampledValue", sampledValues);
  18643. json_object_array_add(transactionDatas, transactionData);
  18644. }
  18645. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  18646. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  18647. ,MESSAGE_TYPE_CALL
  18648. ,guid
  18649. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  18650. json_object_put(StopTransaction);
  18651. // Check File "TempStopTransaction" Exist
  18652. if((access(TempStopTransaction,F_OK))!=-1)
  18653. {
  18654. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  18655. fclose(fopen(TempStopTransaction, "w"));
  18656. }
  18657. else
  18658. {
  18659. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  18660. FILE *log = fopen(TempStopTransaction, "w+");
  18661. if(log == NULL)
  18662. {
  18663. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  18664. return ;
  18665. }
  18666. else
  18667. {
  18668. fclose(log);
  18669. }
  18670. }
  18671. //Add TempStopTransaction | Update TempStopTransaction
  18672. // open file for writing
  18673. FILE *outfile;
  18674. outfile = fopen (TempStopTransaction, "a");
  18675. //DEBUG_INFO("data = %s\n", queuedata);
  18676. fputs(queuedata, outfile);
  18677. fputs("\n", outfile);
  18678. fclose (outfile);
  18679. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18680. OCPP_updatePeriodEnergy(gun_index);
  18681. }
  18682. void checkTempStopTransaction(int gun_index)
  18683. {
  18684. FILE *fptr1;
  18685. char ch;
  18686. char str[QUEUE_MESSAGE_LENGTH]={0};
  18687. char guid[37]={0};
  18688. char tempdata[65]={0};
  18689. char connectorStr[2]={0};
  18690. char TempStopTransaction[256];
  18691. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  18692. fptr1 = fopen(TempStopTransaction, "r");
  18693. //TempStopTransaction格式: 槍號,StopTransaction封包
  18694. if (!fptr1)
  18695. {
  18696. //printf(" File not found or unable to open the input file!!\n");
  18697. return ;
  18698. }
  18699. ch=fgetc(fptr1);
  18700. //printf(" Now the content of the file %s is : \n",fname);
  18701. rewind(fptr1);
  18702. if(ch!=EOF)
  18703. {
  18704. // copy all contents to the temporary file except the specific line
  18705. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18706. {
  18707. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18708. if(str[0]=='\0')
  18709. {
  18710. break;
  18711. }
  18712. //TempStopTransaction格式: 槍號,StopTransaction封包
  18713. strncpy(connectorStr, str, 1);
  18714. if(atoi(connectorStr) != (gun_index+1))
  18715. {
  18716. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18717. fclose(fptr1);
  18718. return ;
  18719. }
  18720. //random_uuid(guid);
  18721. strncpy(guid, str+6, 36); //copy guid
  18722. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18723. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18724. {
  18725. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18726. }
  18727. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18728. OCPP_insert_transaction_msg(NO, str);
  18729. memset(str,0,ARRAY_SIZE(str));
  18730. }
  18731. }
  18732. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18733. fclose(fptr1);
  18734. remove(TempStopTransaction); // remove the original file
  18735. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18736. }
  18737. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18738. {
  18739. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18740. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18741. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18742. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18743. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18744. }
  18745. int GetWebSocketPingInterval(void)
  18746. {
  18747. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18748. }
  18749. int GetServerSign(void)
  18750. {
  18751. return server_sign;
  18752. }
  18753. uint8_t GetOcppSecurityProfile()
  18754. {
  18755. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18756. }
  18757. void GetOcppChargerBoxId(uint8_t *data)
  18758. {
  18759. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18760. }
  18761. void GetOcppSecurityPassword(uint8_t *data)
  18762. {
  18763. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18764. }
  18765. void SetOcppVersion(uint8_t *version)
  18766. {
  18767. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18768. DEBUG_INFO("ocpp version: %s\n", version);
  18769. if(strstr((char*)version, "ocpp1.6") != NULL)
  18770. {
  18771. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18772. }
  18773. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18774. {
  18775. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18776. system("pkill OcppBackend");
  18777. }
  18778. }
  18779. void SetServerSign(int value)
  18780. {
  18781. server_sign = value;
  18782. }
  18783. int GetBootNotificationInterval(void)
  18784. {
  18785. return BootNotificationInterval;
  18786. }
  18787. int GetInternetConn(void)
  18788. {
  18789. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18790. }
  18791. int GetBackendConnectionTimeout(void)
  18792. {
  18793. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18794. }
  18795. int isConnectorInitMode(int gun_index)
  18796. {
  18797. int tempIndex = 0;
  18798. int result = TRUE;
  18799. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18800. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18801. {
  18802. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18803. {
  18804. tempIndex = ((gun_index==2) ? 1: 0);
  18805. }
  18806. else
  18807. {
  18808. tempIndex = gun_index;
  18809. }
  18810. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18811. {
  18812. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18813. {
  18814. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18815. } //end of the same index
  18816. }//end of for CHAdeMO_QUANTITY
  18817. }
  18818. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18819. {
  18820. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18821. {
  18822. tempIndex = ((gun_index==2) ? 1: 0);
  18823. }
  18824. else
  18825. {
  18826. tempIndex = gun_index;
  18827. }
  18828. for (int index = 0; index < CCS_QUANTITY; index++)
  18829. {
  18830. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18831. {
  18832. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18833. } //end of the same index
  18834. } // end of for CCS_QUANTITY
  18835. }
  18836. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18837. {
  18838. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18839. {
  18840. tempIndex = ((gun_index==2) ? 1: 0);
  18841. }
  18842. else
  18843. {
  18844. tempIndex = gun_index;
  18845. }
  18846. for (int index = 0; index < GB_QUANTITY; index++)
  18847. {
  18848. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18849. {
  18850. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18851. } //end of the same index
  18852. } // end of for GB_QUANTITY
  18853. }
  18854. else if(gunType[gun_index] == GUN_TYPE_DO)
  18855. {
  18856. tempIndex = gun_index;
  18857. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18858. {
  18859. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18860. {
  18861. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18862. } //end of the same index
  18863. }
  18864. }
  18865. else
  18866. {
  18867. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18868. {
  18869. tempIndex = 2;
  18870. }
  18871. else
  18872. {
  18873. tempIndex = gun_index;
  18874. }
  18875. for (int index = 0; index < AC_QUANTITY; index++)
  18876. {
  18877. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18878. {
  18879. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18880. }//end of the same index
  18881. }//end of for AC_QUANTITY
  18882. }
  18883. return result;
  18884. }
  18885. void refreshProcDogTimer()
  18886. {
  18887. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  18888. }
  18889. void InitialSystemValue(void)
  18890. {
  18891. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  18892. locallistVersion=0;
  18893. BootNotificationInterval = 0;
  18894. authorizeRetryTimes = 0;
  18895. GunStatusInterval = 10;
  18896. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18897. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18898. //Hear Beat
  18899. HeartBeatWithNOResponse = 0;
  18900. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18901. FirstHeartBeat = 0;
  18902. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18903. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18904. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18905. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18906. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18907. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18908. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18909. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18910. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18911. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18912. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18913. //Status && ConnectorPlugIn Setting
  18914. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18915. {
  18916. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18917. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18918. }
  18919. for (int index = 0; index < CCS_QUANTITY; index++)
  18920. {
  18921. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18922. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18923. }
  18924. for (int index = 0; index < GB_QUANTITY; index++)
  18925. {
  18926. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18927. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18928. }
  18929. for (int index = 0; index < AC_QUANTITY; index++)
  18930. {
  18931. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18932. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18933. }
  18934. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18935. {
  18936. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18937. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18938. }
  18939. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18940. {
  18941. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18942. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18943. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18944. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18945. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18946. }
  18947. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18948. refreshStartTimer(&clientTime.Heartbeat);
  18949. sleep(1);
  18950. }
  18951. void LWS_Send(char *str)
  18952. {
  18953. //=====================================================
  18954. // Check InternetConn 0: disconnected, 1: connected
  18955. //====================================================
  18956. if(GetOcppConnStatus() == 0)
  18957. {
  18958. DEBUG_INFO("offline now !!!\n");
  18959. return;
  18960. }
  18961. // Only disable isWebsocketSendable operation initiated by charger
  18962. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18963. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18964. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18965. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18966. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18967. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18968. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18969. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18970. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18971. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18972. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18973. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18974. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18975. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18976. {
  18977. isWebsocketSendable = 0;
  18978. }
  18979. pthread_mutex_lock(&lock_send);
  18980. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18981. sprintf((char *)SendBuffer, "%s", str);
  18982. SendBufLen = strlen(str);
  18983. pthread_mutex_unlock(&lock_send);
  18984. lws_callback_on_writable(wsi_client);
  18985. //lws_service(context, 0);
  18986. //sleep(1);
  18987. }
  18988. void LWS_SendNow(char *str)
  18989. {
  18990. //=====================================================
  18991. // Check InternetConn 0: disconnected, 1: connected
  18992. //====================================================
  18993. if(GetOcppConnStatus() == 0)
  18994. {
  18995. DEBUG_INFO("offline now !!!\n");
  18996. return;
  18997. }
  18998. // Only disable isWebsocketSendable operation initiated by charger
  18999. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19000. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19001. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19002. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  19003. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19004. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19005. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19006. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  19007. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19008. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  19009. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19010. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19011. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19012. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  19013. {
  19014. isWebsocketSendable = 0;
  19015. }
  19016. pthread_mutex_lock(&lock_send);
  19017. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19018. sprintf((char *)SendBuffer, "%s", str);
  19019. SendBufLen = strlen(str);
  19020. pthread_mutex_unlock(&lock_send);
  19021. lws_callback_on_writable(wsi_client);
  19022. lws_service(context, 0);
  19023. //sleep(1);
  19024. }