MessageHandler.c 933 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP_PH/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP_PH/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. struct OCPP16Data *ShmOCPP16DataPH;
  12. //ConfigurationMaxKeys
  13. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  14. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  15. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  16. //=================================
  17. // StatusNotification cycle
  18. //=================================
  19. static int server_cycle_Status = 120;
  20. //===============================
  21. // Configuration: unknown key
  22. //===============================
  23. static char unknownkey[10][36] = {0};
  24. static int UnknownKeynum = 0;
  25. //===============================
  26. // Gun Total Numbers
  27. //===============================
  28. static ParsingRatedCur modelnameInfo = {0};
  29. static int gunTotalNumber = 0;
  30. static uint8_t gunType[4] = {0};
  31. //===============================
  32. // Local List Version
  33. //===============================
  34. static int locallistVersion=0;
  35. static char idTagAuthorization[32] = {0};
  36. //===============================
  37. // OCPP sign variable
  38. //===============================
  39. static int server_sign = FALSE;
  40. int server_pending = FALSE;
  41. static int BootNotificationInterval = 0;
  42. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  43. //===============================
  44. // OCPP auth variable
  45. //===============================
  46. static int authorizeRetryTimes = 0; //number of Retry times
  47. //===============================
  48. // OCPP other variables
  49. //===============================
  50. static int HeartBeatWaitTime = 10;
  51. static int FirstHeartBeat = 0;
  52. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  53. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  54. static char CurrentChargingProfileScheduleStr[30] = {0};
  55. //========================================
  56. // OCPP status/previous related variables
  57. //========================================
  58. static int GunStatusInterval = 10;
  59. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  60. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  61. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  62. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  63. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  64. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  65. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  66. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  67. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  68. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  69. static int TransactionMessageAttemptsValue = 0;
  70. static int TransactionMessageRetryIntervalValue = 0;
  71. static int TempMeterValueInterval = 0;
  72. static struct OCPPAuthLocalElemet
  73. {
  74. int listVersionInt;
  75. char idTagstr[21];
  76. char parentIdTag[21];
  77. char expiryDate[36];
  78. char idTagstatus[16];
  79. }idTagQuery;
  80. //============================================
  81. // OCPP MeterValue request flag
  82. //============================================
  83. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  84. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  85. //=============================================
  86. // OCPP HeartBeat Response Not Receive Counts
  87. //============================================
  88. static int HeartBeatWithNOResponse = 0;
  89. extern sqlite3 *db;
  90. int TransactionMessageAttemptsGet(void);
  91. int TransactionMessageRetryIntervalGet(void);
  92. int GetOcppConnStatus(void);
  93. void SetOcppConnStatus(uint8_t status);
  94. int setKeyValue(char *key, char *value);
  95. void OCPP_get_TableAuthlocalAllData(void);
  96. void processUnkownKey(void);
  97. struct InterLock
  98. {
  99. unsigned char isGetDiagnosticGoing:1;
  100. unsigned char isUpdateFirmwareGoing:1;
  101. }interLock;
  102. struct ClientTime
  103. {
  104. struct timespec Heartbeat;
  105. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  106. struct timespec StartTransaction;
  107. struct timespec StopTransaction;
  108. struct timespec MeterValues[CONNECTOR_QUANTITY];
  109. struct timespec RemoteStartWait;
  110. struct timespec TcciQueryDeduct;
  111. }clientTime;
  112. typedef union
  113. {
  114. //Operations Initiated by Central System
  115. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  116. struct
  117. {
  118. //CsMsgValue[0]
  119. unsigned char StatusNotificationReq:1; //bit 0,
  120. unsigned char StatusNotificationConf:1; //bit 1,
  121. unsigned char TriggerMeterValue:1; //bit 2,
  122. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  123. unsigned char isOnCharging:1; //bit 4.
  124. unsigned char :3; //bit 5~7
  125. }bits[CONNECTOR_QUANTITY];
  126. }CpinitiateMsg;
  127. CpinitiateMsg cpinitateMsg;
  128. //GetConfiguration Array
  129. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  130. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  131. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  132. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  133. #if 0
  134. static char *ChargePointErrorCodeStr[] = {
  135. MACROSTR(ConnectorLockFailure),
  136. MACROSTR(EVCommunicationError),
  137. MACROSTR(GroundFailure),
  138. MACROSTR(HighTemperature),
  139. MACROSTR(InternalError),
  140. MACROSTR(LocalListConflict),
  141. MACROSTR(NoError),
  142. MACROSTR(OtherError),
  143. MACROSTR(OverCurrentFailure),
  144. MACROSTR(OverVoltage),
  145. MACROSTR(PowerMeterFailure),
  146. MACROSTR(PowerSwitchFailure),
  147. MACROSTR(ReaderFailure),
  148. MACROSTR(ResetFailure),
  149. MACROSTR(UnderVoltage),
  150. MACROSTR(WeakSignal)
  151. };
  152. #endif
  153. static char * ChargePointStatusStr[] = {
  154. MACROSTR(Available),
  155. MACROSTR(Preparing),
  156. MACROSTR(Charging),
  157. MACROSTR(SuspendedEVSE),
  158. MACROSTR(SuspendedEV),
  159. MACROSTR(Finishing),
  160. MACROSTR(Reserved),
  161. MACROSTR(Unavailable),
  162. MACROSTR(Faulted)
  163. };
  164. static char *RegistrationStatusStr[] = {
  165. MACROSTR(Accepted),
  166. MACROSTR(Pending),
  167. MACROSTR(Rejected)
  168. };
  169. static char *AvailabilityTypeStr[] = {
  170. MACROSTR(Inoperative),
  171. MACROSTR(Operative)
  172. };
  173. static char *AvailabilityStatusStr[] = {
  174. MACROSTR(Accepted),
  175. MACROSTR(Rejected),
  176. MACROSTR(Scheduled)
  177. };
  178. static char *ConfigurationStatusStr[] = {
  179. MACROSTR(Accepted),
  180. MACROSTR(Rejected),
  181. MACROSTR(RebootRequired),
  182. MACROSTR(NotSupported)
  183. };
  184. static char *ClearCacheStatusStr[] = {
  185. MACROSTR(Accepted),
  186. MACROSTR(Rejected)
  187. };
  188. static char *ChargingProfilePurposeTypeStr[] = {
  189. MACROSTR(ChargePointMaxProfile),
  190. MACROSTR(TxDefaultProfile),
  191. MACROSTR(TxProfile)
  192. };
  193. static char *ChargingProfileStatusStr[] = {
  194. MACROSTR(Accepted),
  195. MACROSTR(Rejected),
  196. MACROSTR(NotSupported)
  197. };
  198. static char *ClearChargingProfileStatusStr[] = {
  199. MACROSTR(Accepted),
  200. MACROSTR(Unknown)
  201. };
  202. static char *GetCompositeScheduleStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Rejected)
  205. };
  206. static char *UpdateTypeStr[] = {
  207. MACROSTR(Differential),
  208. MACROSTR(Full)
  209. };
  210. static char *UpdateStatusStr[] = {
  211. MACROSTR(Accepted),
  212. MACROSTR(Failed),
  213. MACROSTR(NotSupported),
  214. MACROSTR(VersionMismatch)
  215. };
  216. static char *RemoteStartStopStatusStr[] = {
  217. MACROSTR(Accepted),
  218. MACROSTR(Rejected)
  219. };
  220. static char *ReservationStatusStr[] = {
  221. MACROSTR(Accepted),
  222. MACROSTR(Faulted),
  223. MACROSTR(Occupied),
  224. MACROSTR(Rejected),
  225. MACROSTR(Unavailable)
  226. };
  227. static char *ResetTypeStr[] = {
  228. MACROSTR(Hard),
  229. MACROSTR(Soft)
  230. };
  231. static char *ResetStatusStr[] = {
  232. MACROSTR(Accepted),
  233. MACROSTR(Rejected)
  234. };
  235. static char * DiagnosticsStatusStr[] = {
  236. MACROSTR(Idle),
  237. MACROSTR(Uploaded),
  238. MACROSTR(UploadFailed),
  239. MACROSTR(Uploading)
  240. };
  241. static char * FirmwareStatusStr[] = {
  242. MACROSTR(Downloaded),
  243. MACROSTR(DownloadFailed),
  244. MACROSTR(Downloading),
  245. MACROSTR(Idle),
  246. MACROSTR(InstallationFailed),
  247. MACROSTR(Installing),
  248. MACROSTR(Installed)
  249. };
  250. static char * MessageTriggerStr[] = {
  251. MACROSTR(BootNotification),
  252. MACROSTR(DiagnosticsStatusNotification),
  253. MACROSTR(FirmwareStatusNotification),
  254. MACROSTR(Heartbeat),
  255. MACROSTR(MeterValues),
  256. MACROSTR(StatusNotification)
  257. };
  258. static char * TriggerMessageStatusStr[] = {
  259. MACROSTR(Accepted),
  260. MACROSTR(Rejected),
  261. MACROSTR(NotImplemented)
  262. };
  263. static char * UnlockStatusStr[] = {
  264. MACROSTR(Unlocked),
  265. MACROSTR(UnlockFailed),
  266. MACROSTR(NotSupported)
  267. };
  268. #if 0
  269. static char * StopTransactionReasonStr[] = {
  270. MACROSTR(EmergencyStop),
  271. MACROSTR(EVDisconnected),
  272. MACROSTR(HardReset),
  273. MACROSTR(Local),
  274. MACROSTR(Other),
  275. MACROSTR(PowerLoss),
  276. MACROSTR(Reboot),
  277. MACROSTR(Remote),
  278. MACROSTR(SoftReset),
  279. MACROSTR(UnlockCommand),
  280. MACROSTR(DeAuthorized)
  281. };
  282. #endif
  283. static char * CancelReservationStatusStr[] = {
  284. MACROSTR(Accepted),
  285. MACROSTR(Rejected)
  286. };
  287. static char * ReadingContextStr[] = {
  288. MACROSTR(Interruption.Begin),
  289. MACROSTR(Interruption.End),
  290. MACROSTR(Other),
  291. MACROSTR(Sample.Clock),
  292. MACROSTR(Sample.Periodic),
  293. MACROSTR(Transaction.Begin),
  294. MACROSTR(Transaction.End),
  295. MACROSTR(Trigger)
  296. };
  297. static char * ValueFormatStr[] = {
  298. MACROSTR(Raw),
  299. MACROSTR(SignedData)
  300. };
  301. static char * MeasurandStr[] = {
  302. MACROSTR(Current.Export),
  303. MACROSTR(Current.Import),
  304. MACROSTR(Current.Offered),
  305. MACROSTR(Energy.Active.Export.Register),
  306. MACROSTR(Energy.Active.Import.Register),
  307. MACROSTR(Energy.Reactive.Export.Register),
  308. MACROSTR(Energy.Reactive.Import.Register),
  309. MACROSTR(Energy.Active.Export.Interval),
  310. MACROSTR(Energy.Active.Import.Interval),
  311. MACROSTR(Energy.Reactive.Export.Interval),
  312. MACROSTR(Energy.Reactive.Import.Interval),
  313. MACROSTR(Frequency),
  314. MACROSTR(Power.Active.Export),
  315. MACROSTR(Power.Active.Import),
  316. MACROSTR(Power.Factor),
  317. MACROSTR(Power.Offered),
  318. MACROSTR(Power.Reactive.ExportMACROSTR),
  319. MACROSTR(Power.Reactive.Import),
  320. MACROSTR(RPM),
  321. MACROSTR(SoC),
  322. MACROSTR(Temperature),
  323. MACROSTR(Voltage)
  324. };
  325. static char * LocationStr[] = {
  326. MACROSTR(Body),
  327. MACROSTR(Cable),
  328. MACROSTR(EV),
  329. MACROSTR(Inlet),
  330. MACROSTR(Outlet)
  331. };
  332. static char * PhaseStr[] = {
  333. MACROSTR(L1),
  334. MACROSTR(L2),
  335. MACROSTR(L3),
  336. MACROSTR(N),
  337. MACROSTR(L1-N),
  338. MACROSTR(L2-N),
  339. MACROSTR(L3-N),
  340. MACROSTR(L1-L2),
  341. MACROSTR(L2-L3),
  342. MACROSTR(L3-L1)
  343. };
  344. static char * UnitOfMeasureStr[] = {
  345. MACROSTR(Wh),
  346. MACROSTR(kWh),
  347. MACROSTR(varh),
  348. MACROSTR(kvarh),
  349. MACROSTR(W),
  350. MACROSTR(kW),
  351. MACROSTR(VA),
  352. MACROSTR(kVA),
  353. MACROSTR(var),
  354. MACROSTR(kvar),
  355. MACROSTR(A),
  356. MACROSTR(V),
  357. MACROSTR(Celsius),
  358. MACROSTR(Fahrenheit),
  359. MACROSTR(K),
  360. MACROSTR(Percent)
  361. };
  362. //=========================================
  363. // Save configuration
  364. //=========================================
  365. int runShellCmd(const char*cmd)
  366. {
  367. int result = FAIL;
  368. char buf[256];
  369. FILE *fp;
  370. fp = popen(cmd, "r");
  371. if(fp != NULL)
  372. {
  373. while(fgets(buf, sizeof(buf), fp) != NULL)
  374. {
  375. DEBUG_INFO("%s\n", buf);
  376. }
  377. result = PASS;
  378. }
  379. pclose(fp);
  380. return result;
  381. }
  382. int StoreUsrConfigData(struct SysConfigData *UsrData)
  383. {
  384. int result = PASS;
  385. int fd,wrd;
  386. unsigned int i,Chk;
  387. unsigned char *ptr, *BufTmp;
  388. int MtdBlockSize = 0x300000;
  389. Chk=0;
  390. ptr=(unsigned char *)UsrData;
  391. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  392. {
  393. memset(BufTmp,0,MtdBlockSize);
  394. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  395. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  396. Chk+=*(BufTmp+i);
  397. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  398. // Output configuration to file.
  399. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  400. if (fd < 0)
  401. {
  402. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  403. free(BufTmp);
  404. return 0;
  405. }
  406. wrd=write(fd, BufTmp, MtdBlockSize);
  407. close(fd);
  408. if(wrd<MtdBlockSize)
  409. {
  410. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  411. free(BufTmp);
  412. return 0;
  413. }
  414. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  415. DEBUG_INFO("Erase /dev/mtd10.\n");
  416. runShellCmd("flash_erase /dev/mtd10 0 0");
  417. DEBUG_INFO("Write /dev/mtd10.\n");
  418. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  419. DEBUG_INFO("Erase /dev/mtd11.\n");
  420. runShellCmd("flash_erase /dev/mtd11 0 0");
  421. DEBUG_INFO("Write /dev/mtd11.\n");
  422. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  423. system("rm -f /mnt/EvseConfig.bin");
  424. DEBUG_INFO("EvseConfig write to flash OK\n");
  425. }
  426. else
  427. {
  428. DEBUG_ERROR("alloc BlockSize NG\r\n");
  429. result = FAIL;
  430. }
  431. if(BufTmp!=NULL)
  432. free(BufTmp);
  433. return result;
  434. }
  435. //=========================================
  436. // Sqlite3 related function
  437. //=========================================
  438. static int selectSqlCount = 0;
  439. static int callback(void *data, int argc, char **argv, char **azColName){
  440. int i;
  441. //printf("%s: ", (const char*)data);
  442. selectSqlCount = argc;
  443. for(i = 0; i<argc; i++){
  444. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  445. }
  446. //printf("\n");
  447. return 0;
  448. }
  449. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  450. //int i;
  451. //printf("%s:\n", (const char*)data);
  452. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  453. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  454. return 0;
  455. }
  456. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  457. //printf("%s:\n", (const char*)data);
  458. //idTag
  459. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  460. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  461. //parentIdTag
  462. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  463. //expir_date
  464. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  465. //status
  466. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  467. //version
  468. if(columenCount > 5)
  469. idTagQuery.listVersionInt = atoi(columnValue[5]);
  470. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  471. return 0;
  472. }
  473. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  474. {
  475. // localversion = argv[5] ? atoi(argv[5]) : 0;
  476. // printf("localversion=%d\n", localversion);
  477. return 0;
  478. }
  479. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  480. {
  481. for (int i = 0; i < n_columns; i++)
  482. {
  483. DEBUG_INFO("%s\t", col_values[i]);
  484. }
  485. DEBUG_INFO("\n");
  486. return 0;
  487. }
  488. int OCPP_cleanLocalCache()
  489. {
  490. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  491. char *errMsg = 0;
  492. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  493. if (SQLITE_OK != rc)
  494. {
  495. DEBUG_INFO("SQL error: %s\n",errMsg);
  496. return FALSE;
  497. }
  498. return TRUE;
  499. }
  500. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  501. {
  502. int isSuccess = TRUE;
  503. int ret = 0;
  504. //const char* data = "Callback function called";
  505. char sql[300];
  506. char zErrMsg[200];
  507. memset(sql, 0, 300);
  508. memset(zErrMsg, 0, 200);
  509. 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);
  510. //* Execute SQL statement */
  511. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  512. if( ret != SQLITE_OK )
  513. {
  514. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  515. isSuccess = FALSE;
  516. }
  517. return isSuccess;
  518. }
  519. void OCPP_getIdTagFromLocalCache(char idTag[])
  520. {
  521. int rc = 0;
  522. char sql[100];
  523. char zErrMsg[100];
  524. memset(sql, 0, 100);
  525. memset(zErrMsg, 0, 100);
  526. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  527. memset(&idTagQuery, 0, sizeof(idTagQuery));
  528. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  529. /* Execute SQL statement */
  530. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  531. if( rc != SQLITE_OK )
  532. {
  533. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  534. }
  535. }
  536. void OCPP_getListVerion()
  537. {
  538. int rc = 0;
  539. // const char* data = "Callback function called";
  540. char sql[100];
  541. char zErrMsg[100];
  542. memset(sql, 0, 100);
  543. memset(zErrMsg, 0, 100);
  544. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  545. /* Execute SQL statement */
  546. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  547. if( rc != SQLITE_OK )
  548. {
  549. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  550. }
  551. }
  552. void OCPP_get_TableAuthlocalAllData(void)
  553. {
  554. int rc = 0;
  555. char sql[100];
  556. char zErrMsg[100];
  557. memset(sql, 0, 100);
  558. memset(zErrMsg, 0, 100);
  559. sprintf(sql,"select * from ocpp_auth_local ");
  560. /* Execute SQL statement */
  561. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  562. if( rc != SQLITE_OK )
  563. {
  564. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  565. }
  566. //return ver;
  567. }
  568. int OCPP_cleanLocalList()
  569. {
  570. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  571. char *errMsg = 0;
  572. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  573. if (SQLITE_OK != rc)
  574. {
  575. DEBUG_INFO("%s\n",errMsg);
  576. return FALSE;
  577. }
  578. return TRUE;
  579. }
  580. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  581. {
  582. int isSuccess = FALSE;
  583. int ret = 0;
  584. //const char* data = "Callback function called";
  585. char sql[300];
  586. char zErrMsg[200];
  587. memset(sql, 0, 300);
  588. memset(zErrMsg, 0, 200);
  589. 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);
  590. //* Execute SQL statement */
  591. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  592. if( ret != SQLITE_OK )
  593. {
  594. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  595. return isSuccess;
  596. }
  597. memset(sql, 0, 300);
  598. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  599. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  600. if( ret != SQLITE_OK )
  601. {
  602. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  603. return isSuccess;
  604. }
  605. isSuccess = TRUE;
  606. return isSuccess;
  607. }
  608. void OCPP_getIdTagFromLocalList(char idTag[])
  609. {
  610. int rc = 0;
  611. // const char* data = "Callback function called";
  612. char sql[100];
  613. char zErrMsg[100];
  614. memset(sql, 0, 100);
  615. memset(zErrMsg, 0, 100);
  616. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  617. memset(&idTagQuery, 0, sizeof(idTagQuery));
  618. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  619. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  620. /* Execute SQL statement */
  621. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  622. if( rc != SQLITE_OK )
  623. {
  624. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  625. }
  626. //return ver;
  627. }
  628. void OCPP_deleteIdTagFromLocalList(char idTag[])
  629. {
  630. //int ver = 0;
  631. //int isSuccess = FALSE;
  632. int rc = 0;
  633. char sql[100];
  634. char zErrMsg[100];
  635. memset(sql, 0, 100);
  636. memset(zErrMsg, 0, 100);
  637. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  638. //* Execute SQL statement */
  639. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  640. if( rc != SQLITE_OK )
  641. {
  642. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  643. }
  644. }
  645. int getCurrentYear()
  646. {
  647. int result = 0;
  648. time_t CurrentTime;
  649. struct tm *tm;
  650. CurrentTime = time(NULL);
  651. tm=localtime(&CurrentTime);
  652. result = (tm->tm_year + 1900);
  653. return result;
  654. }
  655. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  656. {
  657. int result = PASS;
  658. char* errMsg = NULL;
  659. char sqlStr[8192];
  660. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  661. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  662. {
  663. result = FAIL;
  664. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  665. }
  666. 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));
  667. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  668. {
  669. result = FAIL;
  670. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  671. }
  672. return result;
  673. }
  674. 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)
  675. {
  676. int result = PASS;
  677. char* errMsg = NULL;
  678. char sqlStr[8192];
  679. 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');",
  680. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  681. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  682. {
  683. result = FAIL;
  684. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  685. }
  686. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  687. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  688. {
  689. result = FAIL;
  690. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  691. }
  692. return result;
  693. }
  694. int OCPP_update_deduct_info(int txId, char *creditNo)
  695. {
  696. int result = PASS;
  697. char* errMsg = NULL;
  698. char sqlStr[8192];
  699. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  700. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  701. {
  702. result = FAIL;
  703. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  704. }
  705. return result;
  706. }
  707. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  708. {
  709. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  710. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  711. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s,\\\"approvalNo\\\":\\\"%s\\\"}",
  712. atoi(columnValue[1]),
  713. columnValue[2],
  714. atoi(columnValue[3])==1?"true":"false",
  715. atoi(columnValue[4])==1?"true":"false",
  716. columnValue[5],
  717. columnValue[9]);
  718. ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
  719. return 0;
  720. }
  721. void OCPP_query_deduct_info()
  722. {
  723. int rc = 0;
  724. char sql[100];
  725. char zErrMsg[100];
  726. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  727. /* Execute SQL statement */
  728. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  729. if( rc != SQLITE_OK )
  730. {
  731. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  732. }
  733. }
  734. void reportReaderStatus(int gun_index)
  735. {
  736. struct timeval tmnow;
  737. struct tm *tm;
  738. char buf[28];//, usec_buf[6];
  739. gettimeofday(&tmnow, NULL);
  740. time_t t;
  741. t = time(NULL);
  742. /*UTC time and date*/
  743. tm = gmtime(&t);
  744. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  745. #if 0 // remove temporally
  746. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  747. strcat(buf,".");
  748. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  749. strcat(buf,usec_buf);
  750. #endif
  751. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  752. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"%s","ID_ReaderStatus");
  753. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, "{\\\"connectorId\\\":%d,\\\"readerStatus\\\":%d,\\\"timestamp\\\":\\\"%s\\\",\\\"SerialNo\\\":\\\"%s\\\",\\\"creditNo\\\":\\\"%s\\\",\\\"VEMData\\\":\\\"%s\\\"}",
  754. (gun_index+1),
  755. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].readerStatus,
  756. buf,
  757. ShmOCPP16DataPH->TcciCustomData.SerialNo[gun_index],
  758. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].creditNo,
  759. ShmOCPP16Data->TcciCustomData.VEMData[gun_index]);
  760. ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
  761. }
  762. //==========================================
  763. // Check time passed since today
  764. //==========================================
  765. long long DiffTimebWithNow(struct timeb ST)
  766. {
  767. //return milli-second
  768. struct timeb ET;
  769. long long StartTime,StopTime;
  770. ftime(&ET);
  771. StartTime=(long long)ST.time;
  772. StopTime=(long long)ET.time;
  773. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  774. }
  775. int getTimePassSinceToday(uint8_t gun_index)
  776. {
  777. int result = -1;
  778. static time_t lastTime[4];
  779. time_t t;
  780. struct tm *tmStartToday;
  781. struct timeb tbStartToday;
  782. t=time(NULL);
  783. if(difftime(t, lastTime[gun_index])>0)
  784. {
  785. tmStartToday=localtime(&t);
  786. tmStartToday->tm_hour = 0;
  787. tmStartToday->tm_min = 0;
  788. tmStartToday->tm_sec = 0;
  789. tbStartToday.time = mktime(tmStartToday);
  790. tbStartToday.millitm = 0;
  791. result = DiffTimebWithNow(tbStartToday)/1000;
  792. lastTime[gun_index] = t;
  793. }
  794. return result;
  795. }
  796. void getNowDatetime(uint8_t *data)
  797. {
  798. time_t t = time(NULL);
  799. struct tm tm = *localtime(&t);
  800. 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);
  801. }
  802. int syncDateTimeRTC(uint8_t *data)
  803. {
  804. struct ParsingResult
  805. {
  806. int result;
  807. int scanedElement;
  808. int year;
  809. int month;
  810. int mday;
  811. int hour;
  812. int min;
  813. int sec;
  814. int tz_hour;
  815. int tz_min;
  816. float minSec;
  817. }result;
  818. struct tm tmOrg;
  819. struct tm *tmTarget;
  820. struct timeb tbTarget;
  821. char buf[128];
  822. memset(&result, 0x00, sizeof(struct ParsingResult));
  823. result.result = PASS;
  824. if(strstr((char*)data, ".") != NULL)
  825. {
  826. // Original data with mini second
  827. if(strstr((char*)data, "Z") != NULL)
  828. {
  829. // Original data with Z
  830. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  831. &result.year,
  832. &result.month,
  833. &result.mday,
  834. &result.hour,
  835. &result.min,
  836. &result.sec,
  837. &result.minSec);
  838. }
  839. else
  840. {
  841. // Original data without Z
  842. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  843. &result.year,
  844. &result.month,
  845. &result.mday,
  846. &result.hour,
  847. &result.min,
  848. &result.sec,
  849. &result.minSec,
  850. &result.tz_hour,
  851. &result.tz_min);
  852. }
  853. }
  854. else
  855. {
  856. // Original data without mini second
  857. if(strstr((char*)data, "Z") != NULL)
  858. {
  859. // Original data with Z
  860. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  861. &result.year,
  862. &result.month,
  863. &result.mday,
  864. &result.hour,
  865. &result.min,
  866. &result.sec);
  867. }
  868. else
  869. {
  870. // Original data without Z
  871. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  872. &result.year,
  873. &result.month,
  874. &result.mday,
  875. &result.hour,
  876. &result.min,
  877. &result.sec,
  878. &result.tz_hour,
  879. &result.tz_min);
  880. }
  881. }
  882. tmOrg.tm_year = result.year - 1900;
  883. tmOrg.tm_mon = result.month - 1;
  884. tmOrg.tm_mday = result.mday;
  885. tmOrg.tm_hour = result.hour;
  886. tmOrg.tm_min = result.min;
  887. tmOrg.tm_sec = result.sec;
  888. tmOrg.tm_gmtoff = 0;
  889. tbTarget.time = mktime(&tmOrg);
  890. tbTarget.timezone = 0;
  891. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  892. tmTarget = gmtime(&tbTarget.time);
  893. 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);
  894. //DEBUG_INFO(" org date time: %s\n", data);
  895. //DEBUG_INFO("parse date time: %s\n", buf);
  896. system(buf);
  897. system("/sbin/hwclock -w --systohc");
  898. if(result.scanedElement < 6)
  899. result.result = FAIL;
  900. return result.result;
  901. }
  902. //==========================================
  903. // GetCompositeSchedule logic related function
  904. //==========================================
  905. int DiffTimebSec(struct timeb ST, struct timeb ET)
  906. {
  907. //return milli-second
  908. unsigned int StartTime,StopTime;
  909. StartTime=(unsigned int)ST.time;
  910. StopTime=(unsigned int)ET.time;
  911. return (StopTime-StartTime);
  912. }
  913. int DiffTimebWithNowSec(struct timeb ST)
  914. {
  915. //return milli-second
  916. struct timeb ET;
  917. unsigned int StartTime,StopTime;
  918. ftime(&ET);
  919. StartTime=(unsigned int)ST.time;
  920. StopTime=(unsigned int)ET.time;
  921. return (StopTime-StartTime);
  922. }
  923. int getStartStop(uint8_t *start, uint8_t *stop)
  924. {
  925. struct ParsingResult
  926. {
  927. int result;
  928. int scanedElement;
  929. int year;
  930. int month;
  931. int mday;
  932. int hour;
  933. int min;
  934. int sec;
  935. int tz_hour;
  936. int tz_min;
  937. float minSec;
  938. };
  939. struct ParsingResult parseStart;
  940. struct ParsingResult parseStop;
  941. int result = -1;
  942. struct tm tmStart;
  943. struct timeb tbStart;
  944. struct tm tmStop;
  945. struct timeb tbStop;
  946. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  947. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  948. // Scan start & stop date time
  949. if(strstr((char*)start, ".") != NULL)
  950. {
  951. // Original data with mini second
  952. if(strstr((char*)start, "Z") != NULL)
  953. {
  954. // Original data with Z
  955. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  956. &parseStart.year,
  957. &parseStart.month,
  958. &parseStart.mday,
  959. &parseStart.hour,
  960. &parseStart.min,
  961. &parseStart.sec,
  962. &parseStart.minSec);
  963. }
  964. else
  965. {
  966. // Original data without Z
  967. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  968. &parseStart.year,
  969. &parseStart.month,
  970. &parseStart.mday,
  971. &parseStart.hour,
  972. &parseStart.min,
  973. &parseStart.sec,
  974. &parseStart.minSec,
  975. &parseStart.tz_hour,
  976. &parseStart.tz_min);
  977. }
  978. }
  979. else
  980. {
  981. // Original data without mini second
  982. if(strstr((char*)start, "Z") != NULL)
  983. {
  984. // Original data with Z
  985. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  986. &parseStart.year,
  987. &parseStart.month,
  988. &parseStart.mday,
  989. &parseStart.hour,
  990. &parseStart.min,
  991. &parseStart.sec);
  992. }
  993. else
  994. {
  995. // Original data without Z
  996. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  997. &parseStart.year,
  998. &parseStart.month,
  999. &parseStart.mday,
  1000. &parseStart.hour,
  1001. &parseStart.min,
  1002. &parseStart.sec,
  1003. &parseStart.tz_hour,
  1004. &parseStart.tz_min);
  1005. }
  1006. }
  1007. if(strstr((char*)stop, ".") != NULL)
  1008. {
  1009. // Original data with mini second
  1010. if(strstr((char*)stop, "Z") != NULL)
  1011. {
  1012. // Original data with Z
  1013. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1014. &parseStop.year,
  1015. &parseStop.month,
  1016. &parseStop.mday,
  1017. &parseStop.hour,
  1018. &parseStop.min,
  1019. &parseStop.sec,
  1020. &parseStop.minSec);
  1021. }
  1022. else
  1023. {
  1024. // Original data without Z
  1025. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1026. &parseStop.year,
  1027. &parseStop.month,
  1028. &parseStop.mday,
  1029. &parseStop.hour,
  1030. &parseStop.min,
  1031. &parseStop.sec,
  1032. &parseStop.minSec,
  1033. &parseStop.tz_hour,
  1034. &parseStop.tz_min);
  1035. }
  1036. }
  1037. else
  1038. {
  1039. // Original data without mini second
  1040. if(strstr((char*)stop, "Z") != NULL)
  1041. {
  1042. // Original data with Z
  1043. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1044. &parseStop.year,
  1045. &parseStop.month,
  1046. &parseStop.mday,
  1047. &parseStop.hour,
  1048. &parseStop.min,
  1049. &parseStop.sec);
  1050. }
  1051. else
  1052. {
  1053. // Original data without Z
  1054. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1055. &parseStop.year,
  1056. &parseStop.month,
  1057. &parseStop.mday,
  1058. &parseStop.hour,
  1059. &parseStop.min,
  1060. &parseStop.sec,
  1061. &parseStop.tz_hour,
  1062. &parseStop.tz_min);
  1063. }
  1064. }
  1065. // Calculate date time difference
  1066. if((parseStart.scanedElement >=6) &&
  1067. (parseStop.scanedElement >=6))
  1068. {
  1069. //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);
  1070. //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);
  1071. tmStart.tm_year = parseStart.year - 1900;
  1072. tmStart.tm_mon = parseStart.month - 1;
  1073. tmStart.tm_mday = parseStart.mday;
  1074. tmStart.tm_hour = parseStart.hour;
  1075. tmStart.tm_min = parseStart.min;
  1076. tmStart.tm_sec = parseStart.sec;
  1077. tmStart.tm_gmtoff = 0;
  1078. tbStart.time = mktime(&tmStart);
  1079. tbStart.timezone = 0;
  1080. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1081. tmStop.tm_year = parseStop.year - 1900;
  1082. tmStop.tm_mon = parseStop.month - 1;
  1083. tmStop.tm_mday = parseStop.mday;
  1084. tmStop.tm_hour = parseStop.hour;
  1085. tmStop.tm_min = parseStop.min;
  1086. tmStop.tm_sec = parseStop.sec;
  1087. tmStop.tm_gmtoff = 0;
  1088. tbStop.time = mktime(&tmStop);
  1089. tbStop.timezone = 0;
  1090. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1091. result = DiffTimebSec(tbStart, tbStop);
  1092. //DEBUG_INFO("getStartStop(): %d\n", result);
  1093. }
  1094. else
  1095. {
  1096. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1097. }
  1098. return result;
  1099. }
  1100. int isOvertNow(uint8_t *start)
  1101. {
  1102. int result = NO;
  1103. struct ParsingResult
  1104. {
  1105. int result;
  1106. int scanedElement;
  1107. int year;
  1108. int month;
  1109. int mday;
  1110. int hour;
  1111. int min;
  1112. int sec;
  1113. int tz_hour;
  1114. int tz_min;
  1115. float minSec;
  1116. }parsingResult;
  1117. struct tm tmStart;
  1118. struct timeb tbStart;
  1119. if(strstr((char*)start, ".") != NULL)
  1120. {
  1121. // Original data with mini second
  1122. if(strstr((char*)start, "Z") != NULL)
  1123. {
  1124. // Original data with Z
  1125. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1126. &parsingResult.year,
  1127. &parsingResult.month,
  1128. &parsingResult.mday,
  1129. &parsingResult.hour,
  1130. &parsingResult.min,
  1131. &parsingResult.sec,
  1132. &parsingResult.minSec);
  1133. }
  1134. else
  1135. {
  1136. // Original data without Z
  1137. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1138. &parsingResult.year,
  1139. &parsingResult.month,
  1140. &parsingResult.mday,
  1141. &parsingResult.hour,
  1142. &parsingResult.min,
  1143. &parsingResult.sec,
  1144. &parsingResult.minSec,
  1145. &parsingResult.tz_hour,
  1146. &parsingResult.tz_min);
  1147. }
  1148. }
  1149. else
  1150. {
  1151. // Original data without mini second
  1152. if(strstr((char*)start, "Z") != NULL)
  1153. {
  1154. // Original data with Z
  1155. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1156. &parsingResult.year,
  1157. &parsingResult.month,
  1158. &parsingResult.mday,
  1159. &parsingResult.hour,
  1160. &parsingResult.min,
  1161. &parsingResult.sec);
  1162. }
  1163. else
  1164. {
  1165. // Original data without Z
  1166. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1167. &parsingResult.year,
  1168. &parsingResult.month,
  1169. &parsingResult.mday,
  1170. &parsingResult.hour,
  1171. &parsingResult.min,
  1172. &parsingResult.sec,
  1173. &parsingResult.tz_hour,
  1174. &parsingResult.tz_min);
  1175. }
  1176. }
  1177. if(parsingResult.scanedElement >= 6)
  1178. {
  1179. tmStart.tm_year = parsingResult.year - 1900;
  1180. tmStart.tm_mon = parsingResult.month - 1;
  1181. tmStart.tm_mday = parsingResult.mday;
  1182. tmStart.tm_hour = parsingResult.hour;
  1183. tmStart.tm_min = parsingResult.min;
  1184. tmStart.tm_sec = parsingResult.sec;
  1185. tmStart.tm_gmtoff = 0;
  1186. tbStart.time = mktime(&tmStart);
  1187. tbStart.timezone = 0;
  1188. tbStart.millitm = 0;
  1189. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1190. if(DiffTimebWithNowSec(tbStart) <= 0)
  1191. result = NO;
  1192. else
  1193. result = YES;
  1194. }
  1195. else
  1196. {
  1197. DEBUG_WARN("Start date parsing error.\n");
  1198. }
  1199. return result;
  1200. }
  1201. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1202. {
  1203. struct ParsingResult
  1204. {
  1205. int result;
  1206. int scanedElement;
  1207. int year;
  1208. int month;
  1209. int mday;
  1210. int hour;
  1211. int min;
  1212. int sec;
  1213. int tz_hour;
  1214. int tz_min;
  1215. float minSec;
  1216. };
  1217. struct ParsingResult parseStart;
  1218. struct ParsingResult parseStop;
  1219. int result = -1;
  1220. struct tm tmStart;
  1221. struct timeb tbStart;
  1222. struct tm tmStop;
  1223. struct timeb tbStop;
  1224. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1225. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1226. // Scan start & stop date time
  1227. if(strstr((char*)start, ".") != NULL)
  1228. {
  1229. // Original data with mini second
  1230. if(strstr((char*)start, "Z") != NULL)
  1231. {
  1232. // Original data with Z
  1233. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1234. &parseStart.year,
  1235. &parseStart.month,
  1236. &parseStart.mday,
  1237. &parseStart.hour,
  1238. &parseStart.min,
  1239. &parseStart.sec,
  1240. &parseStart.minSec);
  1241. }
  1242. else
  1243. {
  1244. // Original data without Z
  1245. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1246. &parseStart.year,
  1247. &parseStart.month,
  1248. &parseStart.mday,
  1249. &parseStart.hour,
  1250. &parseStart.min,
  1251. &parseStart.sec,
  1252. &parseStart.minSec,
  1253. &parseStart.tz_hour,
  1254. &parseStart.tz_min);
  1255. }
  1256. }
  1257. else
  1258. {
  1259. // Original data without mini second
  1260. if(strstr((char*)start, "Z") != NULL)
  1261. {
  1262. // Original data with Z
  1263. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1264. &parseStart.year,
  1265. &parseStart.month,
  1266. &parseStart.mday,
  1267. &parseStart.hour,
  1268. &parseStart.min,
  1269. &parseStart.sec);
  1270. }
  1271. else
  1272. {
  1273. // Original data without Z
  1274. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1275. &parseStart.year,
  1276. &parseStart.month,
  1277. &parseStart.mday,
  1278. &parseStart.hour,
  1279. &parseStart.min,
  1280. &parseStart.sec,
  1281. &parseStart.tz_hour,
  1282. &parseStart.tz_min);
  1283. }
  1284. }
  1285. if(strstr((char*)stop, ".") != NULL)
  1286. {
  1287. // Original data with mini second
  1288. if(strstr((char*)stop, "Z") != NULL)
  1289. {
  1290. // Original data with Z
  1291. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1292. &parseStop.year,
  1293. &parseStop.month,
  1294. &parseStop.mday,
  1295. &parseStop.hour,
  1296. &parseStop.min,
  1297. &parseStop.sec,
  1298. &parseStop.minSec);
  1299. }
  1300. else
  1301. {
  1302. // Original data without Z
  1303. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1304. &parseStop.year,
  1305. &parseStop.month,
  1306. &parseStop.mday,
  1307. &parseStop.hour,
  1308. &parseStop.min,
  1309. &parseStop.sec,
  1310. &parseStop.minSec,
  1311. &parseStop.tz_hour,
  1312. &parseStop.tz_min);
  1313. }
  1314. }
  1315. else
  1316. {
  1317. // Original data without mini second
  1318. if(strstr((char*)stop, "Z") != NULL)
  1319. {
  1320. // Original data with Z
  1321. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1322. &parseStop.year,
  1323. &parseStop.month,
  1324. &parseStop.mday,
  1325. &parseStop.hour,
  1326. &parseStop.min,
  1327. &parseStop.sec);
  1328. }
  1329. else
  1330. {
  1331. // Original data without Z
  1332. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1333. &parseStop.year,
  1334. &parseStop.month,
  1335. &parseStop.mday,
  1336. &parseStop.hour,
  1337. &parseStop.min,
  1338. &parseStop.sec,
  1339. &parseStop.tz_hour,
  1340. &parseStop.tz_min);
  1341. }
  1342. }
  1343. // Calculate date time difference
  1344. if((parseStart.scanedElement >=6) &&
  1345. (parseStop.scanedElement >=6))
  1346. {
  1347. //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);
  1348. //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);
  1349. tmStart.tm_year = parseStart.year - 1900;
  1350. tmStart.tm_mon = parseStart.month - 1;
  1351. tmStart.tm_mday = parseStart.mday;
  1352. tmStart.tm_hour = parseStart.hour;
  1353. tmStart.tm_min = parseStart.min;
  1354. tmStart.tm_sec = parseStart.sec;
  1355. tmStart.tm_gmtoff = 0;
  1356. tbStart.time = mktime(&tmStart);
  1357. tbStart.timezone = 0;
  1358. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1359. tmStop.tm_year = parseStop.year - 1900;
  1360. tmStop.tm_mon = parseStop.month - 1;
  1361. tmStop.tm_mday = parseStop.mday;
  1362. tmStop.tm_hour = parseStop.hour;
  1363. tmStop.tm_min = parseStop.min;
  1364. tmStop.tm_sec = parseStop.sec;
  1365. tmStop.tm_gmtoff = 0;
  1366. tbStop.time = mktime(&tmStop);
  1367. tbStop.timezone = 0;
  1368. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1369. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1370. //DEBUG_INFO("getStartStop(): %d\n", result);
  1371. }
  1372. else
  1373. {
  1374. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1375. }
  1376. return result;
  1377. }
  1378. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1379. {
  1380. FILE *fp;
  1381. char profileFileName[128];
  1382. char *line = NULL;
  1383. size_t len = 0;
  1384. time_t CurrentTime;
  1385. struct tm *tmComposite;
  1386. struct StructChargingProfile maxProfile;
  1387. struct StructChargingProfile compositeProfile;
  1388. uint8_t limitMax=0;
  1389. int compositePeriodIdx = 0;
  1390. CurrentTime = time(NULL);
  1391. tmComposite=localtime(&CurrentTime);
  1392. 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);
  1393. if(isUnitA)
  1394. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1395. else
  1396. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1397. compositeProfile.ChargingSchedule.Duration = durationReq;
  1398. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1399. {
  1400. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1401. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1402. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1403. }
  1404. compositeProfile.ChargingProfileId = 0;
  1405. compositeProfile.StackLevel = 99 ;
  1406. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1407. maxProfile.ChargingProfileId = -1;
  1408. maxProfile.ChargingSchedule.Duration = -1;
  1409. system("rm -f /tmp/*.json");
  1410. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1411. // Search max profile
  1412. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1413. if((access(profileFileName, F_OK))!=-1)
  1414. {
  1415. fp = fopen(profileFileName, "r");
  1416. while(getline(&line, &len, fp) != -1)
  1417. {
  1418. json_object *obj = NULL;
  1419. obj = json_tokener_parse(line);
  1420. if(is_error(obj))
  1421. {
  1422. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1423. }
  1424. else
  1425. {
  1426. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1427. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1428. )
  1429. {
  1430. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1431. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1432. )
  1433. {
  1434. struct tm tmFrom, tmTo;
  1435. struct timeb tbFrom, tbTo;
  1436. 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) &&
  1437. (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))
  1438. {
  1439. tmFrom.tm_year -= 1900;
  1440. tmFrom.tm_mon -= 1;
  1441. tbFrom.time = mktime(&tmFrom);
  1442. tmTo.tm_year -= 1900;
  1443. tmTo.tm_mon -= 1;
  1444. tbTo.time = mktime(&tmTo);
  1445. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1446. {
  1447. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1448. {
  1449. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1450. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1451. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1452. }
  1453. if(maxProfile.ChargingProfileId == -1)
  1454. DEBUG_INFO("MaxProfile found.\n");
  1455. else
  1456. DEBUG_INFO("MaxProfile updated.\n");
  1457. // Required item
  1458. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1459. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1460. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1461. if(isUnitA)
  1462. {
  1463. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1464. 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++)
  1465. {
  1466. 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"));
  1467. 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?
  1468. 3:
  1469. 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")));
  1470. 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")));
  1471. }
  1472. }
  1473. else
  1474. {
  1475. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1476. 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++)
  1477. {
  1478. 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"));
  1479. 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?
  1480. 3:
  1481. 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")));
  1482. 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));
  1483. }
  1484. }
  1485. // Optional item
  1486. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1487. {
  1488. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1489. }
  1490. else
  1491. {
  1492. sprintf((char*)maxProfile.ValidFrom, " ");
  1493. }
  1494. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1495. {
  1496. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1497. }
  1498. else
  1499. {
  1500. sprintf((char*)maxProfile.ValidTo, " ");
  1501. }
  1502. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1503. {
  1504. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1505. }
  1506. else
  1507. {
  1508. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1509. }
  1510. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1511. {
  1512. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1513. }
  1514. else
  1515. {
  1516. maxProfile.TransactionId = -1;
  1517. }
  1518. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1519. {
  1520. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1521. }
  1522. else
  1523. {
  1524. maxProfile.ChargingSchedule.Duration = 86400;
  1525. }
  1526. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1527. {
  1528. 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")));
  1529. }
  1530. else
  1531. {
  1532. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1533. }
  1534. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1535. {
  1536. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1537. }
  1538. else
  1539. {
  1540. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1541. }
  1542. }
  1543. }
  1544. }
  1545. else
  1546. {
  1547. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1548. {
  1549. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1550. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1551. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1552. }
  1553. if(maxProfile.ChargingProfileId == -1)
  1554. DEBUG_INFO("MaxProfile found.\n");
  1555. else
  1556. DEBUG_INFO("MaxProfile updated.\n");
  1557. // Required item
  1558. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1559. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1560. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1561. if(isUnitA)
  1562. {
  1563. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1564. 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++)
  1565. {
  1566. 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"));
  1567. 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?
  1568. 3:
  1569. 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")));
  1570. 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")));
  1571. }
  1572. }
  1573. else
  1574. {
  1575. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1576. 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++)
  1577. {
  1578. 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"));
  1579. 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?
  1580. 3:
  1581. 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")));
  1582. 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));
  1583. }
  1584. }
  1585. // Optional item
  1586. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1587. {
  1588. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1589. }
  1590. else
  1591. {
  1592. sprintf((char*)maxProfile.ValidFrom, " ");
  1593. }
  1594. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1595. {
  1596. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1597. }
  1598. else
  1599. {
  1600. sprintf((char*)maxProfile.ValidTo, " ");
  1601. }
  1602. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1603. {
  1604. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1605. }
  1606. else
  1607. {
  1608. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1609. }
  1610. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1611. {
  1612. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1613. }
  1614. else
  1615. {
  1616. maxProfile.TransactionId = -1;
  1617. }
  1618. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1619. {
  1620. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1621. }
  1622. else
  1623. {
  1624. maxProfile.ChargingSchedule.Duration = 86400;
  1625. }
  1626. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1627. {
  1628. 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")));
  1629. }
  1630. else
  1631. {
  1632. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1633. }
  1634. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1635. {
  1636. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1637. }
  1638. else
  1639. {
  1640. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1641. }
  1642. }
  1643. }
  1644. }
  1645. json_object_put(obj);
  1646. }
  1647. fclose(fp);
  1648. /*
  1649. if(maxProfile.ChargingProfileId !=-1)
  1650. {
  1651. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1652. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1653. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1654. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1655. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1656. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1657. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1658. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1659. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1660. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1661. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1662. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1663. {
  1664. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1665. {
  1666. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1667. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1668. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1669. }
  1670. }
  1671. }
  1672. else
  1673. DEBUG_INFO("MaxProfile not found.\n");
  1674. DEBUG_INFO("------------------------------------\n");*/
  1675. }
  1676. if(maxProfile.ChargingProfileId != -1)
  1677. {
  1678. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1679. {
  1680. if(maxProfile.ChargingSchedule.Duration != -1)
  1681. {
  1682. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1683. 0:
  1684. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1685. }
  1686. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1687. {
  1688. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1689. {
  1690. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1691. 0:
  1692. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1693. if(idxPeriod > 0)
  1694. {
  1695. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1696. {
  1697. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1698. }
  1699. }
  1700. }
  1701. }
  1702. }
  1703. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1704. {
  1705. if(maxProfile.ChargingSchedule.Duration != -1)
  1706. {
  1707. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1708. }
  1709. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1710. {
  1711. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1712. {
  1713. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1714. if(idxPeriod > 0)
  1715. {
  1716. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1717. {
  1718. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1719. }
  1720. }
  1721. }
  1722. }
  1723. }
  1724. else
  1725. {
  1726. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1727. {
  1728. if(maxProfile.ChargingSchedule.Duration != -1)
  1729. {
  1730. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1731. 0:
  1732. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1733. }
  1734. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1735. {
  1736. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1737. {
  1738. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1739. 0:
  1740. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1741. if(idxPeriod > 0)
  1742. {
  1743. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1744. {
  1745. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1746. }
  1747. }
  1748. }
  1749. }
  1750. }
  1751. else
  1752. {
  1753. if(maxProfile.ChargingSchedule.Duration != -1)
  1754. {
  1755. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1756. 0:
  1757. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1758. }
  1759. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1760. {
  1761. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1762. {
  1763. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1764. 0:
  1765. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1766. if(idxPeriod > 0)
  1767. {
  1768. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1769. {
  1770. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1771. }
  1772. }
  1773. }
  1774. }
  1775. }
  1776. }
  1777. /*
  1778. DEBUG_INFO("MaxProfile after align.\n");
  1779. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1780. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1781. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1782. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1783. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1784. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1785. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1786. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1787. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1788. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1789. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1790. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1791. {
  1792. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1793. {
  1794. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1795. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1796. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1797. }
  1798. }
  1799. DEBUG_INFO("------------------------------------\n");*/
  1800. }
  1801. // Find each profile period quantity
  1802. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1803. {
  1804. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1805. limitMax = idx+1;
  1806. }
  1807. if(maxProfile.ChargingProfileId != -1)
  1808. {
  1809. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1810. {
  1811. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1812. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1813. (maxProfile.ChargingSchedule.Duration > 0))
  1814. {
  1815. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1816. {
  1817. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1818. compositePeriodIdx++;
  1819. }
  1820. else
  1821. {
  1822. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1823. }
  1824. }
  1825. }
  1826. }
  1827. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1828. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  1829. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  1830. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  1831. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1832. {
  1833. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1834. {
  1835. compositeProfile.ChargingProfileId = 1;
  1836. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1837. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1838. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1839. }
  1840. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1841. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1842. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1843. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1844. }
  1845. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  1846. if(line)
  1847. free(line);
  1848. }
  1849. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1850. {
  1851. FILE *fp;
  1852. char profileFileName[128];
  1853. char *line = NULL;
  1854. size_t len = 0;
  1855. time_t CurrentTime;
  1856. struct tm *tmComposite;
  1857. struct StructChargingProfile maxProfile;
  1858. struct StructChargingProfile defaultTxProfile;
  1859. struct StructChargingProfile txProfile;
  1860. struct StructChargingProfile compositeProfile;
  1861. struct StructChargingSchedulePeriod tmpPeriod;
  1862. uint8_t limitMax=0;
  1863. uint8_t limitDef=0;
  1864. uint8_t limitTx=0;
  1865. int compositePeriodIdx = 0;
  1866. CurrentTime = time(NULL);
  1867. tmComposite=localtime(&CurrentTime);
  1868. 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);
  1869. if(isUnitA)
  1870. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1871. else
  1872. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1873. compositeProfile.ChargingSchedule.Duration = durationReq;
  1874. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1875. {
  1876. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1877. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1878. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1879. }
  1880. compositeProfile.ChargingProfileId = 0;
  1881. compositeProfile.StackLevel = 99 ;
  1882. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1883. maxProfile.ChargingProfileId = -1;
  1884. defaultTxProfile.ChargingProfileId = -1;
  1885. txProfile.ChargingProfileId = -1;
  1886. maxProfile.ChargingSchedule.Duration = -1;
  1887. defaultTxProfile.ChargingSchedule.Duration = -1;
  1888. txProfile.ChargingSchedule.Duration = -1;
  1889. system("rm -f /tmp/*.json");
  1890. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1891. /*
  1892. * Search valid charging profile
  1893. */
  1894. //DEBUG_INFO("====================================\n");
  1895. // Search tx profile
  1896. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1897. if((access(profileFileName, F_OK))!=-1)
  1898. {
  1899. fp = fopen(profileFileName, "r");
  1900. while(getline(&line, &len, fp) != -1)
  1901. {
  1902. json_object *obj = NULL;
  1903. obj = json_tokener_parse(line);
  1904. if(is_error(obj))
  1905. {
  1906. DEBUG_ERROR("Parse txProfile from file error.\n");
  1907. }
  1908. else
  1909. {
  1910. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1911. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1912. )
  1913. {
  1914. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1915. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1916. )
  1917. {
  1918. struct tm tmFrom, tmTo;
  1919. struct timeb tbFrom, tbTo;
  1920. 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) &&
  1921. (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))
  1922. {
  1923. tmFrom.tm_year -= 1900;
  1924. tmFrom.tm_mon -= 1;
  1925. tbFrom.time = mktime(&tmFrom);
  1926. tmTo.tm_year -= 1900;
  1927. tmTo.tm_mon -= 1;
  1928. tbTo.time = mktime(&tmTo);
  1929. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1930. {
  1931. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1932. {
  1933. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1934. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1935. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1936. }
  1937. if(txProfile.ChargingProfileId == -1)
  1938. DEBUG_INFO("TxProfile found.\n");
  1939. else
  1940. DEBUG_INFO("TxProfile updated.\n");
  1941. // Required item
  1942. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1943. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1944. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1945. if(isUnitA)
  1946. {
  1947. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1948. 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++)
  1949. {
  1950. 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"));
  1951. 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?
  1952. 3:
  1953. 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")));
  1954. 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")));
  1955. }
  1956. }
  1957. else
  1958. {
  1959. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1960. 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++)
  1961. {
  1962. 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"));
  1963. 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?
  1964. 3:
  1965. 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")));
  1966. 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));
  1967. }
  1968. }
  1969. // Optional item
  1970. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1971. {
  1972. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1973. }
  1974. else
  1975. {
  1976. sprintf((char*)txProfile.ValidFrom, " ");
  1977. }
  1978. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1979. {
  1980. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1981. }
  1982. else
  1983. {
  1984. sprintf((char*)txProfile.ValidTo, " ");
  1985. }
  1986. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1987. {
  1988. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1989. }
  1990. else
  1991. {
  1992. sprintf((char*)txProfile.RecurrencyKind, " ");
  1993. }
  1994. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1995. {
  1996. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1997. }
  1998. else
  1999. {
  2000. txProfile.TransactionId = -1;
  2001. }
  2002. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2003. {
  2004. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2005. }
  2006. else
  2007. {
  2008. txProfile.ChargingSchedule.Duration = 86400;
  2009. }
  2010. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2011. {
  2012. 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")));
  2013. }
  2014. else
  2015. {
  2016. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2017. }
  2018. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2019. {
  2020. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2021. }
  2022. else
  2023. {
  2024. txProfile.ChargingSchedule.MinChargingRate = -1;
  2025. }
  2026. }
  2027. }
  2028. }
  2029. else
  2030. {
  2031. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2032. {
  2033. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2034. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2035. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2036. }
  2037. if(txProfile.ChargingProfileId == -1)
  2038. DEBUG_INFO("TxProfile found.\n");
  2039. else
  2040. DEBUG_INFO("TxProfile updated.\n");
  2041. // Required item
  2042. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2043. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2044. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2045. if(isUnitA)
  2046. {
  2047. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2048. 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++)
  2049. {
  2050. 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"));
  2051. 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?
  2052. 3:
  2053. 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")));
  2054. 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")));
  2055. }
  2056. }
  2057. else
  2058. {
  2059. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2060. 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++)
  2061. {
  2062. 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"));
  2063. 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?
  2064. 3:
  2065. 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")));
  2066. 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));
  2067. }
  2068. }
  2069. // Optional item
  2070. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2071. {
  2072. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2073. }
  2074. else
  2075. {
  2076. sprintf((char*)txProfile.ValidFrom, " ");
  2077. }
  2078. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2079. {
  2080. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2081. }
  2082. else
  2083. {
  2084. sprintf((char*)txProfile.ValidTo, " ");
  2085. }
  2086. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2087. {
  2088. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2089. }
  2090. else
  2091. {
  2092. sprintf((char*)txProfile.RecurrencyKind, " ");
  2093. }
  2094. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2095. {
  2096. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2097. }
  2098. else
  2099. {
  2100. txProfile.TransactionId = -1;
  2101. }
  2102. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2103. {
  2104. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2105. }
  2106. else
  2107. {
  2108. txProfile.ChargingSchedule.Duration = 86400;
  2109. }
  2110. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2111. {
  2112. 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")));
  2113. }
  2114. else
  2115. {
  2116. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2117. }
  2118. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2119. {
  2120. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2121. }
  2122. else
  2123. {
  2124. txProfile.ChargingSchedule.MinChargingRate = -1;
  2125. }
  2126. }
  2127. }
  2128. }
  2129. json_object_put(obj);
  2130. }
  2131. fclose(fp);
  2132. /*
  2133. if(txProfile.ChargingProfileId != -1)
  2134. {
  2135. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2136. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2137. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2138. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2139. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2140. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2141. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2142. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2143. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2144. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2145. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2146. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2147. {
  2148. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2149. {
  2150. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2151. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2152. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2153. }
  2154. }
  2155. }
  2156. else
  2157. DEBUG_INFO("TxProfile not found.\n");*/
  2158. }
  2159. // Search default tx profile
  2160. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2161. if((access(profileFileName, F_OK))==-1)
  2162. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2163. if((access(profileFileName, F_OK))!=-1)
  2164. {
  2165. fp = fopen(profileFileName, "r");
  2166. while(getline(&line, &len, fp) != -1)
  2167. {
  2168. json_object *obj = NULL;
  2169. obj = json_tokener_parse(line);
  2170. if(is_error(obj))
  2171. {
  2172. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2173. }
  2174. else
  2175. {
  2176. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2177. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2178. )
  2179. {
  2180. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2181. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2182. )
  2183. {
  2184. struct tm tmFrom, tmTo;
  2185. struct timeb tbFrom, tbTo;
  2186. 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) &&
  2187. (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))
  2188. {
  2189. tmFrom.tm_year -= 1900;
  2190. tmFrom.tm_mon -= 1;
  2191. tbFrom.time = mktime(&tmFrom);
  2192. tmTo.tm_year -= 1900;
  2193. tmTo.tm_mon -= 1;
  2194. tbTo.time = mktime(&tmTo);
  2195. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2196. {
  2197. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2198. {
  2199. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2200. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2201. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2202. }
  2203. if(defaultTxProfile.ChargingProfileId == -1)
  2204. DEBUG_INFO("TxDefaultProfile found.\n");
  2205. else
  2206. DEBUG_INFO("TxDefaultProfile updated.\n");
  2207. // Required item
  2208. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2209. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2210. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2211. if(isUnitA)
  2212. {
  2213. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2214. 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++)
  2215. {
  2216. 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"));
  2217. 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?
  2218. 3:
  2219. 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")));
  2220. 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")));
  2221. }
  2222. }
  2223. else
  2224. {
  2225. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2226. 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++)
  2227. {
  2228. 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"));
  2229. 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?
  2230. 3:
  2231. 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")));
  2232. 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));
  2233. }
  2234. }
  2235. // Optional item
  2236. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2237. {
  2238. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2239. }
  2240. else
  2241. {
  2242. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2243. }
  2244. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2245. {
  2246. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2247. }
  2248. else
  2249. {
  2250. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2251. }
  2252. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2253. {
  2254. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2255. }
  2256. else
  2257. {
  2258. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2259. }
  2260. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2261. {
  2262. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2263. }
  2264. else
  2265. {
  2266. defaultTxProfile.TransactionId = -1;
  2267. }
  2268. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2269. {
  2270. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2271. }
  2272. else
  2273. {
  2274. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2275. }
  2276. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2277. {
  2278. 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")));
  2279. }
  2280. else
  2281. {
  2282. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2283. }
  2284. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2285. {
  2286. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2287. }
  2288. else
  2289. {
  2290. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2291. }
  2292. }
  2293. }
  2294. }
  2295. else
  2296. {
  2297. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2298. {
  2299. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2300. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2301. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2302. }
  2303. if(defaultTxProfile.ChargingProfileId == -1)
  2304. DEBUG_INFO("TxDefaultProfile found.\n");
  2305. else
  2306. DEBUG_INFO("TxDefaultProfile updated.\n");
  2307. // Required item
  2308. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2309. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2310. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2311. if(isUnitA)
  2312. {
  2313. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2314. 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++)
  2315. {
  2316. 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"));
  2317. 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?
  2318. 3:
  2319. 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")));
  2320. 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")));
  2321. }
  2322. }
  2323. else
  2324. {
  2325. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2326. 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++)
  2327. {
  2328. 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"));
  2329. 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?
  2330. 3:
  2331. 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")));
  2332. 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));
  2333. }
  2334. }
  2335. // Optional item
  2336. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2337. {
  2338. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2339. }
  2340. else
  2341. {
  2342. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2343. }
  2344. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2345. {
  2346. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2347. }
  2348. else
  2349. {
  2350. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2351. }
  2352. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2353. {
  2354. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2355. }
  2356. else
  2357. {
  2358. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2359. }
  2360. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2361. {
  2362. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2363. }
  2364. else
  2365. {
  2366. defaultTxProfile.TransactionId = -1;
  2367. }
  2368. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2369. {
  2370. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2371. }
  2372. else
  2373. {
  2374. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2375. }
  2376. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2377. {
  2378. 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")));
  2379. }
  2380. else
  2381. {
  2382. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2383. }
  2384. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2385. {
  2386. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2387. }
  2388. else
  2389. {
  2390. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2391. }
  2392. }
  2393. }
  2394. }
  2395. json_object_put(obj);
  2396. }
  2397. fclose(fp);
  2398. /*
  2399. if(defaultTxProfile.ChargingProfileId != -1)
  2400. {
  2401. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2402. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2403. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2404. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2405. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2406. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2407. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2408. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2409. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2410. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2411. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2412. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2413. {
  2414. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2415. {
  2416. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2417. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2418. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2419. }
  2420. }
  2421. }
  2422. else
  2423. DEBUG_INFO("TxDefaultProfile not found.\n");
  2424. DEBUG_INFO("------------------------------------\n");*/
  2425. }
  2426. // Search max profile
  2427. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2428. if((access(profileFileName, F_OK))!=-1)
  2429. {
  2430. fp = fopen(profileFileName, "r");
  2431. while(getline(&line, &len, fp) != -1)
  2432. {
  2433. json_object *obj = NULL;
  2434. obj = json_tokener_parse(line);
  2435. if(is_error(obj))
  2436. {
  2437. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2438. }
  2439. else
  2440. {
  2441. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2442. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2443. )
  2444. {
  2445. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2446. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2447. )
  2448. {
  2449. struct tm tmFrom, tmTo;
  2450. struct timeb tbFrom, tbTo;
  2451. 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) &&
  2452. (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))
  2453. {
  2454. tmFrom.tm_year -= 1900;
  2455. tmFrom.tm_mon -= 1;
  2456. tbFrom.time = mktime(&tmFrom);
  2457. tmTo.tm_year -= 1900;
  2458. tmTo.tm_mon -= 1;
  2459. tbTo.time = mktime(&tmTo);
  2460. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2461. {
  2462. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2463. {
  2464. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2465. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2466. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2467. }
  2468. if(maxProfile.ChargingProfileId == -1)
  2469. DEBUG_INFO("MaxProfile found.\n");
  2470. else
  2471. DEBUG_INFO("MaxProfile updated.\n");
  2472. // Required item
  2473. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2474. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2475. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2476. if(isUnitA)
  2477. {
  2478. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2479. 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++)
  2480. {
  2481. 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"));
  2482. 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?
  2483. 3:
  2484. 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")));
  2485. 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")));
  2486. }
  2487. }
  2488. else
  2489. {
  2490. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2491. 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++)
  2492. {
  2493. 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"));
  2494. 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?
  2495. 3:
  2496. 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")));
  2497. 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));
  2498. }
  2499. }
  2500. // Optional item
  2501. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2502. {
  2503. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2504. }
  2505. else
  2506. {
  2507. sprintf((char*)maxProfile.ValidFrom, " ");
  2508. }
  2509. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2510. {
  2511. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2512. }
  2513. else
  2514. {
  2515. sprintf((char*)maxProfile.ValidTo, " ");
  2516. }
  2517. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2518. {
  2519. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2520. }
  2521. else
  2522. {
  2523. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2524. }
  2525. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2526. {
  2527. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2528. }
  2529. else
  2530. {
  2531. maxProfile.TransactionId = -1;
  2532. }
  2533. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2534. {
  2535. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2536. }
  2537. else
  2538. {
  2539. maxProfile.ChargingSchedule.Duration = 86400;
  2540. }
  2541. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2542. {
  2543. 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")));
  2544. }
  2545. else
  2546. {
  2547. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2548. }
  2549. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2550. {
  2551. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2552. }
  2553. else
  2554. {
  2555. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2556. }
  2557. }
  2558. }
  2559. }
  2560. else
  2561. {
  2562. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2563. {
  2564. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2565. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2566. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2567. }
  2568. if(maxProfile.ChargingProfileId == -1)
  2569. DEBUG_INFO("MaxProfile found.\n");
  2570. else
  2571. DEBUG_INFO("MaxProfile updated.\n");
  2572. // Required item
  2573. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2574. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2575. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2576. if(isUnitA)
  2577. {
  2578. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2579. 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++)
  2580. {
  2581. 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"));
  2582. 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?
  2583. 3:
  2584. 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")));
  2585. 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")));
  2586. }
  2587. }
  2588. else
  2589. {
  2590. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2591. 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++)
  2592. {
  2593. 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"));
  2594. 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?
  2595. 3:
  2596. 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")));
  2597. 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));
  2598. }
  2599. }
  2600. // Optional item
  2601. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2602. {
  2603. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2604. }
  2605. else
  2606. {
  2607. sprintf((char*)maxProfile.ValidFrom, " ");
  2608. }
  2609. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2610. {
  2611. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2612. }
  2613. else
  2614. {
  2615. sprintf((char*)maxProfile.ValidTo, " ");
  2616. }
  2617. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2618. {
  2619. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2620. }
  2621. else
  2622. {
  2623. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2624. }
  2625. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2626. {
  2627. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2628. }
  2629. else
  2630. {
  2631. maxProfile.TransactionId = -1;
  2632. }
  2633. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2634. {
  2635. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2636. }
  2637. else
  2638. {
  2639. maxProfile.ChargingSchedule.Duration = 86400;
  2640. }
  2641. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2642. {
  2643. 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")));
  2644. }
  2645. else
  2646. {
  2647. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2648. }
  2649. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2650. {
  2651. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2652. }
  2653. else
  2654. {
  2655. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2656. }
  2657. }
  2658. }
  2659. }
  2660. json_object_put(obj);
  2661. }
  2662. fclose(fp);
  2663. /*
  2664. if(maxProfile.ChargingProfileId !=-1)
  2665. {
  2666. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2667. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2668. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2669. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2670. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2671. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2672. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2673. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2674. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2675. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2676. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2677. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2678. {
  2679. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2680. {
  2681. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2682. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2683. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2684. }
  2685. }
  2686. }
  2687. else
  2688. DEBUG_INFO("MaxProfile not found.\n");
  2689. DEBUG_INFO("------------------------------------\n");*/
  2690. }
  2691. /*
  2692. * Align found profile start schedule & periods
  2693. */
  2694. //DEBUG_INFO("====================================\n");
  2695. /*
  2696. // For local test usage, force modify found profile start schedule info
  2697. 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);
  2698. 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);
  2699. 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);
  2700. */
  2701. if(txProfile.ChargingProfileId != -1)
  2702. {
  2703. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2704. {
  2705. if(txProfile.ChargingSchedule.Duration != -1)
  2706. {
  2707. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2708. 0:
  2709. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2710. }
  2711. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2712. {
  2713. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2714. {
  2715. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2716. 0:
  2717. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2718. if(idxPeriod > 0)
  2719. {
  2720. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2721. {
  2722. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2723. }
  2724. }
  2725. }
  2726. }
  2727. }
  2728. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2729. {
  2730. if(txProfile.ChargingSchedule.Duration != -1)
  2731. {
  2732. txProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2733. 0:
  2734. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2735. }
  2736. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2737. {
  2738. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2739. {
  2740. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2741. 0:
  2742. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2743. if(idxPeriod > 0)
  2744. {
  2745. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2746. {
  2747. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2748. }
  2749. }
  2750. }
  2751. }
  2752. }
  2753. else
  2754. {
  2755. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2756. {
  2757. if(txProfile.ChargingSchedule.Duration != -1)
  2758. {
  2759. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2760. 0:
  2761. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2762. }
  2763. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2764. {
  2765. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2766. {
  2767. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2768. 0:
  2769. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2770. if(idxPeriod > 0)
  2771. {
  2772. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2773. {
  2774. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2775. }
  2776. }
  2777. }
  2778. }
  2779. }
  2780. else
  2781. {
  2782. if(txProfile.ChargingSchedule.Duration != -1)
  2783. {
  2784. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2785. 0:
  2786. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2787. }
  2788. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2789. {
  2790. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2791. {
  2792. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2793. 0:
  2794. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2795. if(idxPeriod > 0)
  2796. {
  2797. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2798. {
  2799. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2800. }
  2801. }
  2802. }
  2803. }
  2804. }
  2805. }
  2806. /*
  2807. DEBUG_INFO("txProfile after align.\n");
  2808. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2809. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2810. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2811. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2812. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2813. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2814. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2815. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2816. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2817. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2818. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2819. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2820. {
  2821. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2822. {
  2823. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2824. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2825. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2826. }
  2827. }*/
  2828. }
  2829. if(defaultTxProfile.ChargingProfileId != -1)
  2830. {
  2831. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2832. {
  2833. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2834. {
  2835. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2836. 0:
  2837. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2838. }
  2839. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2840. {
  2841. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2842. {
  2843. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2844. 0:
  2845. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2846. if(idxPeriod > 0)
  2847. {
  2848. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2849. {
  2850. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2851. }
  2852. }
  2853. }
  2854. }
  2855. }
  2856. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2857. {
  2858. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2859. {
  2860. defaultTxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2861. 0:
  2862. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2863. }
  2864. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2865. {
  2866. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2867. {
  2868. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2869. 0:
  2870. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2871. if(idxPeriod > 0)
  2872. {
  2873. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2874. {
  2875. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2876. }
  2877. }
  2878. }
  2879. }
  2880. }
  2881. else
  2882. {
  2883. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2884. {
  2885. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2886. {
  2887. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2888. 0:
  2889. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2890. }
  2891. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2892. {
  2893. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2894. {
  2895. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2896. 0:
  2897. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2898. if(idxPeriod > 0)
  2899. {
  2900. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2901. {
  2902. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2903. }
  2904. }
  2905. }
  2906. }
  2907. }
  2908. else
  2909. {
  2910. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2911. {
  2912. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2913. 0:
  2914. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2915. }
  2916. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2917. {
  2918. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2919. {
  2920. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2921. 0:
  2922. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2923. if(idxPeriod > 0)
  2924. {
  2925. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2926. {
  2927. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2928. }
  2929. }
  2930. }
  2931. }
  2932. }
  2933. }
  2934. /*
  2935. DEBUG_INFO("defaultTxProfile after align.\n");
  2936. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2937. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2938. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2939. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2940. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2941. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2942. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2943. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2944. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2945. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2946. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2947. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2948. {
  2949. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2950. {
  2951. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2952. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2953. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2954. }
  2955. }
  2956. DEBUG_INFO("------------------------------------\n");*/
  2957. }
  2958. if(maxProfile.ChargingProfileId != -1)
  2959. {
  2960. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2961. {
  2962. if(maxProfile.ChargingSchedule.Duration != -1)
  2963. {
  2964. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2965. 0:
  2966. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2967. }
  2968. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2969. {
  2970. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2971. {
  2972. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2973. 0:
  2974. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2975. if(idxPeriod > 0)
  2976. {
  2977. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2978. {
  2979. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2980. }
  2981. }
  2982. }
  2983. }
  2984. }
  2985. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2986. {
  2987. if(maxProfile.ChargingSchedule.Duration != -1)
  2988. {
  2989. maxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2990. 0:
  2991. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2992. }
  2993. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2994. {
  2995. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2996. {
  2997. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2998. 0:
  2999. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3000. if(idxPeriod > 0)
  3001. {
  3002. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3003. {
  3004. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3005. }
  3006. }
  3007. }
  3008. }
  3009. }
  3010. else
  3011. {
  3012. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3013. {
  3014. if(maxProfile.ChargingSchedule.Duration != -1)
  3015. {
  3016. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3017. 0:
  3018. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3019. }
  3020. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3021. {
  3022. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3023. {
  3024. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3025. 0:
  3026. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3027. if(idxPeriod > 0)
  3028. {
  3029. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3030. {
  3031. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3032. }
  3033. }
  3034. }
  3035. }
  3036. }
  3037. else
  3038. {
  3039. if(maxProfile.ChargingSchedule.Duration != -1)
  3040. {
  3041. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3042. 0:
  3043. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3044. }
  3045. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3046. {
  3047. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3048. {
  3049. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3050. 0:
  3051. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3052. if(idxPeriod > 0)
  3053. {
  3054. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3055. {
  3056. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3057. }
  3058. }
  3059. }
  3060. }
  3061. }
  3062. }
  3063. /*
  3064. DEBUG_INFO("MaxProfile after align.\n");
  3065. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3066. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3067. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3068. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3069. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3070. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3071. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3072. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3073. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3074. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3075. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3076. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3077. {
  3078. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3079. {
  3080. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3081. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3082. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3083. }
  3084. }
  3085. DEBUG_INFO("------------------------------------\n");*/
  3086. }
  3087. /*
  3088. * Merge to conposite schedule
  3089. */
  3090. //DEBUG_INFO("====================================\n");
  3091. // Find each profile period quantity
  3092. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3093. {
  3094. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3095. limitMax = idx+1;
  3096. }
  3097. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3098. {
  3099. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3100. limitDef = idx+1;
  3101. }
  3102. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3103. {
  3104. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3105. limitTx = idx+1;
  3106. }
  3107. // TxProfile found, composite schedule based on it
  3108. if(txProfile.ChargingProfileId != -1)
  3109. {
  3110. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3111. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3112. {
  3113. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3114. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3115. (txProfile.ChargingSchedule.Duration > 0))
  3116. {
  3117. if(maxProfile.ChargingProfileId != -1)
  3118. {
  3119. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3120. {
  3121. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3122. {
  3123. if((maxProfile.ChargingSchedule.Duration > 0))
  3124. {
  3125. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3126. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3127. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3128. }
  3129. else
  3130. {
  3131. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3132. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3133. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3134. }
  3135. }
  3136. if(idxMaxPeriod == (limitMax-1))
  3137. {
  3138. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3139. {
  3140. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3141. {
  3142. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3143. compositePeriodIdx++;
  3144. }
  3145. else
  3146. {
  3147. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3148. }
  3149. }
  3150. }
  3151. }
  3152. }
  3153. else
  3154. {
  3155. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3156. {
  3157. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3158. compositePeriodIdx++;
  3159. }
  3160. else
  3161. {
  3162. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3163. }
  3164. }
  3165. }
  3166. if(idxTxPeriod == (limitTx-1))
  3167. {
  3168. if(defaultTxProfile.ChargingProfileId != -1)
  3169. {
  3170. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3171. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3172. {
  3173. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3174. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3175. (defaultTxProfile.ChargingSchedule.Duration>0))
  3176. {
  3177. if(maxProfile.ChargingProfileId != -1)
  3178. {
  3179. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3180. {
  3181. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3182. {
  3183. if((maxProfile.ChargingSchedule.Duration > 0))
  3184. {
  3185. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3186. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3187. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3188. }
  3189. else
  3190. {
  3191. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3192. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3193. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3194. }
  3195. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3196. {
  3197. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3198. {
  3199. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3200. compositePeriodIdx++;
  3201. }
  3202. else
  3203. {
  3204. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3205. }
  3206. }
  3207. // Delete duplicate period
  3208. if(compositePeriodIdx > 1)
  3209. {
  3210. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3211. {
  3212. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3213. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3214. compositePeriodIdx -= 1;
  3215. }
  3216. }
  3217. }
  3218. else
  3219. {
  3220. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3221. {
  3222. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3223. compositePeriodIdx++;
  3224. }
  3225. else
  3226. {
  3227. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3228. }
  3229. break;
  3230. }
  3231. }
  3232. }
  3233. else
  3234. {
  3235. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3236. {
  3237. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3238. compositePeriodIdx++;
  3239. }
  3240. else
  3241. {
  3242. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3243. }
  3244. }
  3245. }
  3246. }
  3247. }
  3248. }
  3249. }
  3250. }
  3251. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3252. else if(defaultTxProfile.ChargingProfileId != -1)
  3253. {
  3254. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3255. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3256. {
  3257. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3258. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3259. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3260. {
  3261. if(maxProfile.ChargingProfileId != -1)
  3262. {
  3263. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3264. {
  3265. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3266. {
  3267. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3268. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3269. if((maxProfile.ChargingSchedule.Duration > 0))
  3270. {
  3271. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3272. }
  3273. else
  3274. {
  3275. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3276. }
  3277. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3278. {
  3279. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3280. {
  3281. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3282. compositePeriodIdx++;
  3283. }
  3284. else
  3285. {
  3286. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3287. }
  3288. }
  3289. // Delete duplicate period
  3290. if(compositePeriodIdx > 1)
  3291. {
  3292. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3293. {
  3294. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3295. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3296. compositePeriodIdx -= 1;
  3297. }
  3298. }
  3299. }
  3300. else
  3301. {
  3302. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3303. {
  3304. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3305. compositePeriodIdx++;
  3306. }
  3307. else
  3308. {
  3309. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3310. }
  3311. break;
  3312. }
  3313. }
  3314. }
  3315. else
  3316. {
  3317. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3318. {
  3319. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3320. compositePeriodIdx++;
  3321. }
  3322. else
  3323. {
  3324. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3325. }
  3326. }
  3327. }
  3328. }
  3329. }
  3330. // Fill other period by MaxProfile
  3331. if(maxProfile.ChargingProfileId != -1)
  3332. {
  3333. if(compositePeriodIdx==0)
  3334. {
  3335. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3336. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3337. {
  3338. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3339. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3340. (maxProfile.ChargingSchedule.Duration > 0))
  3341. {
  3342. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3343. {
  3344. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3345. compositePeriodIdx++;
  3346. }
  3347. else
  3348. {
  3349. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3350. }
  3351. }
  3352. }
  3353. }
  3354. else
  3355. {
  3356. int lastCompositePeriodIdx = compositePeriodIdx;
  3357. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3358. {
  3359. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3360. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3361. (maxProfile.ChargingSchedule.Duration > 0))
  3362. {
  3363. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3364. {
  3365. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3366. {
  3367. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3368. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3369. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3370. }
  3371. else
  3372. {
  3373. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3374. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3375. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3376. }
  3377. }
  3378. if(tmpPeriod.Limit != -1)
  3379. {
  3380. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3381. {
  3382. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3383. {
  3384. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3385. compositePeriodIdx++;
  3386. }
  3387. else
  3388. {
  3389. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3390. }
  3391. }
  3392. // Delete duplicate period
  3393. if(compositePeriodIdx > 1)
  3394. {
  3395. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3396. {
  3397. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3398. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3399. compositePeriodIdx -= 1;
  3400. }
  3401. }
  3402. }
  3403. }
  3404. }
  3405. }
  3406. }
  3407. compositeProfile.ChargingSchedule.Duration = durationReq;
  3408. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3409. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3410. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  3411. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  3412. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3413. {
  3414. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3415. {
  3416. compositeProfile.ChargingProfileId = 1;
  3417. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3418. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3419. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3420. }
  3421. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3422. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3423. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3424. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3425. }
  3426. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3427. if(line)
  3428. free(line);
  3429. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  3430. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3431. }
  3432. //==========================================
  3433. // Init all share memory
  3434. //==========================================
  3435. int InitShareMemory()
  3436. {
  3437. int result = PASS;
  3438. int MeterSMId;
  3439. //creat ShmSysConfigAndInfo
  3440. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3441. {
  3442. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3443. result = FAIL;
  3444. }
  3445. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3446. {
  3447. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3448. result = FAIL;
  3449. }
  3450. else
  3451. {}
  3452. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3453. {
  3454. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3455. result = FAIL;
  3456. }
  3457. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3458. {
  3459. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3460. result = FAIL;
  3461. }
  3462. else
  3463. {}
  3464. //creat ShmPsuData
  3465. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3466. {
  3467. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3468. result = FAIL;
  3469. }
  3470. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3471. {
  3472. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3473. result = FAIL;
  3474. }
  3475. else
  3476. {}
  3477. //link ShmOCPP16Data
  3478. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3479. {
  3480. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3481. result = FAIL;
  3482. }
  3483. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3484. {
  3485. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3486. result = FAIL;
  3487. }
  3488. else
  3489. {}
  3490. //creat ShmOCPP16DataPH
  3491. if ((MeterSMId = shmget(ShmOcppPHModuleKey, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  3492. {
  3493. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  3494. result = FAIL;
  3495. }
  3496. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3497. {
  3498. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  3499. result = FAIL;
  3500. }
  3501. else
  3502. {}
  3503. /****************************** For Initial Settings************************************************/
  3504. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  3505. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  3506. // allocate Configuration memory address
  3507. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  3508. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3509. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3510. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3511. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  3512. //offline MeterValue Interval
  3513. TempMeterValueInterval = 0;
  3514. return result;
  3515. }
  3516. int ProcessShareMemory()
  3517. {
  3518. int result = PASS;
  3519. if(InitShareMemory() == FAIL)
  3520. {
  3521. DEBUG_ERROR("InitShareMemory NG\n");
  3522. if(ShmStatusCodeData!=NULL)
  3523. {
  3524. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3525. }
  3526. result = FAIL;
  3527. }
  3528. // Model name parsing
  3529. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3530. {
  3531. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3532. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3533. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3534. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3535. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3536. ) // 'D' means DC
  3537. {
  3538. // DO series
  3539. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3540. {
  3541. SystemInitial += 1;
  3542. gunTotalNumber += 1;
  3543. gunType[gun_index] = GUN_TYPE_DO;
  3544. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3545. {
  3546. case Gun_Type_Chademo:
  3547. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3548. break;
  3549. case Gun_Type_CCS_2:
  3550. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3551. break;
  3552. case Gun_Type_GB:
  3553. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3554. break;
  3555. case Gun_Type_AC:
  3556. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3557. break;
  3558. default:
  3559. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3560. break;
  3561. }
  3562. }
  3563. }
  3564. else
  3565. {
  3566. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3567. {
  3568. SystemInitial += 1;
  3569. gunTotalNumber += 1;
  3570. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3571. {
  3572. case Gun_Type_Chademo:
  3573. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3574. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3575. break;
  3576. case Gun_Type_CCS_2:
  3577. gunType[gun_index] = GUN_TYPE_CCS;
  3578. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3579. break;
  3580. case Gun_Type_GB:
  3581. gunType[gun_index] = GUN_TYPE_GBT;
  3582. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3583. break;
  3584. case Gun_Type_AC:
  3585. gunType[gun_index] = GUN_TYPE_AC;
  3586. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3587. break;
  3588. default:
  3589. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3590. break;
  3591. }
  3592. }
  3593. }
  3594. }
  3595. else
  3596. {
  3597. DEBUG_ERROR("Model name parsing fail.\n");
  3598. result = FAIL;
  3599. }
  3600. if(result != PASS)sleep(5);
  3601. return result;
  3602. }
  3603. void checkRemoteStart(uint8_t connectorIdInt)
  3604. {
  3605. uint8_t tempIndex;
  3606. int result = PASS;
  3607. char cmdBuf[512];
  3608. //check Transaction active
  3609. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3610. {
  3611. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3612. {
  3613. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3614. }
  3615. else
  3616. {
  3617. tempIndex = connectorIdInt -1;
  3618. }
  3619. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3620. {
  3621. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3622. {
  3623. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3624. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3625. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3626. {
  3627. //Reserved
  3628. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3629. }
  3630. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3631. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3632. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3633. {
  3634. //Reserved
  3635. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3636. result = FAIL;
  3637. goto end;
  3638. }
  3639. else
  3640. {
  3641. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3642. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3643. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3644. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3645. {
  3646. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  3647. result = FAIL;
  3648. goto end;
  3649. }
  3650. }//END FOR ELSE
  3651. }
  3652. }// END FOR CHAdeMO_QUANTITY
  3653. }
  3654. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3655. {
  3656. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3657. {
  3658. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3659. }
  3660. else
  3661. {
  3662. tempIndex = connectorIdInt -1;
  3663. }
  3664. for (int index = 0; index < CCS_QUANTITY; index++)
  3665. {
  3666. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3667. {
  3668. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3669. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3670. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3671. {
  3672. //Reserved
  3673. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3674. }
  3675. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3676. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3677. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3678. {
  3679. //Reserved
  3680. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3681. result = FAIL;
  3682. goto end;
  3683. }
  3684. else
  3685. {
  3686. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3687. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3688. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3689. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3690. {
  3691. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3692. result = FAIL;
  3693. goto end;
  3694. }
  3695. }// END FOR ELSE
  3696. }
  3697. }// END FOR CCS_QUANTITY
  3698. }
  3699. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3700. {
  3701. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3702. {
  3703. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3704. }
  3705. else
  3706. {
  3707. tempIndex = connectorIdInt -1;
  3708. }
  3709. for (int index = 0; index < GB_QUANTITY; index++)
  3710. {
  3711. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3712. {
  3713. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3714. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3715. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3716. {
  3717. //Reserved
  3718. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3719. }
  3720. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3721. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3722. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3723. {
  3724. //Reserved
  3725. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3726. result = FAIL;
  3727. goto end;
  3728. }
  3729. else
  3730. {
  3731. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3732. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3733. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3734. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3735. {
  3736. DEBUG_WARN("GBT connector not allow start cause busy.\n.");
  3737. result = FAIL;
  3738. goto end;
  3739. }
  3740. }// END FOR ELSE
  3741. }
  3742. } // END FOR GB_QUANTITY
  3743. }
  3744. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3745. {
  3746. tempIndex = connectorIdInt -1;
  3747. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3748. {
  3749. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3750. {
  3751. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3752. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3753. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3754. {
  3755. //Reserved
  3756. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3757. }
  3758. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3759. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3760. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3761. {
  3762. //Reserved
  3763. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3764. result = FAIL;
  3765. goto end;
  3766. }
  3767. else
  3768. {
  3769. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3770. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3771. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3772. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3773. {
  3774. DEBUG_WARN("Dispenser connector not allow start cause busy.\n.");
  3775. result = FAIL;
  3776. goto end;
  3777. }
  3778. }// END FOR ELSE
  3779. }
  3780. } // END FOR GB_QUANTITY
  3781. }
  3782. else
  3783. {
  3784. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3785. {
  3786. tempIndex = 2;
  3787. }
  3788. else
  3789. {
  3790. tempIndex = connectorIdInt -1;
  3791. }
  3792. for (int index = 0; index < AC_QUANTITY; index++)
  3793. {
  3794. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3795. {
  3796. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3797. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3798. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3799. {
  3800. //Reserved
  3801. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3802. }
  3803. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3804. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3805. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3806. {
  3807. //Reserved
  3808. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3809. result = FAIL;
  3810. goto end;
  3811. }
  3812. else
  3813. {
  3814. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3815. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3816. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3817. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3818. {
  3819. DEBUG_WARN("AC connector not allow start cause busy.\n.");
  3820. result = FAIL;
  3821. goto end;
  3822. }
  3823. }//END FOR ELSE
  3824. }
  3825. }// END FOR AC_QUANTITY
  3826. }
  3827. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3828. {
  3829. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3830. {
  3831. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3832. if((access("/Storage/OCPP_PH/TxProfile_Tmp.json", F_OK))!=-1)
  3833. {
  3834. sprintf(cmdBuf, "mv /Storage/OCPP_PH/TxProfile_Tmp.json /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  3835. system(cmdBuf);
  3836. }
  3837. }
  3838. else
  3839. {
  3840. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3841. result = FAIL;
  3842. }
  3843. }
  3844. end:
  3845. if(result == PASS)
  3846. {
  3847. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3848. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3849. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3850. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3851. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3852. }
  3853. }
  3854. void CheckSystemValue(void)
  3855. {
  3856. char filenmae[100]={0};
  3857. char str[100]={0};
  3858. int tempIndex = 0;
  3859. //===============================
  3860. // send Heartbeat
  3861. //===============================
  3862. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3863. {
  3864. //parameter for test
  3865. sendHeartbeatRequest(0);
  3866. //==============================================
  3867. // Reset Waiting Time
  3868. //==============================================
  3869. HeartBeatWithNOResponse += 2;
  3870. }
  3871. //===============================
  3872. // Credit deduct report
  3873. //===============================
  3874. if(ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq)
  3875. {
  3876. OCPP_insert_deduct_info(ShmOCPP16DataPH->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.creditNo,
  3877. ShmOCPP16DataPH->TcciCustomData.DeductInfo.deductResult, ShmOCPP16DataPH->TcciCustomData.DeductInfo.isDonateInvoice,
  3878. ShmOCPP16DataPH->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.vemData,
  3879. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.RRN,
  3880. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.storeId);
  3881. ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq = FALSE;
  3882. }
  3883. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  3884. {
  3885. OCPP_query_deduct_info();
  3886. refreshStartTimer(&clientTime.TcciQueryDeduct);
  3887. }
  3888. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3889. {
  3890. // ClockAlign MeterValue
  3891. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3892. {
  3893. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3894. {
  3895. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3896. {
  3897. tempIndex = ((gun_index==2) ? 1: 0);
  3898. }
  3899. else
  3900. {
  3901. tempIndex = gun_index;
  3902. }
  3903. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3904. {
  3905. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3906. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3907. {
  3908. reqClockAlignMeter[gun_index] = 1;
  3909. }
  3910. }// End for CHAdeMO
  3911. }
  3912. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3913. {
  3914. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3915. {
  3916. tempIndex = ((gun_index==2) ? 1: 0);
  3917. }
  3918. else
  3919. {
  3920. tempIndex = gun_index;
  3921. }
  3922. for (int index = 0; index < CCS_QUANTITY; index++)
  3923. {
  3924. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3925. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3926. {
  3927. reqClockAlignMeter[gun_index] = 1;
  3928. }
  3929. } // End for CCS
  3930. }
  3931. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3932. {
  3933. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3934. {
  3935. tempIndex = ((gun_index==2) ? 1: 0);
  3936. }
  3937. else
  3938. {
  3939. tempIndex = gun_index;
  3940. }
  3941. for (int index = 0; index < GB_QUANTITY; index++)
  3942. {
  3943. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3944. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3945. {
  3946. reqClockAlignMeter[gun_index] = 1;
  3947. }
  3948. }// End for GB
  3949. }
  3950. else if(gunType[gun_index] == GUN_TYPE_DO)
  3951. {
  3952. tempIndex = gun_index;
  3953. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3954. {
  3955. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3956. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3957. {
  3958. reqClockAlignMeter[gun_index] = 1;
  3959. }
  3960. }
  3961. }
  3962. else
  3963. {
  3964. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3965. {
  3966. tempIndex = 2;
  3967. }
  3968. else
  3969. {
  3970. tempIndex = gun_index;
  3971. }
  3972. for (int index = 0; index < AC_QUANTITY; index++)
  3973. {
  3974. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3975. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3976. {
  3977. reqClockAlignMeter[gun_index] = 1;
  3978. }
  3979. }//End for AC
  3980. }
  3981. }
  3982. }
  3983. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3984. {
  3985. //==========================================
  3986. // Check remote start without connector id
  3987. //==========================================
  3988. if(ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  3989. {
  3990. int connectorIdInt = -1;
  3991. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  3992. {
  3993. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  3994. {
  3995. connectorIdInt = (gun_index+1);
  3996. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  3997. checkRemoteStart(connectorIdInt);
  3998. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3999. break;
  4000. }
  4001. }
  4002. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4003. {
  4004. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4005. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  4006. }
  4007. }
  4008. //==========================================
  4009. // csu trigger DataTransferReq
  4010. //==========================================
  4011. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  4012. {
  4013. sendDataTransferRequest(gun_index);
  4014. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  4015. }
  4016. //===============================
  4017. // CSU Trigger Authorize Request
  4018. //===============================
  4019. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4020. {
  4021. sendAuthorizeRequest(0);
  4022. authorizeRetryTimes = authorizeRetryTimes + 1;
  4023. if(authorizeRetryTimes < 3)
  4024. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4025. }
  4026. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4027. {
  4028. authorizeRetryTimes = 0;
  4029. SetOcppConnStatus(FALSE);
  4030. server_sign = FALSE;
  4031. }
  4032. else if((server_sign == FALSE) && (strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16DataPH->OcppConnStatus == 0)&& (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1))
  4033. {
  4034. sendAuthorizeRequest(0);
  4035. }
  4036. //==============================================
  4037. // Charger start transaction
  4038. //==============================================
  4039. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4040. {
  4041. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4042. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  4043. sendStartTransactionRequest(gun_index);
  4044. refreshStartTimer(&clientTime.StartTransaction);
  4045. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4046. //storeTempStopTransaction(gun_index);
  4047. }
  4048. //==============================================
  4049. // Charger stop transaction
  4050. //==============================================
  4051. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4052. {
  4053. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4054. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  4055. sendStopTransactionRequest(gun_index);
  4056. refreshStartTimer(&clientTime.StopTransaction);
  4057. memset(&ShmOCPP16DataPH->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4058. }
  4059. //==============================================
  4060. // Charger status report
  4061. //==============================================
  4062. //--- Check Mode Change ---//
  4063. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4064. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4065. {
  4066. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4067. {
  4068. tempIndex = ((gun_index==2) ? 1: 0);
  4069. }
  4070. else
  4071. {
  4072. tempIndex = gun_index;
  4073. }
  4074. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4075. {
  4076. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4077. {
  4078. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4079. {
  4080. // Sent unplug message for California pricing logic
  4081. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  4082. {
  4083. uint8_t ts[20];
  4084. getNowDatetime(ts);
  4085. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4086. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4087. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4088. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  4089. }
  4090. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4091. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4092. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4093. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4094. {
  4095. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4096. if((access(filenmae,F_OK))!=-1)
  4097. {
  4098. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4099. sprintf(str,"rm -f %s",filenmae);
  4100. system(str);
  4101. }
  4102. }
  4103. }
  4104. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4105. #if 1 // for TempStopTransaction
  4106. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4107. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4108. {
  4109. checkTempStopTransaction(gun_index);
  4110. }
  4111. #endif
  4112. }
  4113. }
  4114. }
  4115. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4116. {
  4117. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4118. {
  4119. tempIndex = ((gun_index==2) ? 1: 0);
  4120. }
  4121. else
  4122. {
  4123. tempIndex = gun_index;
  4124. }
  4125. for (int index = 0; index < CCS_QUANTITY; index++)
  4126. {
  4127. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4128. {
  4129. 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]*/ )
  4130. {
  4131. // Sent unplug message for California pricing logic
  4132. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  4133. {
  4134. uint8_t ts[20];
  4135. getNowDatetime(ts);
  4136. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4137. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4138. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4139. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  4140. }
  4141. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4142. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4143. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4144. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4145. {
  4146. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4147. if((access(filenmae,F_OK))!=-1)
  4148. {
  4149. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4150. sprintf(str,"rm -f %s",filenmae);
  4151. system(str);
  4152. }
  4153. }
  4154. }
  4155. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4156. #if 1 // for TempStopTransaction
  4157. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4158. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4159. {
  4160. checkTempStopTransaction(gun_index);
  4161. }
  4162. #endif
  4163. }
  4164. }
  4165. }
  4166. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4167. {
  4168. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4169. {
  4170. tempIndex = ((gun_index==2) ? 1: 0);
  4171. }
  4172. else
  4173. {
  4174. tempIndex = gun_index;
  4175. }
  4176. for (int index = 0; index < GB_QUANTITY; index++)
  4177. {
  4178. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4179. {
  4180. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4181. {
  4182. // Sent unplug message for California pricing logic
  4183. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  4184. {
  4185. uint8_t ts[20];
  4186. getNowDatetime(ts);
  4187. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4188. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4189. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4190. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  4191. }
  4192. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4193. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4194. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4195. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4196. {
  4197. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4198. if((access(filenmae,F_OK))!=-1)
  4199. {
  4200. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4201. sprintf(str,"rm -f %s",filenmae);
  4202. system(str);
  4203. }
  4204. }
  4205. }
  4206. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4207. #if 1 // for TempStopTransaction
  4208. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4209. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4210. {
  4211. checkTempStopTransaction(gun_index);
  4212. }
  4213. #endif
  4214. }
  4215. }
  4216. }
  4217. else if(gunType[gun_index] == GUN_TYPE_DO)
  4218. {
  4219. tempIndex = gun_index;
  4220. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4221. {
  4222. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4223. {
  4224. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4225. {
  4226. // Sent unplug message for California pricing logic
  4227. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  4228. {
  4229. uint8_t ts[20];
  4230. getNowDatetime(ts);
  4231. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4232. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4233. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4234. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  4235. }
  4236. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4237. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4238. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4239. 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
  4240. {
  4241. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4242. if((access(filenmae,F_OK))!=-1)
  4243. {
  4244. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4245. sprintf(str,"rm -f %s",filenmae);
  4246. system(str);
  4247. }
  4248. }
  4249. }
  4250. 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);
  4251. #if 1 // for TempStopTransaction
  4252. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4253. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4254. {
  4255. checkTempStopTransaction(gun_index);
  4256. }
  4257. #endif
  4258. }
  4259. }
  4260. }
  4261. else
  4262. {
  4263. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4264. {
  4265. tempIndex = 2;
  4266. }
  4267. else
  4268. {
  4269. tempIndex = gun_index;
  4270. }
  4271. for (int index = 0; index < AC_QUANTITY; index++)
  4272. {
  4273. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4274. {
  4275. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4276. {
  4277. // Sent unplug message for California pricing logic
  4278. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  4279. {
  4280. uint8_t ts[20];
  4281. getNowDatetime(ts);
  4282. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4283. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4284. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4285. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  4286. }
  4287. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4288. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4289. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4290. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4291. {
  4292. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4293. if((access(filenmae,F_OK))!=-1)
  4294. {
  4295. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4296. sprintf(str,"rm -f %s",filenmae);
  4297. system(str);
  4298. }
  4299. }
  4300. }
  4301. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4302. #if 1 // for TempStopTransaction
  4303. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4304. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4305. {
  4306. checkTempStopTransaction(gun_index);
  4307. }
  4308. #endif
  4309. }
  4310. }// END
  4311. }
  4312. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) &&
  4313. (
  4314. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4315. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4316. )
  4317. )
  4318. {
  4319. if(SystemInitial > 0)
  4320. SystemInitial -= 1;
  4321. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  4322. sendStatusNotificationRequest(gun_index);
  4323. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4324. }
  4325. //==============================================
  4326. // TCCI reader status report
  4327. //==============================================
  4328. if(ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1)
  4329. {
  4330. reportReaderStatus(gun_index);
  4331. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4332. }
  4333. //==============================================
  4334. // CSU Trigger Smart Charging Profile
  4335. //==============================================
  4336. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4337. {
  4338. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  4339. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4340. }
  4341. //==============================================
  4342. // Meter report
  4343. //==============================================
  4344. // Trigger MeterValue
  4345. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4346. {
  4347. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4348. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4349. }
  4350. // Clock-aligned Meter value
  4351. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4352. {
  4353. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4354. reqClockAlignMeter[gun_index] = 0;
  4355. }
  4356. // Sample period MeterValue
  4357. if(((getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>3?(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):3))))
  4358. {
  4359. //check Transaction active
  4360. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4361. {
  4362. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4363. {
  4364. tempIndex = ((gun_index==2) ? 1: 0);
  4365. }
  4366. else
  4367. {
  4368. tempIndex = gun_index;
  4369. }
  4370. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4371. {
  4372. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4373. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4374. {
  4375. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4376. {
  4377. reqSampleMeter[gun_index] = 1;
  4378. }
  4379. }
  4380. }// End for CHAdeMO
  4381. }
  4382. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4383. {
  4384. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4385. {
  4386. tempIndex = ((gun_index==2) ? 1: 0);
  4387. }
  4388. else
  4389. {
  4390. tempIndex = gun_index;
  4391. }
  4392. for (int index = 0; index < CCS_QUANTITY; index++)
  4393. {
  4394. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4395. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4396. {
  4397. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4398. {
  4399. reqSampleMeter[gun_index] = 1;
  4400. }
  4401. }
  4402. } // End for CCS
  4403. }
  4404. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4405. {
  4406. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4407. {
  4408. tempIndex = ((gun_index==2) ? 1: 0);
  4409. }
  4410. else
  4411. {
  4412. tempIndex = gun_index;
  4413. }
  4414. for (int index = 0; index < GB_QUANTITY; index++)
  4415. {
  4416. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4417. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4418. {
  4419. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4420. {
  4421. reqSampleMeter[gun_index] = 1;
  4422. }
  4423. }
  4424. }// End for GB
  4425. }
  4426. else if(gunType[gun_index] == GUN_TYPE_DO)
  4427. {
  4428. tempIndex = gun_index;
  4429. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4430. {
  4431. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4432. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4433. {
  4434. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4435. {
  4436. reqSampleMeter[gun_index] = 1;
  4437. }
  4438. }
  4439. }
  4440. }
  4441. else
  4442. {
  4443. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4444. {
  4445. tempIndex = 2;
  4446. }
  4447. else
  4448. {
  4449. tempIndex = gun_index;
  4450. }
  4451. for (int index = 0; index < AC_QUANTITY; index++)
  4452. {
  4453. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4454. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4455. {
  4456. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4457. {
  4458. reqSampleMeter[gun_index] = 1;
  4459. }
  4460. }
  4461. }//End for AC
  4462. }
  4463. if(reqSampleMeter[gun_index] == 1)
  4464. {
  4465. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4466. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4467. //storeTempStopTransaction(gun_index);
  4468. reqSampleMeter[gun_index] = 0;
  4469. }
  4470. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4471. }
  4472. //==============================================
  4473. // Check Connector reserved
  4474. //==============================================
  4475. //===============================
  4476. // Check if Reserve is expired
  4477. //===============================
  4478. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  4479. {
  4480. double diff_t;
  4481. struct tm tp;
  4482. // current time
  4483. time_t t = time(NULL);
  4484. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  4485. tp.tm_isdst = -1;
  4486. time_t utc = mktime(&tp);
  4487. diff_t = difftime(utc, t);
  4488. if(diff_t <= 0)
  4489. {
  4490. DEBUG_INFO("reserve expired.\n");
  4491. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  4492. }
  4493. }//END OF Check if Reserve is expired
  4494. //==========================================
  4495. // csu trigger FirmwareStatusNotificationReq
  4496. //==========================================
  4497. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4498. {
  4499. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  4500. }
  4501. //==========================================
  4502. // csu trigger DiagnosticsStatusNotificationReq
  4503. //==========================================
  4504. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4505. {
  4506. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  4507. }
  4508. //==========================================
  4509. // csu trigger CancelReservationConf
  4510. //==========================================
  4511. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4512. {
  4513. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  4514. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4515. }
  4516. //==========================================
  4517. // csu trigger ChangeAvailabilityConf
  4518. //==========================================
  4519. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4520. {
  4521. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  4522. }
  4523. //==========================================
  4524. // csu trigger UnlockConnectorConf
  4525. //==========================================
  4526. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4527. {
  4528. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  4529. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4530. }
  4531. //==========================================
  4532. // csu trigger ReserveNowConf
  4533. //==========================================
  4534. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4535. {
  4536. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  4537. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4538. }
  4539. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  4540. {
  4541. sendSignCertificateRequest();
  4542. }
  4543. }
  4544. }
  4545. //==========================================
  4546. // send request routine
  4547. //==========================================
  4548. int sendAuthorizeRequest(int gun_index)
  4549. {
  4550. mtrace();
  4551. int result = FAIL;
  4552. char message[100]={0};
  4553. char guid[37];
  4554. char tempdata[65]={0};
  4555. DEBUG_INFO("sendAuthorizeRequest...\n");
  4556. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4557. //Local Authorize
  4558. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  4559. {
  4560. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4561. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4562. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4563. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4564. result = PASS;
  4565. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4566. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4567. authorizeRetryTimes = 0;
  4568. return result;
  4569. }
  4570. else if(((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16DataPH->OcppConnStatus == 0))||
  4571. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4572. {
  4573. // Query from cache
  4574. DEBUG_INFO("Authorize from cache.\n");
  4575. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4576. // Query from list
  4577. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4578. {
  4579. DEBUG_INFO("Authorize from list.\n");
  4580. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4581. }
  4582. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4583. {
  4584. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4585. {
  4586. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4587. }
  4588. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4589. {
  4590. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4591. }
  4592. if(!GetOcppConnStatus())
  4593. {
  4594. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4595. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4596. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4597. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4598. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4599. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4600. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4601. authorizeRetryTimes = 0;
  4602. return result;
  4603. }
  4604. }
  4605. else
  4606. {
  4607. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4608. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4609. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4610. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4611. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  4612. else
  4613. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4614. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4615. result = PASS;
  4616. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4617. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4618. authorizeRetryTimes = 0;
  4619. return result;
  4620. }
  4621. }
  4622. //initialize struct Authorize
  4623. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  4624. //get data from shared memory
  4625. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4626. random_uuid(guid);
  4627. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  4628. LWS_Send(message);
  4629. sprintf(tempdata, "Authorize,%d", gun_index);
  4630. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4631. {
  4632. result = PASS;
  4633. DEBUG_INFO("Authorize mapItem pass\n");
  4634. }
  4635. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4636. return result;
  4637. }
  4638. int sendBootNotificationRequest(void)
  4639. {
  4640. mtrace();
  4641. int result = FAIL;
  4642. char message[500]={0}, payload[700]={0};
  4643. char guid[37]={0};
  4644. char tempdata[65]={0};
  4645. // Fill BootNotification fields
  4646. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  4647. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4648. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4649. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4650. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4651. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4652. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4653. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4654. ShmOCPP16DataPH->ChargeBoxId
  4655. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4656. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4657. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4658. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  4659. ,ShmOCPP16DataPH->BootNotification.CpIccid
  4660. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  4661. random_uuid(guid);
  4662. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4663. LWS_Send(message);
  4664. sprintf(tempdata, "BootNotification,0");
  4665. 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*/)
  4666. {
  4667. result = PASS;
  4668. }
  4669. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4670. strcpy(queuedata,message);
  4671. return result;
  4672. }
  4673. int sendDataTransferRequest(int gun_index)
  4674. {
  4675. mtrace();
  4676. char message[1000]={0};
  4677. char guid[37]={0};
  4678. char tempdata[65]={0};
  4679. int result = FAIL;
  4680. random_uuid(guid);
  4681. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4682. MESSAGE_TYPE_CALL,
  4683. guid,
  4684. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4685. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4686. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4687. LWS_Send(message);
  4688. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4689. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4690. {
  4691. result = PASS;
  4692. DEBUG_INFO("DataTransfer mapItem pass\n");
  4693. }
  4694. return result;
  4695. }
  4696. int sendDiagnosticsStatusNotificationRequest(char *status)
  4697. {
  4698. mtrace();
  4699. int result = FAIL;
  4700. char message[110]={0};
  4701. char guid[37]={0};
  4702. char tempdata[65]={0};
  4703. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4704. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4705. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4706. random_uuid(guid);
  4707. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4708. LWS_SendNow(message);
  4709. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4710. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4711. {
  4712. result = PASS;
  4713. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4714. }
  4715. //#ifdef SystemLogMessage
  4716. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4717. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4718. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4719. //#endif
  4720. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4721. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4722. //record status
  4723. if(strcmp(status,"Idle")==0)
  4724. {
  4725. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4726. }
  4727. else if(strcmp(status,"Uploaded")==0)
  4728. {
  4729. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4730. }
  4731. else if(strcmp(status,"UploadFailed")==0)
  4732. {
  4733. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4734. }
  4735. else if(strcmp(status,"Uploading")==0)
  4736. {
  4737. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4738. }
  4739. return result;
  4740. }
  4741. int sendFirmwareStatusNotificationRequest(char *status)
  4742. {
  4743. mtrace();
  4744. int result = FAIL;
  4745. char message[110]={0};
  4746. char guid[37]={0};
  4747. char tempdata[65]={0};
  4748. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4749. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4750. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4751. random_uuid(guid);
  4752. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4753. LWS_SendNow(message);
  4754. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4755. 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*/)
  4756. {
  4757. result = PASS;
  4758. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4759. }
  4760. //#ifdef SystemLogMessage
  4761. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4762. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4763. //#endif
  4764. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4765. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4766. //record status
  4767. if(strcmp(status,"Downloaded")==0)
  4768. {
  4769. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4770. }
  4771. else if(strcmp(status,"DownloadFailed")==0)
  4772. {
  4773. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4774. }
  4775. else if(strcmp(status,"Downloading")==0)
  4776. {
  4777. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4778. }
  4779. else if(strcmp(status,"Idle")==0)
  4780. {
  4781. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4782. }
  4783. else if(strcmp(status,"InstallationFailed")==0)
  4784. {
  4785. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4786. }
  4787. else if(strcmp(status,"Installing")==0)
  4788. {
  4789. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4790. }
  4791. else if(strcmp(status,"Installed")==0)
  4792. {
  4793. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4794. }
  4795. return result;
  4796. }
  4797. int sendHeartbeatRequest(int gun_index)
  4798. {
  4799. mtrace();
  4800. int result = FAIL;
  4801. char message[80]={0};
  4802. char guid[37]={0};
  4803. char tempdata[65]={0};
  4804. random_uuid(guid);
  4805. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4806. , MESSAGE_TYPE_CALL
  4807. , guid );
  4808. LWS_Send(message);
  4809. sprintf(tempdata, "Heartbeat,%d", 0);
  4810. 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*/)
  4811. {
  4812. result = PASS;
  4813. }
  4814. return result;
  4815. }
  4816. int sendStartTransactionRequest(int gun_index)
  4817. {
  4818. mtrace();
  4819. int result = FAIL;
  4820. char message[250]={0};
  4821. char guid[37]={0};
  4822. struct timeval tmnow;
  4823. struct tm *tm;
  4824. char buf[28];//, usec_buf[6];
  4825. char tempdata[65]={0};
  4826. int tempIndex = 0;
  4827. DEBUG_INFO("sendStartTransactionRequest...\n");
  4828. gettimeofday(&tmnow, NULL);
  4829. time_t t;
  4830. t = time(NULL);
  4831. /*UTC time and date*/
  4832. tm = gmtime(&t);
  4833. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4834. #if 0 // remove temporally
  4835. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4836. strcat(buf,".");
  4837. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4838. strcat(buf,usec_buf);
  4839. #endif
  4840. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4841. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4842. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4843. // clear StartTransaction Response
  4844. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4845. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4846. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4847. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4848. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4849. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4850. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4851. {
  4852. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4853. {
  4854. tempIndex = ((gun_index==2) ? 1: 0);
  4855. }
  4856. else
  4857. {
  4858. tempIndex = gun_index;
  4859. }
  4860. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4861. {
  4862. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4863. {
  4864. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4865. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4866. }
  4867. }
  4868. }
  4869. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4870. {
  4871. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4872. {
  4873. tempIndex = ((gun_index==2) ? 1: 0);
  4874. }
  4875. else
  4876. {
  4877. tempIndex = gun_index;
  4878. }
  4879. for (int index = 0; index < CCS_QUANTITY; index++)
  4880. {
  4881. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4882. {
  4883. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4884. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4885. }
  4886. }
  4887. }
  4888. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4889. {
  4890. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4891. {
  4892. tempIndex = ((gun_index==2) ? 1: 0);
  4893. }
  4894. else
  4895. {
  4896. tempIndex = gun_index;
  4897. }
  4898. for (int index = 0; index < GB_QUANTITY; index++)
  4899. {
  4900. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4901. {
  4902. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4903. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4904. }
  4905. }
  4906. }
  4907. else if(gunType[gun_index] == GUN_TYPE_DO)
  4908. {
  4909. tempIndex = gun_index;
  4910. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4911. {
  4912. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4913. {
  4914. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4915. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4916. }
  4917. }
  4918. }
  4919. else
  4920. {
  4921. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4922. {
  4923. tempIndex = 2;
  4924. }
  4925. else
  4926. {
  4927. tempIndex = gun_index;
  4928. }
  4929. for (int index = 0; index < AC_QUANTITY; index++)
  4930. {
  4931. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4932. {
  4933. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4934. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4935. }
  4936. }
  4937. }
  4938. random_uuid(guid);
  4939. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4940. {
  4941. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4942. , gun_index +1
  4943. , MESSAGE_TYPE_CALL
  4944. , guid
  4945. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4946. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4947. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4948. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4949. }
  4950. else
  4951. {
  4952. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4953. , gun_index +1
  4954. , MESSAGE_TYPE_CALL
  4955. , guid
  4956. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4957. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4958. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4959. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  4960. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4961. }
  4962. #if 1
  4963. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4964. 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*/)
  4965. {
  4966. result = PASS;
  4967. }
  4968. #endif
  4969. strcpy(queuedata, message);
  4970. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4971. OCPP_insert_transaction_msg(YES, queuedata);
  4972. return result;
  4973. }
  4974. int sendStatusNotificationRequest(int gun_index)
  4975. {
  4976. mtrace();
  4977. int result = FAIL;
  4978. char message[600]={0};
  4979. char guid[37];
  4980. int currentStatus = 0;
  4981. struct timeval tmnow;
  4982. struct tm *tm;
  4983. char buf[28];//, usec_buf[6];
  4984. char tempdata[65]={0};
  4985. int tempIndex = 0;
  4986. uint8_t isStateChanged = TRUE;
  4987. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4988. gettimeofday(&tmnow, NULL);
  4989. time_t t;
  4990. t = time(NULL);
  4991. /*UTC time and date*/
  4992. tm = gmtime(&t);
  4993. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4994. #if 0 // remove temporally
  4995. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4996. strcat(buf,".");
  4997. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4998. strcat(buf,usec_buf);
  4999. #endif
  5000. //printf("%s",buf);
  5001. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5002. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5003. // it's option
  5004. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  5005. /*
  5006. enum _SYSTEM_STATUS
  5007. {
  5008. S_BOOTING = 0,
  5009. S_IDLE, = 1
  5010. S_AUTHORIZING, =2
  5011. S_REASSIGN_CHECK, =3
  5012. S_REASSIGN, =4
  5013. S_PRECHARGE, =5
  5014. S_PREPARING_FOR_EV, =6
  5015. S_PREPARING_FOR_EVSE, =7
  5016. S_CHARGING, =8
  5017. S_TERMINATING, =9
  5018. S_COMPLETE, =10
  5019. S_ALARM, =11
  5020. S_FAULT =12
  5021. }
  5022. */
  5023. //check Transaction active
  5024. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5025. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5026. {
  5027. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5028. {
  5029. tempIndex = ((gun_index==2) ? 1: 0);
  5030. }
  5031. else
  5032. {
  5033. tempIndex = gun_index;
  5034. }
  5035. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5036. {
  5037. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5038. {
  5039. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5040. {
  5041. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5042. {
  5043. currentStatus = Preparing; //OCPP Status: Preparing
  5044. }
  5045. else
  5046. {
  5047. currentStatus = Available; //OCPP Status: Available
  5048. }
  5049. }
  5050. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5051. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5052. ) //S_PRECHARGE
  5053. {
  5054. currentStatus = Preparing; //OCPP Status: Preparing
  5055. }
  5056. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5057. {
  5058. currentStatus = Charging; //OCPP Status: Charging
  5059. }
  5060. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5061. {
  5062. currentStatus = Finishing; //OCPP Status: Finishing
  5063. }
  5064. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5065. {
  5066. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5067. }
  5068. 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
  5069. {
  5070. currentStatus = Unavailable; //OCPP Status: Unavailable
  5071. }
  5072. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5073. {
  5074. currentStatus = Faulted; //OCPP Status: Faulted
  5075. }
  5076. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5077. {
  5078. currentStatus = Reserved; //OCPP Status: Reserved
  5079. }
  5080. } //end of the same index
  5081. }//end of for CHAdeMO_QUANTITY
  5082. }
  5083. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5084. {
  5085. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5086. {
  5087. tempIndex = ((gun_index==2) ? 1: 0);
  5088. }
  5089. else
  5090. {
  5091. tempIndex = gun_index;
  5092. }
  5093. for (int index = 0; index < CCS_QUANTITY; index++)
  5094. {
  5095. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5096. {
  5097. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5098. {
  5099. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5100. {
  5101. currentStatus = Preparing; //OCPP Status: Preparing
  5102. }
  5103. else
  5104. {
  5105. currentStatus = Available; //OCPP Status: Available
  5106. }
  5107. }
  5108. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5109. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5110. ) //S_PRECHARGE
  5111. {
  5112. currentStatus = Preparing; //OCPP Status: Preparing
  5113. }
  5114. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5115. {
  5116. currentStatus = Charging; //OCPP Status: Charging
  5117. }
  5118. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5119. {
  5120. currentStatus = Finishing; //OCPP Status: Finishing
  5121. }
  5122. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5123. {
  5124. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5125. }
  5126. 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
  5127. {
  5128. currentStatus = Unavailable; //OCPP Status : Unavailable
  5129. }
  5130. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5131. {
  5132. currentStatus = Faulted; //OCPP Status: Faulted
  5133. }
  5134. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5135. {
  5136. currentStatus = Reserved; //OCPP Status: Reserved
  5137. }
  5138. } //end of the same index
  5139. } // end of for CCS_QUANTITY
  5140. }
  5141. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5142. {
  5143. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5144. {
  5145. tempIndex = ((gun_index==2) ? 1: 0);
  5146. }
  5147. else
  5148. {
  5149. tempIndex = gun_index;
  5150. }
  5151. for (int index = 0; index < GB_QUANTITY; index++)
  5152. {
  5153. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5154. {
  5155. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5156. {
  5157. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5158. {
  5159. currentStatus = Preparing; //OCPP Status: Preparing
  5160. }
  5161. else
  5162. {
  5163. currentStatus = Available; //OCPP Status: Available
  5164. }
  5165. }
  5166. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5167. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5168. ) //S_PRECHARGE
  5169. {
  5170. currentStatus = Preparing; //OCPP Status: Preparing
  5171. }
  5172. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5173. {
  5174. currentStatus = Charging; //OCPP Status: Charging
  5175. }
  5176. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5177. {
  5178. currentStatus = Finishing; //OCPP Status: Finishing
  5179. }
  5180. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5181. {
  5182. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5183. }
  5184. 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
  5185. {
  5186. currentStatus = Unavailable; //OCPP Status: Unavailable
  5187. }
  5188. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5189. {
  5190. currentStatus = Faulted; //OCPP Status: Faulted
  5191. }
  5192. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5193. {
  5194. currentStatus = Reserved; //OCPP Status: Reserved
  5195. }
  5196. } //end of the same index
  5197. } // end of for GB_QUANTITY
  5198. }
  5199. else if(gunType[gun_index] == GUN_TYPE_DO)
  5200. {
  5201. tempIndex = gun_index;
  5202. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5203. {
  5204. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5205. {
  5206. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5207. {
  5208. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5209. {
  5210. currentStatus = Preparing; //OCPP Status: Preparing
  5211. }
  5212. else
  5213. {
  5214. currentStatus = Available; //OCPP Status: Available
  5215. }
  5216. }
  5217. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5218. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5219. ) //S_PRECHARGE
  5220. {
  5221. currentStatus = Preparing; //OCPP Status: Preparing
  5222. }
  5223. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5224. {
  5225. currentStatus = Charging; //OCPP Status: Charging
  5226. }
  5227. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5228. {
  5229. currentStatus = Finishing; //OCPP Status: Finishing
  5230. }
  5231. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5232. {
  5233. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5234. }
  5235. 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
  5236. {
  5237. currentStatus = Unavailable; //OCPP Status: Unavailable
  5238. }
  5239. 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
  5240. {
  5241. currentStatus = Faulted; //OCPP Status: Faulted
  5242. }
  5243. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5244. {
  5245. currentStatus = Reserved; //OCPP Status: Reserved
  5246. }
  5247. } //end of the same index
  5248. }
  5249. }
  5250. else
  5251. {
  5252. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5253. {
  5254. tempIndex = 2;
  5255. }
  5256. else
  5257. {
  5258. tempIndex = gun_index;
  5259. }
  5260. for (int index = 0; index < AC_QUANTITY; index++)
  5261. {
  5262. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5263. {
  5264. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5265. {
  5266. 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))
  5267. {
  5268. currentStatus = Preparing; //OCPP Status: Preparing
  5269. }
  5270. else
  5271. {
  5272. currentStatus = Available; //OCPP Status: Available
  5273. }
  5274. }
  5275. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5276. {
  5277. currentStatus = Preparing; //OCPP Status: Preparing
  5278. }
  5279. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5280. {
  5281. currentStatus = Charging; //OCPP Status: Charging
  5282. }
  5283. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5284. {
  5285. currentStatus = Finishing; //OCPP Status: Finishing
  5286. }
  5287. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5288. {
  5289. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5290. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5291. else
  5292. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5293. }
  5294. 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
  5295. {
  5296. currentStatus = Unavailable; //OCPP Status: Unavailable
  5297. }
  5298. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5299. {
  5300. currentStatus = Faulted; //OCPP Status: Faulted
  5301. }
  5302. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5303. {
  5304. currentStatus = Reserved; //OCPP Status: Reserved
  5305. }
  5306. }//end of the same index
  5307. }//end of for AC_QUANTITY
  5308. }
  5309. //it's option
  5310. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5311. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5312. (strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5313. {
  5314. isStateChanged = FALSE;
  5315. }
  5316. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5317. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  5318. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5319. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5320. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  5321. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  5322. random_uuid(guid);
  5323. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5324. , MESSAGE_TYPE_CALL
  5325. , guid
  5326. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  5327. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  5328. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  5329. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  5330. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  5331. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  5332. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  5333. if((server_sign == TRUE) && isStateChanged)
  5334. {
  5335. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5336. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5337. LWS_Send(message);
  5338. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5339. 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*/)
  5340. {
  5341. //DEBUG_ERROR("statusNotification mapitem pass");
  5342. result = PASS;
  5343. }
  5344. }
  5345. else
  5346. {
  5347. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5348. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5349. result = PASS;
  5350. }
  5351. return result;
  5352. }
  5353. int sendStopTransactionRequest(int gun_index)
  5354. {
  5355. mtrace();
  5356. int result = FAIL;
  5357. //char message[1500]={0};
  5358. char guid[37]={0};
  5359. char tempdata[65]={0};
  5360. int tempIndex = 0;
  5361. char TempStopTransaction[256];
  5362. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  5363. //int idx_sample=0;
  5364. DEBUG_INFO("sendStopTransactionRequest \n");
  5365. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5366. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  5367. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5368. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5369. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5370. {
  5371. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5372. {
  5373. tempIndex = ((gun_index==2) ? 1: 0);
  5374. }
  5375. else
  5376. {
  5377. tempIndex = gun_index;
  5378. }
  5379. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5380. {
  5381. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5382. {
  5383. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5384. }
  5385. }// END OF CHAdeMO_QUANTITY
  5386. }
  5387. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5388. {
  5389. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5390. {
  5391. tempIndex = ((gun_index==2) ? 1: 0);
  5392. }
  5393. else
  5394. {
  5395. tempIndex = gun_index;
  5396. }
  5397. for (int index = 0; index < CCS_QUANTITY; index++)
  5398. {
  5399. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5400. {
  5401. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5402. }
  5403. }// END OF CCS_QUANTITY
  5404. }
  5405. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5406. {
  5407. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5408. {
  5409. tempIndex = ((gun_index==2) ? 1: 0);
  5410. }
  5411. else
  5412. {
  5413. tempIndex = gun_index;
  5414. }
  5415. for (int index = 0; index < GB_QUANTITY; index++)
  5416. {
  5417. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5418. {
  5419. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5420. }
  5421. }// END OF GB_QUANTITY
  5422. }
  5423. else if(gunType[gun_index] == GUN_TYPE_DO)
  5424. {
  5425. tempIndex = gun_index;
  5426. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5427. {
  5428. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5429. {
  5430. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5431. }
  5432. }// END OF GB_QUANTITY
  5433. }
  5434. else
  5435. {
  5436. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5437. {
  5438. tempIndex = 2;
  5439. }
  5440. else
  5441. {
  5442. tempIndex = gun_index;
  5443. }
  5444. for (int index = 0; index < AC_QUANTITY; index++)
  5445. {
  5446. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5447. {
  5448. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5449. }
  5450. }// END OF AC_QUANTITY
  5451. }
  5452. //====================================== Stop Transaction Time =====================================================
  5453. struct timeval tmnow;
  5454. struct tm *tm;
  5455. char buf[28];//, usec_buf[6];
  5456. gettimeofday(&tmnow, NULL);
  5457. time_t t;
  5458. t = time(NULL);
  5459. /*UTC time and date*/
  5460. tm = gmtime(&t);
  5461. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5462. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  5463. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  5464. random_uuid(guid);
  5465. /***********************************transactionData******************************************************/
  5466. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5467. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5468. //=================================
  5469. // Transaction_Begin
  5470. //=================================
  5471. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5472. {
  5473. //============================================ Energy.Active.Import.Interval ================================
  5474. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5475. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5476. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5477. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  5478. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5479. 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))
  5480. {
  5481. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5482. }
  5483. else
  5484. {
  5485. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5486. }
  5487. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5488. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5489. }
  5490. //=================================
  5491. // Transaction_End
  5492. //=================================
  5493. // ================================= Current.Import L1 ===============================================
  5494. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5495. {
  5496. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5497. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5498. {
  5499. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5500. {
  5501. tempIndex = ((gun_index==2) ? 1: 0);
  5502. }
  5503. else
  5504. {
  5505. tempIndex = gun_index;
  5506. }
  5507. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5508. {
  5509. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5510. {
  5511. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5512. }
  5513. }// End of for CHAdeMO_QUANTITY
  5514. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5515. }
  5516. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5517. {
  5518. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5519. {
  5520. tempIndex = ((gun_index==2) ? 1: 0);
  5521. }
  5522. else
  5523. {
  5524. tempIndex = gun_index;
  5525. }
  5526. for (int index = 0; index < CCS_QUANTITY; index++)
  5527. {
  5528. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5529. {
  5530. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5531. }
  5532. }// End of for CCS_QUANTITY
  5533. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5534. }
  5535. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5536. {
  5537. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5538. {
  5539. tempIndex = ((gun_index==2) ? 1: 0);
  5540. }
  5541. else
  5542. {
  5543. tempIndex = gun_index;
  5544. }
  5545. for (int index = 0; index < GB_QUANTITY; index++)
  5546. {
  5547. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5548. {
  5549. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5550. }
  5551. }// End of for GB_QUANTITY
  5552. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5553. }
  5554. else if(gunType[gun_index] == GUN_TYPE_DO)
  5555. {
  5556. tempIndex = gun_index;
  5557. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5558. {
  5559. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5560. {
  5561. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5562. }
  5563. }
  5564. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5565. }
  5566. else
  5567. {
  5568. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5569. {
  5570. tempIndex = 2;
  5571. }
  5572. else
  5573. {
  5574. tempIndex = gun_index;
  5575. }
  5576. for (int index = 0; index < AC_QUANTITY; index++)
  5577. {
  5578. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5579. {
  5580. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5581. }
  5582. }// End of for AC_QUANTITY
  5583. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5584. }
  5585. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5586. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5587. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5588. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5589. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5590. }
  5591. // ================================= Energy.Active.Import.Interval ==============================================
  5592. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5593. {
  5594. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5595. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5596. {
  5597. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5598. {
  5599. tempIndex = ((gun_index==2) ? 1: 0);
  5600. }
  5601. else
  5602. {
  5603. tempIndex = gun_index;
  5604. }
  5605. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5606. {
  5607. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5608. {
  5609. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5610. }
  5611. }// END OF CHAdeMO_QUANTITY
  5612. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5613. }
  5614. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5615. {
  5616. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5617. {
  5618. tempIndex = ((gun_index==2) ? 1: 0);
  5619. }
  5620. else
  5621. {
  5622. tempIndex = gun_index;
  5623. }
  5624. for (int index = 0; index < CCS_QUANTITY; index++)
  5625. {
  5626. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5627. {
  5628. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5629. }
  5630. }// END OF CCS_QUANTITY
  5631. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5632. }
  5633. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5634. {
  5635. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5636. {
  5637. tempIndex = ((gun_index==2) ? 1: 0);
  5638. }
  5639. else
  5640. {
  5641. tempIndex = gun_index;
  5642. }
  5643. for (int index = 0; index < GB_QUANTITY; index++)
  5644. {
  5645. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5646. {
  5647. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5648. }
  5649. }// END OF GB_QUANTITY
  5650. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5651. }
  5652. else if(gunType[gun_index] == GUN_TYPE_DO)
  5653. {
  5654. tempIndex = gun_index;
  5655. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5656. {
  5657. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5658. {
  5659. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5660. }
  5661. }
  5662. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5663. }
  5664. else
  5665. {
  5666. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5667. {
  5668. tempIndex = 2;
  5669. }
  5670. else
  5671. {
  5672. tempIndex = gun_index;
  5673. }
  5674. for (int index = 0; index < AC_QUANTITY; index++)
  5675. {
  5676. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5677. {
  5678. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5679. }
  5680. }// END OF AC_QUANTITY
  5681. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5682. }
  5683. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5684. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5685. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5686. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5687. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5688. }
  5689. //=================================== Power.Active.Import ==================================================
  5690. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5691. {
  5692. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5693. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5694. {
  5695. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5696. {
  5697. tempIndex = ((gun_index==2) ? 1: 0);
  5698. }
  5699. else
  5700. {
  5701. tempIndex = gun_index;
  5702. }
  5703. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5704. {
  5705. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5706. {
  5707. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5708. }
  5709. } // End for CHAdeMO_QUANTITY
  5710. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5711. }
  5712. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5713. {
  5714. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5715. {
  5716. tempIndex = ((gun_index==2) ? 1: 0);
  5717. }
  5718. else
  5719. {
  5720. tempIndex = gun_index;
  5721. }
  5722. for (int index = 0; index < CCS_QUANTITY; index++)
  5723. {
  5724. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5725. {
  5726. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5727. }
  5728. } // END for CCS_QUANTITY
  5729. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5730. }
  5731. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5732. {
  5733. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5734. {
  5735. tempIndex = ((gun_index==2) ? 1: 0);
  5736. }
  5737. else
  5738. {
  5739. tempIndex = gun_index;
  5740. }
  5741. for (int index = 0; index < GB_QUANTITY; index++)
  5742. {
  5743. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5744. {
  5745. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5746. }
  5747. }// END for GB_QUANTITY
  5748. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5749. }
  5750. else if(gunType[gun_index] == GUN_TYPE_DO)
  5751. {
  5752. tempIndex = gun_index;
  5753. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5754. {
  5755. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5756. {
  5757. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5758. }
  5759. }
  5760. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5761. }
  5762. else
  5763. {
  5764. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5765. {
  5766. tempIndex = 2;
  5767. }
  5768. else
  5769. {
  5770. tempIndex = gun_index;
  5771. }
  5772. for (int index = 0; index < AC_QUANTITY; index++)
  5773. {
  5774. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5775. {
  5776. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5777. }
  5778. } // END for AC_QUANTITY
  5779. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5780. }
  5781. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5782. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5783. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5784. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5785. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5786. }
  5787. //============================ Voltage L1 ====================================
  5788. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5789. {
  5790. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5791. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5792. {
  5793. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5794. {
  5795. tempIndex = ((gun_index==2) ? 1: 0);
  5796. }
  5797. else
  5798. {
  5799. tempIndex = gun_index;
  5800. }
  5801. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5802. {
  5803. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5804. {
  5805. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5806. }
  5807. } // END OF FOR CHAdeMO_QUANTITY
  5808. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5809. }
  5810. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5811. {
  5812. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5813. {
  5814. tempIndex = ((gun_index==2) ? 1: 0);
  5815. }
  5816. else
  5817. {
  5818. tempIndex = gun_index;
  5819. }
  5820. for (int index = 0; index < CCS_QUANTITY; index++)
  5821. {
  5822. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5823. {
  5824. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5825. }
  5826. } // END OF FOR CCS_QUANTITY
  5827. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5828. }
  5829. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5830. {
  5831. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5832. {
  5833. tempIndex = ((gun_index==2) ? 1: 0);
  5834. }
  5835. else
  5836. {
  5837. tempIndex = gun_index;
  5838. }
  5839. for (int index = 0; index < GB_QUANTITY; index++)
  5840. {
  5841. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5842. {
  5843. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5844. }
  5845. } // END OF FOR GB_QUANTITY
  5846. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5847. }
  5848. else if(gunType[gun_index] == GUN_TYPE_DO)
  5849. {
  5850. tempIndex = gun_index;
  5851. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5852. {
  5853. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5854. {
  5855. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5856. }
  5857. }
  5858. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5859. }
  5860. else
  5861. {
  5862. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5863. {
  5864. tempIndex = 2;
  5865. }
  5866. else
  5867. {
  5868. tempIndex = gun_index;
  5869. }
  5870. for (int index = 0; index < AC_QUANTITY; index++)
  5871. {
  5872. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5873. {
  5874. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  5875. }
  5876. } // END OF FOR AC_QUANTITY
  5877. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5878. }
  5879. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5880. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5881. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5882. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5883. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5884. }
  5885. //====================== End SoC ================================
  5886. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5887. {
  5888. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5889. 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))
  5890. {
  5891. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5892. {
  5893. tempIndex = ((gun_index==2) ? 1: 0);
  5894. }
  5895. else
  5896. {
  5897. tempIndex = gun_index;
  5898. }
  5899. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5900. {
  5901. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5902. {
  5903. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5904. {
  5905. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5906. }
  5907. }
  5908. }
  5909. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5910. {
  5911. for (int index = 0; index < CCS_QUANTITY; index++)
  5912. {
  5913. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5914. {
  5915. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5916. }
  5917. }
  5918. }
  5919. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5920. {
  5921. for (int index = 0; index < GB_QUANTITY; index++)
  5922. {
  5923. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5924. {
  5925. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5926. }
  5927. }
  5928. }
  5929. else if(gunType[gun_index] == GUN_TYPE_DO)
  5930. {
  5931. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5932. {
  5933. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5934. {
  5935. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5936. }
  5937. }
  5938. }
  5939. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5940. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5941. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5942. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5943. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5944. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5945. } // END FOR DC CASE
  5946. }
  5947. // ================================= Current.Import L2 ===============================================
  5948. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5949. {
  5950. // AC 3 phse L2 current
  5951. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5952. {
  5953. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5954. {
  5955. tempIndex = 2;
  5956. }
  5957. else
  5958. {
  5959. tempIndex = gun_index;
  5960. }
  5961. for (int index = 0; index < AC_QUANTITY; index++)
  5962. {
  5963. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5964. {
  5965. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5966. }
  5967. }// End of for AC_QUANTITY
  5968. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5969. }
  5970. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5971. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5972. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5973. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5974. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5975. }
  5976. // ================================= Current.Import L3 ===============================================
  5977. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5978. {
  5979. // AC 3 phse L3 current
  5980. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5981. {
  5982. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5983. {
  5984. tempIndex = 2;
  5985. }
  5986. else
  5987. {
  5988. tempIndex = gun_index;
  5989. }
  5990. for (int index = 0; index < AC_QUANTITY; index++)
  5991. {
  5992. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5993. {
  5994. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5995. }
  5996. }// End of for AC_QUANTITY
  5997. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5998. }
  5999. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6000. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6001. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6002. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6003. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6004. }
  6005. //============================ Voltage L2 ====================================
  6006. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6007. {
  6008. // AC 3 phse L2 voltage
  6009. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6010. {
  6011. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6012. {
  6013. tempIndex = 2;
  6014. }
  6015. else
  6016. {
  6017. tempIndex = gun_index;
  6018. }
  6019. for (int index = 0; index < AC_QUANTITY; index++)
  6020. {
  6021. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6022. {
  6023. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  6024. }
  6025. } // END OF FOR AC_QUANTITY
  6026. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6027. }
  6028. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6029. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6030. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6031. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6032. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6033. }
  6034. //============================ Voltage L3 ====================================
  6035. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6036. {
  6037. // AC 3 phse L3 voltage
  6038. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6039. {
  6040. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6041. {
  6042. tempIndex = 2;
  6043. }
  6044. else
  6045. {
  6046. tempIndex = gun_index;
  6047. }
  6048. for (int index = 0; index < AC_QUANTITY; index++)
  6049. {
  6050. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6051. {
  6052. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  6053. }
  6054. } // END OF FOR AC_QUANTITY
  6055. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6056. }
  6057. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6058. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6059. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6060. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6061. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6062. }
  6063. //====================== Start SoC ================================
  6064. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6065. {
  6066. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6067. 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))
  6068. {
  6069. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6070. {
  6071. tempIndex = ((gun_index==2) ? 1: 0);
  6072. }
  6073. else
  6074. {
  6075. tempIndex = gun_index;
  6076. }
  6077. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6078. {
  6079. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6080. {
  6081. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6082. {
  6083. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6084. }
  6085. }
  6086. }
  6087. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6088. {
  6089. for (int index = 0; index < CCS_QUANTITY; index++)
  6090. {
  6091. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6092. {
  6093. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6094. }
  6095. }
  6096. }
  6097. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6098. {
  6099. for (int index = 0; index < GB_QUANTITY; index++)
  6100. {
  6101. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6102. {
  6103. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6104. }
  6105. }
  6106. }
  6107. else if(gunType[gun_index] == GUN_TYPE_DO)
  6108. {
  6109. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6110. {
  6111. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6112. {
  6113. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6114. }
  6115. }
  6116. }
  6117. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6118. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6119. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6120. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6121. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6122. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6123. } // END FOR DC CASE
  6124. }
  6125. //================================================ Message create ====================================================
  6126. json_object *StopTransaction = json_object_new_object();
  6127. json_object *transactionDatas = json_object_new_array();
  6128. json_object *sampledValues = json_object_new_array();
  6129. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  6130. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  6131. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  6132. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  6133. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  6134. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  6135. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  6136. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  6137. {
  6138. json_object *transactionData = json_object_new_object();
  6139. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6140. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6141. {
  6142. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6143. {
  6144. json_object *sampledValue = json_object_new_object();
  6145. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6146. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6147. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6148. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6149. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6150. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6151. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6152. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6153. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6154. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6155. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6156. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6157. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6158. json_object_array_add(sampledValues, sampledValue);
  6159. }
  6160. }
  6161. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6162. json_object_array_add(transactionDatas, transactionData);
  6163. }
  6164. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6165. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6166. ,MESSAGE_TYPE_CALL
  6167. ,guid
  6168. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6169. json_object_put(StopTransaction);
  6170. #if 1 // for TempStopTransaction
  6171. //Delete TempStopTransaction
  6172. if((access(TempStopTransaction,F_OK))!=-1)
  6173. {
  6174. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6175. }
  6176. #endif
  6177. #if 1
  6178. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6179. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6180. {
  6181. result = PASS;
  6182. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6183. }
  6184. #endif
  6185. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6186. OCPP_insert_transaction_msg(NO, queuedata);
  6187. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6188. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  6189. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  6190. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6191. {
  6192. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  6193. }
  6194. //for test
  6195. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6196. return result;
  6197. }
  6198. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6199. {
  6200. mtrace();
  6201. int result = FAIL;
  6202. char guid[37]={0};
  6203. char tempdata[65]={0};
  6204. int tempIndex = 0;
  6205. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6206. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6207. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6208. //set value
  6209. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6210. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6211. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  6212. -1);
  6213. random_uuid(guid);
  6214. //UTC Date time
  6215. struct timeval tmnow;
  6216. struct tm *tm;
  6217. char buf[28];//, usec_buf[6];
  6218. gettimeofday(&tmnow, NULL);
  6219. time_t t;
  6220. t = time(NULL);
  6221. /*UTC time and date*/
  6222. tm = gmtime(&t);
  6223. if(dataType == ReadingContext_Sample_Clock)
  6224. {
  6225. struct tm *tmTarget;
  6226. struct timeb tbTarget;
  6227. tbTarget.time = mktime(tm);
  6228. tbTarget.time -= (atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6229. tmTarget = gmtime(&tbTarget.time);
  6230. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6231. }
  6232. else
  6233. {
  6234. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6235. }
  6236. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6237. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6238. //********************************(1)Current.Import L1************************************************/
  6239. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6240. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6241. (dataType == ReadingContext_Trigger))
  6242. {
  6243. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6244. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6245. {
  6246. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6247. {
  6248. tempIndex = ((gun_index==2) ? 1: 0);
  6249. }
  6250. else
  6251. {
  6252. tempIndex = gun_index;
  6253. }
  6254. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6255. {
  6256. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6257. {
  6258. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6259. }
  6260. }
  6261. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6262. }
  6263. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6264. {
  6265. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6266. {
  6267. tempIndex = ((gun_index==2) ? 1: 0);
  6268. }
  6269. else
  6270. {
  6271. tempIndex = gun_index;
  6272. }
  6273. for (int index = 0; index < CCS_QUANTITY; index++)
  6274. {
  6275. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6276. {
  6277. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6278. }
  6279. }
  6280. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6281. }
  6282. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6283. {
  6284. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6285. {
  6286. tempIndex = ((gun_index==2) ? 1: 0);
  6287. }
  6288. else
  6289. {
  6290. tempIndex = gun_index;
  6291. }
  6292. for (int index = 0; index < GB_QUANTITY; index++)
  6293. {
  6294. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6295. {
  6296. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6297. }
  6298. }
  6299. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6300. }
  6301. else if(gunType[gun_index] == GUN_TYPE_DO)
  6302. {
  6303. tempIndex = gun_index;
  6304. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6305. {
  6306. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6307. {
  6308. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6309. }
  6310. }
  6311. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6312. }
  6313. else
  6314. {
  6315. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6316. {
  6317. tempIndex = 2;
  6318. }
  6319. else
  6320. {
  6321. tempIndex = gun_index;
  6322. }
  6323. for (int index = 0; index < AC_QUANTITY; index++)
  6324. {
  6325. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6326. {
  6327. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6328. }
  6329. }
  6330. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6331. }
  6332. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6333. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6334. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6335. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6336. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6337. }
  6338. //********************************(2)Energy.Active.Import.Register ************************************************/
  6339. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6340. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6341. (dataType == ReadingContext_Trigger))
  6342. {
  6343. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6344. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6345. {
  6346. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6347. {
  6348. tempIndex = ((gun_index==2) ? 1: 0);
  6349. }
  6350. else
  6351. {
  6352. tempIndex = gun_index;
  6353. }
  6354. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6355. {
  6356. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6357. {
  6358. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6359. }
  6360. }
  6361. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6362. }
  6363. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6364. {
  6365. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6366. {
  6367. tempIndex = ((gun_index==2) ? 1: 0);
  6368. }
  6369. else
  6370. {
  6371. tempIndex = gun_index;
  6372. }
  6373. for (int index = 0; index < CCS_QUANTITY; index++)
  6374. {
  6375. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6376. {
  6377. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6378. }
  6379. }
  6380. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6381. }
  6382. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6383. {
  6384. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6385. {
  6386. tempIndex = ((gun_index==2) ? 1: 0);
  6387. }
  6388. else
  6389. {
  6390. tempIndex = gun_index;
  6391. }
  6392. for (int index = 0; index < GB_QUANTITY; index++)
  6393. {
  6394. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6395. {
  6396. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6397. }
  6398. }
  6399. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6400. }
  6401. else if(gunType[gun_index] == GUN_TYPE_DO)
  6402. {
  6403. tempIndex = gun_index;
  6404. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6405. {
  6406. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6407. {
  6408. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6409. }
  6410. }
  6411. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6412. }
  6413. else
  6414. {
  6415. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6416. {
  6417. tempIndex = 2;
  6418. }
  6419. else
  6420. {
  6421. tempIndex = gun_index;
  6422. }
  6423. for (int index = 0; index < AC_QUANTITY; index++)
  6424. {
  6425. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6426. {
  6427. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6428. }
  6429. }
  6430. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6431. }
  6432. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6433. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6434. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6435. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6436. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6437. }
  6438. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6439. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6440. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6441. (dataType == ReadingContext_Trigger))
  6442. {
  6443. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6444. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6445. {
  6446. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6447. {
  6448. tempIndex = ((gun_index==2) ? 1: 0);
  6449. }
  6450. else
  6451. {
  6452. tempIndex = gun_index;
  6453. }
  6454. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6455. {
  6456. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6457. {
  6458. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6459. }
  6460. } // END OF FOR CHAdeMO_QUANTITY
  6461. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6462. }
  6463. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6464. {
  6465. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6466. {
  6467. tempIndex = ((gun_index==2) ? 1: 0);
  6468. }
  6469. else
  6470. {
  6471. tempIndex = gun_index;
  6472. }
  6473. for (int index = 0; index < CCS_QUANTITY; index++)
  6474. {
  6475. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6476. {
  6477. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6478. }
  6479. } // END OF CCS_QUANTITY
  6480. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6481. }
  6482. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6483. {
  6484. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6485. {
  6486. tempIndex = ((gun_index==2) ? 1: 0);
  6487. }
  6488. else
  6489. {
  6490. tempIndex = gun_index;
  6491. }
  6492. for (int index = 0; index < GB_QUANTITY; index++)
  6493. {
  6494. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6495. {
  6496. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6497. }
  6498. } // END OF GB_QUANTITY
  6499. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6500. }
  6501. else if(gunType[gun_index] == GUN_TYPE_DO)
  6502. {
  6503. tempIndex = gun_index;
  6504. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6505. {
  6506. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6507. {
  6508. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6509. }
  6510. }
  6511. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6512. }
  6513. else
  6514. {
  6515. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6516. {
  6517. tempIndex = 2;
  6518. }
  6519. else
  6520. {
  6521. tempIndex = gun_index;
  6522. }
  6523. for (int index = 0; index < AC_QUANTITY; index++)
  6524. {
  6525. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6526. {
  6527. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6528. }
  6529. }
  6530. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6531. }
  6532. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6533. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6534. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6535. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6536. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6537. }
  6538. //********************************(4)Power.Active.Import************************************************/
  6539. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6540. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6541. (dataType == ReadingContext_Trigger))
  6542. {
  6543. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6544. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6545. {
  6546. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6547. {
  6548. tempIndex = ((gun_index==2) ? 1: 0);
  6549. }
  6550. else
  6551. {
  6552. tempIndex = gun_index;
  6553. }
  6554. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6555. {
  6556. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6557. {
  6558. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6559. }
  6560. } // END OF FOR
  6561. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6562. }
  6563. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6564. {
  6565. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6566. {
  6567. tempIndex = ((gun_index==2) ? 1: 0);
  6568. }
  6569. else
  6570. {
  6571. tempIndex = gun_index;
  6572. }
  6573. for (int index = 0; index < CCS_QUANTITY; index++)
  6574. {
  6575. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6576. {
  6577. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6578. }
  6579. }
  6580. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6581. }
  6582. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6583. {
  6584. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6585. {
  6586. tempIndex = ((gun_index==2) ? 1: 0);
  6587. }
  6588. else
  6589. {
  6590. tempIndex = gun_index;
  6591. }
  6592. for (int index = 0; index < GB_QUANTITY; index++)
  6593. {
  6594. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6595. {
  6596. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6597. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6598. }
  6599. }
  6600. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6601. }
  6602. else if(gunType[gun_index] == GUN_TYPE_DO)
  6603. {
  6604. tempIndex = gun_index;
  6605. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6606. {
  6607. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6608. {
  6609. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6610. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6611. }
  6612. }
  6613. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6614. }
  6615. else
  6616. {
  6617. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6618. {
  6619. tempIndex = 2;
  6620. }
  6621. else
  6622. {
  6623. tempIndex = gun_index;
  6624. }
  6625. for (int index = 0; index < AC_QUANTITY; index++)
  6626. {
  6627. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6628. {
  6629. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6630. }
  6631. }
  6632. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6633. }
  6634. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6635. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6636. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6637. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6638. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6639. }
  6640. //***********************************************(5)VOLTAGE L1******************************************************/
  6641. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6642. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6643. (dataType == ReadingContext_Trigger))
  6644. {
  6645. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6646. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6647. {
  6648. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6649. {
  6650. tempIndex = ((gun_index==2) ? 1: 0);
  6651. }
  6652. else
  6653. {
  6654. tempIndex = gun_index;
  6655. }
  6656. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6657. {
  6658. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6659. {
  6660. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6661. }
  6662. }
  6663. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6664. }
  6665. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6666. {
  6667. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6668. {
  6669. tempIndex = ((gun_index==2) ? 1: 0);
  6670. }
  6671. else
  6672. {
  6673. tempIndex = gun_index;
  6674. }
  6675. for (int index = 0; index < CCS_QUANTITY; index++)
  6676. {
  6677. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6678. {
  6679. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6680. }
  6681. }
  6682. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6683. }
  6684. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6685. {
  6686. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6687. {
  6688. tempIndex = ((gun_index==2) ? 1: 0);
  6689. }
  6690. else
  6691. {
  6692. tempIndex = gun_index;
  6693. }
  6694. for (int index = 0; index < GB_QUANTITY; index++)
  6695. {
  6696. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6697. {
  6698. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6699. }
  6700. }
  6701. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6702. }
  6703. else if(gunType[gun_index] == GUN_TYPE_DO)
  6704. {
  6705. tempIndex = gun_index;
  6706. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6707. {
  6708. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6709. {
  6710. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6711. }
  6712. }
  6713. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6714. }
  6715. else
  6716. {
  6717. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6718. {
  6719. tempIndex = 2;
  6720. }
  6721. else
  6722. {
  6723. tempIndex = gun_index;
  6724. }
  6725. for (int index = 0; index < AC_QUANTITY; index++)
  6726. {
  6727. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6728. {
  6729. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6730. }
  6731. }
  6732. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6733. }
  6734. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6735. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6736. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6737. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6738. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6739. }
  6740. //***********************************************(6)SOC******************************************************/
  6741. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6742. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6743. (dataType == ReadingContext_Trigger))
  6744. {
  6745. 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))
  6746. {
  6747. //idx_sample=5;
  6748. //sampledValue = NULL;
  6749. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6750. {
  6751. tempIndex = ((gun_index==2) ? 1: 0);
  6752. }
  6753. else
  6754. {
  6755. tempIndex = gun_index;
  6756. }
  6757. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6758. {
  6759. //tempIndex = ((gun_index==2) ? 1: 0);
  6760. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6761. {
  6762. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6763. {
  6764. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6765. }
  6766. }
  6767. }
  6768. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6769. {
  6770. //tempIndex = ((gun_index==2) ? 1: 0);
  6771. for (int index = 0; index < CCS_QUANTITY; index++)
  6772. {
  6773. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6774. {
  6775. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6776. }
  6777. }
  6778. }
  6779. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6780. {
  6781. //tempIndex = ((gun_index==2) ? 1: 0);
  6782. for (int index = 0; index < GB_QUANTITY; index++)
  6783. {
  6784. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6785. {
  6786. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6787. }
  6788. }
  6789. }
  6790. else if(gunType[gun_index] == GUN_TYPE_DO)
  6791. {
  6792. //tempIndex = ((gun_index==2) ? 1: 0);
  6793. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6794. {
  6795. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6796. {
  6797. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6798. }
  6799. }
  6800. }
  6801. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6802. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6803. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6804. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6805. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6806. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6807. }
  6808. }
  6809. //********************************(7)Current.Import L2************************************************/
  6810. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6811. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6812. (dataType == ReadingContext_Trigger))
  6813. {
  6814. // Only for AC 3 phase
  6815. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6816. {
  6817. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6818. {
  6819. tempIndex = 2;
  6820. }
  6821. else
  6822. {
  6823. tempIndex = gun_index;
  6824. }
  6825. for (int index = 0; index < AC_QUANTITY; index++)
  6826. {
  6827. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6828. {
  6829. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6830. }
  6831. }
  6832. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6833. }
  6834. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6835. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6836. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6837. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6838. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6839. }
  6840. //********************************(8)Current.Import L3************************************************/
  6841. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6842. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6843. (dataType == ReadingContext_Trigger))
  6844. {
  6845. // Only for AC 3 phase
  6846. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6847. {
  6848. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6849. {
  6850. tempIndex = 2;
  6851. }
  6852. else
  6853. {
  6854. tempIndex = gun_index;
  6855. }
  6856. for (int index = 0; index < AC_QUANTITY; index++)
  6857. {
  6858. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6859. {
  6860. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6861. }
  6862. }
  6863. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6864. }
  6865. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6866. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6867. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6868. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6869. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6870. }
  6871. //***********************************************(9)VOLTAGE L2******************************************************/
  6872. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6873. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6874. (dataType == ReadingContext_Trigger))
  6875. {
  6876. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6877. {
  6878. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6879. {
  6880. tempIndex = 2;
  6881. }
  6882. else
  6883. {
  6884. tempIndex = gun_index;
  6885. }
  6886. for (int index = 0; index < AC_QUANTITY; index++)
  6887. {
  6888. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6889. {
  6890. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6891. }
  6892. }
  6893. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6894. }
  6895. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6896. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6897. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6898. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6899. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6900. }
  6901. //***********************************************(10)VOLTAGE L3******************************************************/
  6902. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6903. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6904. (dataType == ReadingContext_Trigger))
  6905. {
  6906. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6907. {
  6908. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6909. {
  6910. tempIndex = 2;
  6911. }
  6912. else
  6913. {
  6914. tempIndex = gun_index;
  6915. }
  6916. for (int index = 0; index < AC_QUANTITY; index++)
  6917. {
  6918. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6919. {
  6920. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6921. }
  6922. }
  6923. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6924. }
  6925. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6926. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6927. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6928. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6929. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6930. }
  6931. //***********************************************(11)Current.Offered******************************************************/
  6932. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6933. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6934. (dataType == ReadingContext_Trigger))
  6935. {
  6936. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6937. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6938. {
  6939. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6940. {
  6941. tempIndex = ((gun_index==2) ? 1: 0);
  6942. }
  6943. else
  6944. {
  6945. tempIndex = gun_index;
  6946. }
  6947. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6948. {
  6949. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6950. {
  6951. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  6952. }
  6953. } // END OF FOR CHAdeMO_QUANTITY
  6954. }
  6955. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6956. {
  6957. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6958. {
  6959. tempIndex = ((gun_index==2) ? 1: 0);
  6960. }
  6961. else
  6962. {
  6963. tempIndex = gun_index;
  6964. }
  6965. for (int index = 0; index < CCS_QUANTITY; index++)
  6966. {
  6967. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6968. {
  6969. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  6970. }
  6971. } // END OF CCS_QUANTITY
  6972. }
  6973. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6974. {
  6975. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6976. {
  6977. tempIndex = ((gun_index==2) ? 1: 0);
  6978. }
  6979. else
  6980. {
  6981. tempIndex = gun_index;
  6982. }
  6983. for (int index = 0; index < GB_QUANTITY; index++)
  6984. {
  6985. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6986. {
  6987. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  6988. }
  6989. } // END OF GB_QUANTITY
  6990. }
  6991. else if(gunType[gun_index] == GUN_TYPE_DO)
  6992. {
  6993. tempIndex = gun_index;
  6994. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6995. {
  6996. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6997. {
  6998. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  6999. }
  7000. }
  7001. }
  7002. else
  7003. {
  7004. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7005. {
  7006. tempIndex = 2;
  7007. }
  7008. else
  7009. {
  7010. tempIndex = gun_index;
  7011. }
  7012. for (int index = 0; index < AC_QUANTITY; index++)
  7013. {
  7014. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7015. {
  7016. uint16_t currentOffer;
  7017. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7018. {
  7019. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7020. }
  7021. else
  7022. {
  7023. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7024. }
  7025. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7026. }
  7027. }
  7028. }
  7029. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7030. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7031. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7032. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7033. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7034. }
  7035. //***********************************************(12)Power.Offered******************************************************/
  7036. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7037. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7038. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7039. {
  7040. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7041. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7042. {
  7043. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7044. {
  7045. tempIndex = ((gun_index==2) ? 1: 0);
  7046. }
  7047. else
  7048. {
  7049. tempIndex = gun_index;
  7050. }
  7051. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7052. {
  7053. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7054. {
  7055. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  7056. }
  7057. } // END OF FOR CHAdeMO_QUANTITY
  7058. }
  7059. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7060. {
  7061. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7062. {
  7063. tempIndex = ((gun_index==2) ? 1: 0);
  7064. }
  7065. else
  7066. {
  7067. tempIndex = gun_index;
  7068. }
  7069. for (int index = 0; index < CCS_QUANTITY; index++)
  7070. {
  7071. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7072. {
  7073. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  7074. }
  7075. } // END OF CCS_QUANTITY
  7076. }
  7077. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7078. {
  7079. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7080. {
  7081. tempIndex = ((gun_index==2) ? 1: 0);
  7082. }
  7083. else
  7084. {
  7085. tempIndex = gun_index;
  7086. }
  7087. for (int index = 0; index < GB_QUANTITY; index++)
  7088. {
  7089. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7090. {
  7091. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  7092. }
  7093. } // END OF GB_QUANTITY
  7094. }
  7095. else if(gunType[gun_index] == GUN_TYPE_DO)
  7096. {
  7097. tempIndex = gun_index;
  7098. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7099. {
  7100. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7101. {
  7102. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  7103. }
  7104. }
  7105. }
  7106. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7107. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7108. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7109. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7110. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7111. }
  7112. // Message create ====================================================================================================
  7113. if(TRUE)
  7114. {
  7115. json_object *MeterValueReq = json_object_new_object();
  7116. json_object *MeterValues = json_object_new_array();
  7117. json_object *sampledValues = json_object_new_array();
  7118. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  7119. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  7120. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  7121. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  7122. {
  7123. json_object *MeterValue = json_object_new_object();
  7124. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7125. {
  7126. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7127. {
  7128. json_object *sampledValue = json_object_new_object();
  7129. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7130. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7131. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7132. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7133. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7134. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7135. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7136. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7137. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7138. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7139. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7140. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7141. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7142. json_object_array_add(sampledValues, sampledValue);
  7143. }
  7144. }
  7145. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7146. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7147. json_object_array_add(MeterValues, MeterValue);
  7148. }
  7149. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7150. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7151. ,gun_index + 1
  7152. ,MESSAGE_TYPE_CALL
  7153. ,guid
  7154. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7155. json_object_put(MeterValueReq);
  7156. }
  7157. // Put request guid to hash map
  7158. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7159. 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*/)
  7160. {
  7161. result = PASS;
  7162. //DEBUG_INFO("MeterValues mapitem pass\n");
  7163. }
  7164. if((dataType != ReadingContext_Trigger) &&
  7165. (dataType != ReadingContext_Sample_Clock) &&
  7166. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7167. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7168. else
  7169. {
  7170. if(FirstHeartBeat)
  7171. LWS_Send(queuedata +2);
  7172. }
  7173. return result;
  7174. }
  7175. int sendLogStatusNotificationRequest(char *status)
  7176. {
  7177. mtrace();
  7178. int result = PASS;
  7179. char message[4096]={0};
  7180. char guid[37]={0};
  7181. char tempdata[128]={0};
  7182. json_object *LogStatusNotification = json_object_new_object();
  7183. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7184. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  7185. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  7186. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  7187. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  7188. random_uuid(guid);
  7189. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7190. json_object_put(LogStatusNotification);
  7191. LWS_Send(message);
  7192. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7193. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7194. {
  7195. result = PASS;
  7196. }
  7197. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  7198. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  7199. return result;
  7200. }
  7201. int sendSecurityEventNotificationRequest()
  7202. {
  7203. mtrace();
  7204. int result = PASS;
  7205. char message[4096]={0};
  7206. char guid[37]={0};
  7207. char tempdata[128]={0};
  7208. json_object *SecurityEventNotification = json_object_new_object();
  7209. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7210. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  7211. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  7212. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  7213. random_uuid(guid);
  7214. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7215. json_object_put(SecurityEventNotification);
  7216. LWS_Send(message);
  7217. sprintf(tempdata, "SecurityEventNotification,0");
  7218. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7219. {
  7220. result = PASS;
  7221. }
  7222. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  7223. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  7224. return result;
  7225. }
  7226. int sendSignCertificateRequest()
  7227. {
  7228. mtrace();
  7229. int result = PASS;
  7230. char message[4096]={0};
  7231. char guid[37]={0};
  7232. char tempdata[128]={0};
  7233. json_object *SignCertificate = json_object_new_object();
  7234. DEBUG_INFO("sendSignCertificateRequest...\n");
  7235. // Read csr file content
  7236. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  7237. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  7238. char *line = NULL;
  7239. size_t len = 0;
  7240. while(getline(&line, &len, fp) != -1)
  7241. {
  7242. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7243. {
  7244. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  7245. }
  7246. }
  7247. fclose(fp);
  7248. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  7249. random_uuid(guid);
  7250. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7251. json_object_put(SignCertificate);
  7252. LWS_Send(message);
  7253. sprintf(tempdata, "SignCertificate,0");
  7254. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7255. {
  7256. result = PASS;
  7257. }
  7258. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  7259. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  7260. return result;
  7261. }
  7262. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7263. {
  7264. mtrace();
  7265. int result = PASS;
  7266. char message[110]={0};
  7267. char guid[37]={0};
  7268. char tempdata[65]={0};
  7269. json_object *FirmwareStatusNotification = json_object_new_object();
  7270. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7271. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7272. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  7273. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  7274. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  7275. random_uuid(guid);
  7276. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7277. json_object_put(FirmwareStatusNotification);
  7278. LWS_Send(message);
  7279. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7280. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7281. {
  7282. result = PASS;
  7283. }
  7284. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7285. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7286. return result;
  7287. }
  7288. //==========================================
  7289. // send confirm routine
  7290. //==========================================
  7291. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7292. {
  7293. mtrace();
  7294. int result = FAIL;
  7295. char message[100]={0};
  7296. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7297. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7298. LWS_Send(message);
  7299. result = TRUE;
  7300. return result;
  7301. }
  7302. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7303. {
  7304. mtrace();
  7305. int result = FAIL;
  7306. char message[100]={0};
  7307. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7308. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7309. LWS_Send(message);
  7310. result = TRUE;
  7311. return result;
  7312. }
  7313. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7314. {
  7315. mtrace();
  7316. int result = FAIL;
  7317. char message[100]={0};
  7318. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7319. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7320. LWS_Send(message);
  7321. result = TRUE;
  7322. return result;
  7323. }
  7324. int sendClearCacheConfirmation(char *uuid,char *payload)
  7325. {
  7326. mtrace();
  7327. int result = FAIL;
  7328. char message[500]={0};
  7329. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7330. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7331. LWS_Send(message);
  7332. return result;
  7333. }
  7334. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7335. {
  7336. mtrace();
  7337. int result = FAIL;
  7338. char message[500]={0};
  7339. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7340. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7341. LWS_Send(message);
  7342. return result;
  7343. }
  7344. int sendDataTransferConfirmation(char *uuid,char *payload)
  7345. {
  7346. mtrace();
  7347. char statusStr[20]={0};
  7348. char dataStr[10]={0};
  7349. char sstr[20]={0};
  7350. int c = 0;
  7351. char *loc;
  7352. int result = FAIL;
  7353. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7354. /**********************status**************************/
  7355. loc = strstr(payload, "status");
  7356. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7357. c = 0;
  7358. while (loc[3+strlen("status")+c] != '\"')
  7359. {
  7360. sstr[c] = loc[3+strlen("status")+c];
  7361. c++;
  7362. }
  7363. sstr[c] = '\0';
  7364. strcpy(statusStr, sstr);
  7365. /**********************data**************************/
  7366. loc = strstr(payload, "data");
  7367. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7368. c = 0;
  7369. while (loc[3+strlen("data")+c] != '\"')
  7370. {
  7371. sstr[c] = loc[3+strlen("data")+c];
  7372. c++;
  7373. }
  7374. sstr[c] = '\0';
  7375. strcpy(dataStr, sstr);
  7376. return result;
  7377. }
  7378. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7379. {
  7380. mtrace();
  7381. int result = FAIL;
  7382. char message[1000]={0};
  7383. int CompositeScheduleIndex = 0;
  7384. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7385. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7386. if(nPeriod == 0)
  7387. {
  7388. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7389. {
  7390. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7391. ,MESSAGE_TYPE_CALLRESULT
  7392. ,uuid
  7393. ,payload
  7394. ,connectorIdInt);
  7395. }
  7396. else
  7397. {
  7398. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  7399. ,MESSAGE_TYPE_CALLRESULT
  7400. ,uuid
  7401. ,payload
  7402. ,connectorIdInt
  7403. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7404. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7405. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7406. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7407. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7408. }
  7409. }
  7410. else
  7411. {
  7412. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7413. ,MESSAGE_TYPE_CALLRESULT
  7414. ,uuid
  7415. ,payload
  7416. ,connectorIdInt
  7417. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7418. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7419. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7420. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7421. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7422. {
  7423. if (idx_sample == 0)
  7424. {
  7425. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7426. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7427. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7428. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7429. }
  7430. else
  7431. {
  7432. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7433. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7434. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7435. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7436. }
  7437. }
  7438. sprintf(message + strlen(message), "]}}]");
  7439. }
  7440. LWS_Send(message);
  7441. result = TRUE;
  7442. return result;
  7443. }
  7444. int sendGetConfigurationConfirmation(char *uuid)
  7445. {
  7446. mtrace();
  7447. int result = FAIL;
  7448. int MaxKeySupported = 0;
  7449. int sentConfigurationNumber= 0;
  7450. int sentunConfigurationNumber= 0;
  7451. char message[1024*10]={0};
  7452. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7453. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7454. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  7455. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7456. ,MESSAGE_TYPE_CALLRESULT
  7457. ,uuid );
  7458. //configuration key
  7459. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7460. {
  7461. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7462. {
  7463. if (sentConfigurationNumber == 0)
  7464. {
  7465. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7466. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7467. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7468. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7469. }
  7470. else
  7471. {
  7472. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7473. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7474. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7475. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7476. }
  7477. sentConfigurationNumber = sentConfigurationNumber + 1;
  7478. }
  7479. }
  7480. sprintf(message + strlen(message), "]");
  7481. if(UnknownKeynum != 0)
  7482. {
  7483. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7484. //unkown key
  7485. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7486. {
  7487. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7488. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7489. if(sentunConfigurationNumber == 0)
  7490. {
  7491. sprintf(message + strlen(message), "\"%s\""
  7492. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7493. }
  7494. else
  7495. {
  7496. sprintf(message + strlen(message), ",\"%s\""
  7497. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7498. }
  7499. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7500. }
  7501. sprintf(message + strlen(message), "]");
  7502. }
  7503. sprintf(message + strlen(message), "}]");
  7504. LWS_Send(message);
  7505. return result;
  7506. }
  7507. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7508. {
  7509. mtrace();
  7510. int result = FAIL;
  7511. char message[400]={0};
  7512. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7513. if(strcmp(payload,"")==0)
  7514. {
  7515. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7516. }
  7517. else
  7518. {
  7519. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7520. }
  7521. LWS_Send(message);
  7522. result = TRUE;
  7523. return result;
  7524. }
  7525. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7526. {
  7527. mtrace();
  7528. int result = FAIL;
  7529. char message[80]={0};
  7530. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7531. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  7532. LWS_Send(message);
  7533. result = TRUE;
  7534. return result;
  7535. }
  7536. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7537. {
  7538. mtrace();
  7539. int result = FAIL;
  7540. char message[80]={0};
  7541. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7542. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7543. LWS_Send(message);
  7544. result = TRUE;
  7545. return result;
  7546. }
  7547. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7548. {
  7549. mtrace();
  7550. int result = FAIL;
  7551. char message[80]={0};
  7552. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7553. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7554. LWS_Send(message);
  7555. result = TRUE;
  7556. return result;
  7557. }
  7558. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7559. {
  7560. mtrace();
  7561. int result = FAIL;
  7562. char message[80]={0};
  7563. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7564. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7565. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7566. LWS_Send(message);
  7567. result = TRUE;
  7568. return result;
  7569. }
  7570. int sendResetConfirmation(char *uuid,char *payload)
  7571. {
  7572. mtrace();
  7573. int result = FAIL;
  7574. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7575. char message[80]={0};
  7576. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  7577. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7578. LWS_Send(message);
  7579. result = TRUE;
  7580. return result;
  7581. }
  7582. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7583. {
  7584. mtrace();
  7585. int result = FAIL;
  7586. char message[500]={0};
  7587. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7588. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7589. LWS_Send(message);
  7590. result = TRUE;
  7591. return result;
  7592. }
  7593. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7594. {
  7595. mtrace();
  7596. int result = FAIL;
  7597. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7598. char message[80]={0};
  7599. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7600. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7601. LWS_Send(message);
  7602. result = TRUE;
  7603. return result;
  7604. }
  7605. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7606. {
  7607. mtrace();
  7608. int result = FAIL;
  7609. char message[80]={0};
  7610. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7611. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7612. LWS_Send(message);
  7613. result = TRUE;
  7614. return result;
  7615. }
  7616. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7617. {
  7618. mtrace();
  7619. int result = FAIL;
  7620. char message[80]={0};
  7621. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7622. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7623. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7624. LWS_Send(message);
  7625. result = TRUE;
  7626. return result;
  7627. }
  7628. int sendUpdateFirmwareConfirmation(char *uuid)
  7629. {
  7630. mtrace();
  7631. int result = FAIL;
  7632. char message[60]={0};
  7633. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7634. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7635. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7636. LWS_Send(message);
  7637. result = TRUE;
  7638. return result;
  7639. }
  7640. int sendCertificateSignedConfirmation(char *uuid)
  7641. {
  7642. mtrace();
  7643. int result = PASS;
  7644. char message[4096]={0};
  7645. json_object *CertificateSigned = json_object_new_object();
  7646. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7647. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  7648. sprintf(message,"[%d,\"%s\",%s]"
  7649. ,MESSAGE_TYPE_CALLRESULT
  7650. ,uuid
  7651. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7652. json_object_put(CertificateSigned);
  7653. LWS_Send(message);
  7654. return result;
  7655. }
  7656. int sendDeleteCertificateConfirmation(char *uuid)
  7657. {
  7658. mtrace();
  7659. int result = PASS;
  7660. char message[4096]={0};
  7661. json_object *DeleteCertificate = json_object_new_object();
  7662. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7663. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  7664. sprintf(message,"[%d,\"%s\",%s]"
  7665. ,MESSAGE_TYPE_CALLRESULT
  7666. ,uuid
  7667. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7668. json_object_put(DeleteCertificate);
  7669. LWS_Send(message);
  7670. return result;
  7671. }
  7672. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7673. {
  7674. mtrace();
  7675. int result = PASS;
  7676. char message[4096]={0};
  7677. json_object *ExtendedTriggerMessage = json_object_new_object();
  7678. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7679. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7680. sprintf(message,"[%d,\"%s\",%s]"
  7681. ,MESSAGE_TYPE_CALLRESULT
  7682. ,uuid
  7683. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7684. json_object_put(ExtendedTriggerMessage);
  7685. LWS_Send(message);
  7686. return result;
  7687. }
  7688. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7689. {
  7690. mtrace();
  7691. int result = PASS;
  7692. char message[4096]={0};
  7693. json_object *GetInstalledCertificateIds = json_object_new_object();
  7694. json_object *certificateHashDataDatas = json_object_new_array();
  7695. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7696. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7697. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7698. {
  7699. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7700. {
  7701. json_object *certificateHashData = json_object_new_object();
  7702. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7703. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7704. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7705. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7706. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7707. }
  7708. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7709. }
  7710. else
  7711. {
  7712. json_object_put(certificateHashDataDatas);
  7713. }
  7714. sprintf(message,"[%d,\"%s\",%s]"
  7715. ,MESSAGE_TYPE_CALLRESULT
  7716. ,uuid
  7717. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7718. json_object_put(GetInstalledCertificateIds);
  7719. LWS_Send(message);
  7720. return result;
  7721. }
  7722. int sendGetLogConfirmation(char *uuid)
  7723. {
  7724. mtrace();
  7725. int result = PASS;
  7726. char message[4096]={0};
  7727. json_object *GetLog = json_object_new_object();
  7728. DEBUG_INFO("sendGetLogConfirmation...\n");
  7729. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7730. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7731. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7732. sprintf(message,"[%d,\"%s\",%s]"
  7733. ,MESSAGE_TYPE_CALLRESULT
  7734. ,uuid
  7735. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7736. json_object_put(GetLog);
  7737. LWS_Send(message);
  7738. return result;
  7739. }
  7740. int sendInstallCertificateConfirmation(char *uuid)
  7741. {
  7742. mtrace();
  7743. int result = PASS;
  7744. char message[4096]={0};
  7745. json_object *InstallCertificate = json_object_new_object();
  7746. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7747. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7748. sprintf(message,"[%d,\"%s\",%s]"
  7749. ,MESSAGE_TYPE_CALLRESULT
  7750. ,uuid
  7751. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7752. json_object_put(InstallCertificate);
  7753. LWS_Send(message);
  7754. return result;
  7755. }
  7756. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7757. {
  7758. mtrace();
  7759. int result = PASS;
  7760. char message[4096]={0};
  7761. json_object *SignedUpdateFirmware = json_object_new_object();
  7762. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7763. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7764. sprintf(message,"[%d,\"%s\",%s]"
  7765. ,MESSAGE_TYPE_CALLRESULT
  7766. ,uuid
  7767. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7768. json_object_put(SignedUpdateFirmware);
  7769. LWS_Send(message);
  7770. return result;
  7771. }
  7772. int sendUnknownConfirmation(char *uuid)
  7773. {
  7774. mtrace();
  7775. int result = PASS;
  7776. char message[256]={0};
  7777. DEBUG_INFO("sendUnknownConfirmation...\n");
  7778. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7779. LWS_Send(message);
  7780. return result;
  7781. }
  7782. //==========================================
  7783. // Handle server request routine Start
  7784. //==========================================
  7785. int handleCancelReservationRequest(char *uuid, char *payload)
  7786. {
  7787. mtrace();
  7788. int result = FAIL;
  7789. int gunNO = 0;
  7790. int reservationIdInt = -1;
  7791. char comfirmstr[20];
  7792. DEBUG_INFO("handleCancelReservationRequest...\n");
  7793. json_object *CancelReservation;
  7794. CancelReservation = json_tokener_parse(payload);
  7795. if(!is_error(CancelReservation))
  7796. {
  7797. // Required data
  7798. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7799. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7800. }
  7801. json_object_put(CancelReservation);
  7802. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7803. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7804. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7805. if(reservationIdInt != -1)
  7806. {
  7807. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7808. //check Transaction active
  7809. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7810. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7811. {
  7812. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7813. {
  7814. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7815. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7816. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7817. {
  7818. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7819. }
  7820. else
  7821. {
  7822. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7823. }
  7824. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7825. goto end;
  7826. }
  7827. }
  7828. for (int index = 0; index < CCS_QUANTITY; index++)
  7829. {
  7830. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7831. {
  7832. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7833. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7834. if(gunType[2] == GUN_TYPE_CCS)
  7835. {
  7836. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7837. }
  7838. else
  7839. {
  7840. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7841. }
  7842. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7843. goto end;
  7844. }
  7845. }
  7846. for (int index = 0; index < GB_QUANTITY; index++)
  7847. {
  7848. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7849. {
  7850. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7851. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7852. if(gunType[2] == GUN_TYPE_GBT)
  7853. {
  7854. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7855. }
  7856. else
  7857. {
  7858. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7859. }
  7860. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7861. goto end;
  7862. }
  7863. }
  7864. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7865. {
  7866. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7867. {
  7868. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7869. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7870. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7871. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7872. goto end;
  7873. }
  7874. }
  7875. for (int index = 0; index < AC_QUANTITY; index++)
  7876. {
  7877. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7878. {
  7879. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7880. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7881. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7882. {
  7883. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7884. }
  7885. else
  7886. {
  7887. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7888. }
  7889. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7890. goto end;
  7891. }
  7892. }
  7893. }
  7894. //The reservationId does NOT match the reservationId
  7895. sendCancelReservationConfirmation(uuid, comfirmstr);
  7896. end:
  7897. // Fill in ocpp packet uuid
  7898. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  7899. return result;
  7900. }
  7901. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7902. {
  7903. mtrace();
  7904. int result = FAIL;
  7905. int gunIndex = -1;
  7906. char typeStr[16]={0};
  7907. char comfirmstr[20];
  7908. int specificId = FALSE;
  7909. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7910. json_object *ChangeAvailability;
  7911. ChangeAvailability = json_tokener_parse(payload);
  7912. if(!is_error(ChangeAvailability))
  7913. {
  7914. // Required data
  7915. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7916. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7917. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7918. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7919. }
  7920. json_object_put(ChangeAvailability);
  7921. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7922. {
  7923. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7924. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7925. }
  7926. else if(gunIndex == 0)
  7927. {
  7928. for(int i=0; i < gunTotalNumber; i++)
  7929. {
  7930. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  7931. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  7932. }
  7933. }
  7934. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7935. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7936. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  7937. {
  7938. specificId = TRUE;
  7939. }
  7940. if(specificId == FALSE)
  7941. goto end;
  7942. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7943. {
  7944. //----------------------gunIndex is 0 ------------------------------------------------//
  7945. if(gunIndex == 0)
  7946. {
  7947. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7948. {
  7949. for(int i=0; i < gunTotalNumber; i++)
  7950. {
  7951. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7952. {
  7953. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7954. {
  7955. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7956. {
  7957. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7958. goto end;
  7959. }
  7960. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7961. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7962. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7963. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7964. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7965. {
  7966. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7967. goto end;
  7968. }
  7969. }
  7970. }//END FOR CHAdeMO_QUANTITY
  7971. for (int index = 0; index < CCS_QUANTITY; index++)
  7972. {
  7973. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7974. {
  7975. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7976. {
  7977. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7978. goto end;
  7979. }
  7980. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7981. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7982. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7983. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7984. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7985. {
  7986. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7987. goto end;
  7988. }
  7989. }
  7990. }//END FOR CCS_QUANTITY
  7991. for (int index = 0; index < GB_QUANTITY; index++)
  7992. {
  7993. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7994. {
  7995. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7996. {
  7997. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7998. goto end;
  7999. }
  8000. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8001. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8002. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8003. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8004. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8005. {
  8006. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8007. goto end;
  8008. }
  8009. }
  8010. }// END FOR GB_QUANTITY
  8011. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8012. {
  8013. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8014. {
  8015. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8016. {
  8017. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8018. goto end;
  8019. }
  8020. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8021. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8022. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8023. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8024. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8025. {
  8026. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8027. goto end;
  8028. }
  8029. }
  8030. }// END FOR GENERAL_GUN_QUANTITY
  8031. for (int index = 0; index < AC_QUANTITY; index++)
  8032. {
  8033. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8034. {
  8035. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8036. {
  8037. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8038. goto end;
  8039. }
  8040. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8041. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8042. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8043. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8044. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8045. {
  8046. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8047. goto end;
  8048. }
  8049. }
  8050. }//END FOR AC_QUANTITY
  8051. }// END FOR gunTotalNumber
  8052. }
  8053. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8054. {
  8055. for(int i=0; i < gunTotalNumber; i++)
  8056. {
  8057. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8058. {
  8059. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8060. goto end;
  8061. }
  8062. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8063. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8064. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8065. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8066. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8067. {
  8068. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8069. goto end;
  8070. }
  8071. }
  8072. }
  8073. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8074. goto end;
  8075. }
  8076. //----------------------gunIndex is not 0 ------------------------------------------------//
  8077. //check Transaction active
  8078. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8079. {
  8080. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8081. {
  8082. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8083. {
  8084. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8085. goto end;
  8086. }
  8087. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8088. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8089. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8090. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8091. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8092. {
  8093. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8094. goto end;
  8095. }
  8096. else
  8097. {
  8098. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8099. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8100. goto end;
  8101. }
  8102. }
  8103. }//END FOR CHAdeMO_QUANTITY
  8104. for (int index = 0; index < CCS_QUANTITY; index++)
  8105. {
  8106. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8107. {
  8108. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8109. {
  8110. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8111. goto end;
  8112. }
  8113. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8114. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8115. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8116. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8117. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8118. {
  8119. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8120. goto end;
  8121. }
  8122. else
  8123. {
  8124. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8125. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8126. goto end;
  8127. }
  8128. }
  8129. }//END FOR CCS_QUANTITY
  8130. for (int index = 0; index < GB_QUANTITY; index++)
  8131. {
  8132. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8133. {
  8134. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8135. {
  8136. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8137. goto end;
  8138. }
  8139. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8140. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8141. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8142. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8143. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8144. {
  8145. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8146. goto end;
  8147. }
  8148. else
  8149. {
  8150. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8151. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8152. goto end;
  8153. }
  8154. }
  8155. }// END FOR GB_QUANTITY
  8156. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8157. {
  8158. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8159. {
  8160. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8161. {
  8162. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8163. goto end;
  8164. }
  8165. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8166. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8167. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8168. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8169. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8170. {
  8171. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8172. goto end;
  8173. }
  8174. else
  8175. {
  8176. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8177. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8178. goto end;
  8179. }
  8180. }
  8181. }// END FOR GENERAL_GUN_QUANTITY
  8182. for (int index = 0; index < AC_QUANTITY; index++)
  8183. {
  8184. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8185. {
  8186. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8187. {
  8188. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8189. goto end;
  8190. }
  8191. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8192. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8193. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8194. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8195. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8196. {
  8197. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8198. goto end;
  8199. }
  8200. else
  8201. {
  8202. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8203. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8204. goto end;
  8205. }
  8206. }
  8207. }//END FOR AC_QUANTITY
  8208. }//END FOR AvailabilityTypeStr[Inoperative]
  8209. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8210. {
  8211. //----------------------gunIndex is 0 ------------------------------------------------//
  8212. if(gunIndex == 0)
  8213. {
  8214. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8215. {
  8216. for(int i=0; i < gunTotalNumber; i++)
  8217. {
  8218. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8219. {
  8220. 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
  8221. {
  8222. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8223. goto end;
  8224. }
  8225. }//END FOR CHAdeMO_QUANTITY
  8226. for (int index = 0; index < CCS_QUANTITY; index++)
  8227. {
  8228. 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
  8229. {
  8230. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8231. goto end;
  8232. }
  8233. }//END FOR CCS_QUANTITY
  8234. for (int index = 0; index < GB_QUANTITY; index++)
  8235. {
  8236. 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
  8237. {
  8238. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8239. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8240. goto end;
  8241. }
  8242. }// END FOR GB_QUANTITY
  8243. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8244. {
  8245. 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
  8246. {
  8247. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8248. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8249. goto end;
  8250. }
  8251. }// END FOR GENERAL_GUN_QUANTITY
  8252. for (int index = 0; index < AC_QUANTITY; index++)
  8253. {
  8254. 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
  8255. {
  8256. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8257. goto end;
  8258. }
  8259. }//END FOR CHAdeMO_QUANTITY
  8260. }// END FOR gunTotalNumber
  8261. }
  8262. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8263. {
  8264. for(int i=0; i < gunTotalNumber; i++)
  8265. {
  8266. for (int index = 0; index < AC_QUANTITY; index++)
  8267. {
  8268. 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
  8269. {
  8270. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8271. goto end;
  8272. }
  8273. }//END FOR CHAdeMO_QUANTITY
  8274. } // END FOR gunTotalNumber
  8275. }
  8276. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8277. goto end;
  8278. }
  8279. //----------------------gunIndex is not 0 ------------------------------------------------//
  8280. //check Transaction active
  8281. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8282. {
  8283. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8284. {
  8285. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8286. goto end;
  8287. }
  8288. }//END FOR CHAdeMO_QUANTITY
  8289. for (int index = 0; index < CCS_QUANTITY; index++)
  8290. {
  8291. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8292. {
  8293. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8294. goto end;
  8295. }
  8296. }//END FOR CCS_QUANTITY
  8297. for (int index = 0; index < GB_QUANTITY; index++)
  8298. {
  8299. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8300. {
  8301. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8302. goto end;
  8303. }
  8304. }// END FOR GB_QUANTITY
  8305. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8306. {
  8307. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8308. {
  8309. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8310. goto end;
  8311. }
  8312. }// END FOR GENERAL_GUN_QUANTITY
  8313. for (int index = 0; index < AC_QUANTITY; index++)
  8314. {
  8315. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8316. {
  8317. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8318. goto end;
  8319. }
  8320. }//END FOR AC_QUANTITY
  8321. }//END FOR AvailabilityTypeStr[Operative]
  8322. end:
  8323. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8324. {
  8325. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8326. }
  8327. else
  8328. {
  8329. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8330. }
  8331. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8332. {
  8333. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8334. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8335. }
  8336. else if(gunIndex == 0)
  8337. {
  8338. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8339. {
  8340. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8341. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8342. }
  8343. }
  8344. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8345. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8346. return result;
  8347. }
  8348. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8349. {
  8350. mtrace();
  8351. int valueInvalid = NO;
  8352. int result = FAIL;
  8353. char keystr[40]={0};
  8354. char valuestr[501]={0}; //value should be limited in 500 bytes
  8355. char comfirmstr[20]={0};
  8356. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8357. json_object *ChangeConfiguration;
  8358. ChangeConfiguration = json_tokener_parse(payload);
  8359. if(!is_error(ChangeConfiguration))
  8360. {
  8361. // Required data
  8362. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8363. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8364. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8365. {
  8366. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8367. }
  8368. else
  8369. {
  8370. valueInvalid = YES;
  8371. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8372. }
  8373. }
  8374. json_object_put(ChangeConfiguration);
  8375. if((uuid==NULL) || (payload ==NULL) || (valueInvalid == YES))
  8376. {
  8377. DEBUG_ERROR("Payload is null or not accepted.\n");
  8378. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8379. }
  8380. else
  8381. {
  8382. int status = setKeyValue(keystr, valuestr);
  8383. switch(status)
  8384. {
  8385. case ConfigurationStatus_Accepted:
  8386. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8387. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  8388. StoreConfigurationTable();
  8389. break;
  8390. case RebootRequired:
  8391. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8392. StoreConfigurationTable();
  8393. break;
  8394. case NotSupported:
  8395. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8396. break;
  8397. case ConfigurationStatus_Rejected:
  8398. default:
  8399. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8400. break;
  8401. }
  8402. }
  8403. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8404. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  8405. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8406. {
  8407. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8408. SetOcppConnStatus(FALSE);
  8409. }
  8410. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8411. {
  8412. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8413. }
  8414. return result;
  8415. }
  8416. int handleClearCacheRequest(char *uuid, char *payload)
  8417. {
  8418. mtrace();
  8419. int result = FAIL;
  8420. char comfirmstr[20];
  8421. char rmFileCmd[100]={0};
  8422. struct stat stats;
  8423. DEBUG_INFO("handleClearCacheRequest...\n");
  8424. stat("/Storage/OCPP_PH", &stats);
  8425. // Check for directory existence
  8426. if (S_ISDIR(stats.st_mode) == 1)
  8427. {}
  8428. else
  8429. {
  8430. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8431. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  8432. system(rmFileCmd);
  8433. }
  8434. if(OCPP_cleanLocalCache())
  8435. {
  8436. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8437. }
  8438. else
  8439. {
  8440. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8441. }
  8442. sendClearCacheConfirmation(uuid, comfirmstr);
  8443. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8444. return result;
  8445. }
  8446. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8447. {
  8448. mtrace();
  8449. int result = FAIL;
  8450. int resultRename;
  8451. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8452. char chargingProfilePurposeStr[26]={0};
  8453. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8454. char tempchargingProfilePurposeStr[26]={0};
  8455. char str[100]={0};
  8456. char fname[200]={0};
  8457. char comfirmstr[20]={0};
  8458. char word[1600]={0};
  8459. int clearflag = FALSE;
  8460. int chargingProfileIdIsNULL = FALSE;
  8461. int connectorIsNULL = FALSE;
  8462. int chargingProfilePurposeIsNULL = FALSE;
  8463. int stackLevelIsNULL = FALSE;
  8464. //int GotoEnd = FALSE;
  8465. FILE *fptr1, *fptr2;
  8466. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  8467. int n_chargingProfile=0;
  8468. int isEmptyFile = FALSE;
  8469. char sLineWord[1600]={0};
  8470. char chargingProfiles[10][100]={0};
  8471. int ChargeProfileCount = 0;
  8472. int ch;
  8473. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8474. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8475. json_object *ClearChargingProfile;
  8476. ClearChargingProfile = json_tokener_parse(payload);
  8477. if(!is_error(ClearChargingProfile))
  8478. {
  8479. // Optional data
  8480. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8481. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8482. else
  8483. chargingProfileIdIsNULL = TRUE;
  8484. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8485. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8486. else
  8487. connectorIsNULL = TRUE;
  8488. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8489. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8490. else
  8491. chargingProfilePurposeIsNULL = TRUE;
  8492. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8493. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8494. else
  8495. stackLevelIsNULL = TRUE;
  8496. }
  8497. json_object_put(ClearChargingProfile);
  8498. if(connectorIsNULL == FALSE)
  8499. {
  8500. switch(connectorIdInt)
  8501. {
  8502. case 0:
  8503. if(chargingProfilePurposeIsNULL == TRUE)
  8504. {
  8505. int l = 0;
  8506. strcpy(fname, ChargePointMaxProfile_JSON);
  8507. if((access(fname,F_OK))!=-1)
  8508. {
  8509. strcpy(chargingProfiles[l], fname);
  8510. l = l + 1;
  8511. }
  8512. strcpy(fname, TxDefaultProfile_0_JSON);
  8513. if((access(fname,F_OK))!=-1)
  8514. {
  8515. strcpy(chargingProfiles[l], fname);
  8516. l = l + 1;
  8517. }
  8518. ChargeProfileCount = l;
  8519. }
  8520. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8521. {
  8522. strcpy(fname, ChargePointMaxProfile_JSON);
  8523. if((access(fname,F_OK))!=-1)
  8524. {
  8525. strcpy(chargingProfiles[0], fname);
  8526. ChargeProfileCount = 1;
  8527. }
  8528. }
  8529. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8530. {
  8531. strcpy(fname, TxDefaultProfile_0_JSON);
  8532. if((access(fname,F_OK))!=-1)
  8533. {
  8534. strcpy(chargingProfiles[0], fname);
  8535. ChargeProfileCount = 1;
  8536. }
  8537. }
  8538. break;
  8539. default:
  8540. if(chargingProfilePurposeIsNULL == TRUE)
  8541. {
  8542. int m = 0;
  8543. memset(fname, 0, ARRAY_SIZE(fname));
  8544. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8545. if((access(fname,F_OK))!=-1)
  8546. {
  8547. strcpy(chargingProfiles[m], fname);
  8548. m = m + 1;
  8549. }
  8550. memset(fname, 0, ARRAY_SIZE(fname));
  8551. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8552. if((access(fname,F_OK))!=-1)
  8553. {
  8554. strcpy(chargingProfiles[m], fname);
  8555. m = m + 1;
  8556. }
  8557. ChargeProfileCount = m;
  8558. }
  8559. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8560. {
  8561. //strcpy(fname, TxDefaultProfile_1_JSON);
  8562. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8563. if((access(fname,F_OK))!=-1)
  8564. {
  8565. strcpy(chargingProfiles[0], fname);
  8566. ChargeProfileCount = 1;
  8567. }
  8568. }
  8569. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8570. {
  8571. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8572. if((access(fname,F_OK))!=-1)
  8573. {
  8574. strcpy(chargingProfiles[0], fname);
  8575. ChargeProfileCount = 1;
  8576. }
  8577. //strcpy(fname, TxProfile_1_JSON);
  8578. }
  8579. //strcpy(fname, ChargePointMaxProfile_JSON );
  8580. break;
  8581. }
  8582. }
  8583. else // Check all Charging Profiles
  8584. {
  8585. int i = 0;
  8586. char fnametemp[200]={0};
  8587. ChargeProfileCount = 0;
  8588. //Check ChargePointMaxProfile.json exit
  8589. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  8590. {
  8591. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  8592. i = i + 1;
  8593. }
  8594. //Check TxDefaultProfile_0.json exit
  8595. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  8596. {
  8597. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  8598. i = i + 1;
  8599. }
  8600. //Check TxDefaultProfile_%d.json
  8601. for(int j=1; j <= gunTotalNumber; j++)
  8602. {
  8603. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8604. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  8605. if((access(fnametemp,F_OK))!=-1)
  8606. {
  8607. strcpy(chargingProfiles[i], fnametemp);
  8608. i = i + 1;
  8609. }
  8610. }
  8611. //Check TxProfile_%d.json
  8612. for(int j=1; j <= gunTotalNumber; j++)
  8613. {
  8614. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8615. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  8616. if((access(fnametemp,F_OK))!=-1)
  8617. {
  8618. strcpy(chargingProfiles[i], fnametemp);
  8619. i = i + 1;
  8620. }
  8621. }
  8622. ChargeProfileCount = i;
  8623. }// End connectorIsNULL is TRUE
  8624. if(ChargeProfileCount == 0)
  8625. {
  8626. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8627. goto end;
  8628. }
  8629. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8630. {
  8631. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8632. goto end;
  8633. }
  8634. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8635. {
  8636. memset(str, 0, ARRAY_SIZE(str));
  8637. // clear temp file
  8638. sprintf(str,"rm -f %s",temp);
  8639. system(str);
  8640. for(int k=0; k < ChargeProfileCount; k++)
  8641. {
  8642. memset(str, 0, ARRAY_SIZE(str));
  8643. //clear file in C
  8644. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8645. system(str);
  8646. }
  8647. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8648. goto end;
  8649. }
  8650. else if(connectorIsNULL == TRUE)
  8651. {
  8652. for(int k=0; k < ChargeProfileCount; k++)
  8653. {
  8654. fptr1 = fopen(chargingProfiles[k], "r");
  8655. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  8656. //Check Charging Profile Count
  8657. while(fscanf(fptr1, "%s", word) != EOF)
  8658. {
  8659. //DEBUG_INFO("word=%s\n",word);
  8660. if(strstr(word, "chargingProfileId")!= NULL)
  8661. {
  8662. //DEBUG_INFO("test chargingProfileId \n");
  8663. n_chargingProfile = n_chargingProfile + 1;
  8664. //DEBUG_INFO("chargingProfileId Found\n");
  8665. }
  8666. }
  8667. rewind(fptr1);
  8668. //search Charging Profile Element
  8669. //int i= 0;
  8670. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8671. {
  8672. json_object *tmpProfilee;
  8673. tmpProfilee = json_tokener_parse(sLineWord);
  8674. if(!is_error(tmpProfilee))
  8675. {
  8676. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8677. {
  8678. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8679. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8680. }
  8681. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8682. {
  8683. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8684. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8685. }
  8686. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8687. {
  8688. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8689. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8690. }
  8691. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8692. {
  8693. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8694. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8695. }
  8696. }
  8697. json_object_put(tmpProfilee);
  8698. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8699. {
  8700. //------- not write to fptr2-------//
  8701. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8702. //clearflag = TRUE;
  8703. }
  8704. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8705. {
  8706. //------- not write to fptr2-------//
  8707. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8708. }
  8709. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8710. {
  8711. //------- not write to fptr2-------//
  8712. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8713. }
  8714. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8715. {
  8716. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8717. }
  8718. else
  8719. {
  8720. fprintf(fptr2, sLineWord);//writing data into file
  8721. }
  8722. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8723. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8724. if(clearflag == TRUE)
  8725. {
  8726. fclose(fptr1);
  8727. fclose(fptr2);
  8728. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8729. system(str);
  8730. // clear temp file
  8731. sprintf(str,"rm -f %s",temp);
  8732. system(str);
  8733. }
  8734. else
  8735. {
  8736. fclose(fptr1);
  8737. fclose(fptr2);
  8738. memset(str, 0, ARRAY_SIZE(str));
  8739. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8740. system(str);
  8741. resultRename = rename(temp, chargingProfiles[k]);
  8742. if(resultRename == 0)
  8743. {
  8744. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8745. }
  8746. else
  8747. {
  8748. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8749. }
  8750. if(comfirmstr[0]== 0)
  8751. {
  8752. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8753. }
  8754. //Check chargingProfile is empty file
  8755. /*------ Read the file ----------------*/
  8756. fptr1=fopen(chargingProfiles[k],"r");
  8757. ch=fgetc(fptr1);
  8758. rewind(fptr1);
  8759. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8760. if(ch!=EOF)
  8761. {
  8762. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8763. {
  8764. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8765. if(sLineWord[0]=='\0')
  8766. {
  8767. isEmptyFile = TRUE;
  8768. break;
  8769. }
  8770. else
  8771. {
  8772. isEmptyFile = FALSE;
  8773. break;
  8774. }
  8775. }
  8776. }
  8777. else
  8778. isEmptyFile = TRUE;
  8779. fclose(fptr1);
  8780. if(isEmptyFile == TRUE)
  8781. {
  8782. memset(str, 0, ARRAY_SIZE(str));
  8783. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8784. system(str);
  8785. }
  8786. }
  8787. }// End of while(int k=0; k < ChargePointCount; k++)
  8788. }
  8789. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8790. {
  8791. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8792. for(int k=0; k < ChargeProfileCount; k++)
  8793. {
  8794. fptr1 = fopen(chargingProfiles[k], "r");
  8795. fptr2 = fopen(temp, "w+");
  8796. //Check Charging Profile Count
  8797. while(fscanf(fptr1, "%s", word) != EOF)
  8798. {
  8799. //DEBUG_INFO("word=%s\n",word);
  8800. if(strstr(word, "chargingProfileId")!= NULL)
  8801. {
  8802. n_chargingProfile = n_chargingProfile + 1;
  8803. }
  8804. }
  8805. rewind(fptr1);
  8806. //search Charging Profile Element
  8807. //int i= 0;
  8808. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8809. {
  8810. json_object *tmpProfilee;
  8811. tmpProfilee = json_tokener_parse(sLineWord);
  8812. if(!is_error(tmpProfilee))
  8813. {
  8814. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8815. {
  8816. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8817. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8818. }
  8819. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8820. {
  8821. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8822. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8823. }
  8824. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8825. {
  8826. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8827. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8828. }
  8829. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8830. {
  8831. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8832. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8833. }
  8834. }
  8835. json_object_put(tmpProfilee);
  8836. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8837. {
  8838. //------- not write to fptr2-------//
  8839. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8840. //clearflag = TRUE;
  8841. }
  8842. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8843. {
  8844. //------- not write to fptr2-------//
  8845. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8846. }
  8847. else if(stackLevelIsNULL == TRUE)
  8848. {
  8849. //Clear Whole File
  8850. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8851. clearflag = TRUE;
  8852. break;
  8853. }
  8854. else
  8855. {
  8856. fprintf(fptr2, sLineWord);//writing data into file
  8857. }
  8858. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8859. }
  8860. if(clearflag == TRUE)
  8861. {
  8862. fclose(fptr1);
  8863. fclose(fptr2);
  8864. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8865. system(str);
  8866. // clear temp file
  8867. sprintf(str,"rm -f %s",temp);
  8868. system(str);
  8869. }
  8870. else
  8871. {
  8872. fclose(fptr1);
  8873. fclose(fptr2);
  8874. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8875. system(str);
  8876. resultRename = rename(temp, chargingProfiles[k]);
  8877. if(resultRename == 0)
  8878. {
  8879. DEBUG_INFO("File ChargingProfile renamed successfully");
  8880. }
  8881. else
  8882. {
  8883. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8884. }
  8885. if(comfirmstr[0]== 0)
  8886. {
  8887. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8888. }
  8889. //Check chargingProfile is empty file
  8890. /*------ Read the file ----------------*/
  8891. fptr1=fopen(chargingProfiles[k],"r");
  8892. ch=fgetc(fptr1);
  8893. rewind(fptr1);
  8894. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8895. if(ch!=EOF)
  8896. {
  8897. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8898. {
  8899. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8900. if(sLineWord[0]=='\0')
  8901. {
  8902. isEmptyFile = TRUE;
  8903. break;
  8904. }
  8905. else
  8906. {
  8907. isEmptyFile = FALSE;
  8908. break;
  8909. }
  8910. }
  8911. }
  8912. else
  8913. isEmptyFile = TRUE;
  8914. fclose(fptr1);
  8915. if(isEmptyFile == TRUE)
  8916. {
  8917. memset(str, 0, ARRAY_SIZE(str));
  8918. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8919. system(str);
  8920. }
  8921. /*------- End of reading ---------------*/
  8922. }
  8923. } // while(int k=0; k < ChargeProfileCount; k++)
  8924. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8925. end:
  8926. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8927. {
  8928. if(connectorIdInt == 0)
  8929. {
  8930. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8931. {
  8932. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  8933. }
  8934. }
  8935. else
  8936. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  8937. }
  8938. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8939. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8940. return result;
  8941. }
  8942. void createFirmwareVersionByDataTransfer(void)
  8943. {
  8944. json_object *FirmwareDataTransfer = json_object_new_object();
  8945. // AC & DC model
  8946. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8947. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8948. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8949. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8950. // DC model
  8951. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8952. {
  8953. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8954. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8955. (gunType[3] != GUN_TYPE_UNKNOWN))
  8956. {
  8957. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8958. }
  8959. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8960. {
  8961. // DS DM DW
  8962. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8963. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8964. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8965. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8966. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8967. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8968. }
  8969. else
  8970. {
  8971. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8972. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8973. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8974. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8975. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8976. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8977. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8978. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8979. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8980. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8981. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8982. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8983. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8984. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8985. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8986. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8987. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8988. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8989. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8990. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8991. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8992. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8993. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8994. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8995. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8996. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8997. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8998. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8999. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9000. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9001. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9002. }
  9003. }
  9004. // 4G model
  9005. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9006. {
  9007. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9008. }
  9009. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9010. json_object_put(FirmwareDataTransfer);
  9011. }
  9012. int handleDataTransferRequest(char *uuid, char *payload)
  9013. {
  9014. mtrace();
  9015. json_object *response = json_object_new_object();
  9016. int result = FAIL;
  9017. char tempvendorId[255]={0};
  9018. char tempmessageId[50]={0};
  9019. char tempdata[1024]={0};
  9020. char message[2048]={0};
  9021. DEBUG_INFO("handleDataTransferRequest...\n");
  9022. if((uuid != NULL) && (payload != NULL))
  9023. {
  9024. json_object *DataTransfer;
  9025. DataTransfer = json_tokener_parse(payload);
  9026. if(!is_error(DataTransfer))
  9027. {
  9028. // Required data
  9029. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9030. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9031. // Optional data
  9032. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9033. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9034. if(json_object_object_get(DataTransfer, "data") != NULL)
  9035. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9036. result = PASS;
  9037. }
  9038. json_object_put(DataTransfer);
  9039. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9040. {
  9041. // Send all moudle firmware version on EVSE
  9042. createFirmwareVersionByDataTransfer();
  9043. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9044. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData));
  9045. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9046. json_object_put(response);
  9047. }
  9048. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9049. {
  9050. system("/usr/bin/run_tmate_restart.sh &");
  9051. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9052. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9053. json_object_put(response);
  9054. }
  9055. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9056. {
  9057. json_object *data;
  9058. data = json_tokener_parse(tempdata);
  9059. if(!is_error(data))
  9060. {
  9061. 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))
  9062. {
  9063. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9064. memset(&ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9065. if(json_object_object_get(data, "SOC") != NULL)
  9066. {
  9067. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9068. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9069. }
  9070. if(json_object_object_get(data, "Energy") != NULL)
  9071. {
  9072. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9073. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9074. }
  9075. if(json_object_object_get(data, "Duration") != NULL)
  9076. {
  9077. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9078. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9079. }
  9080. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9081. }
  9082. else
  9083. {
  9084. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9085. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9086. }
  9087. }
  9088. else
  9089. {
  9090. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9091. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9092. }
  9093. json_object_put(data);
  9094. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9095. json_object_put(response);
  9096. }
  9097. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9098. {
  9099. json_object *data;
  9100. data = json_tokener_parse(tempdata);
  9101. if(!is_error(data))
  9102. {
  9103. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9104. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9105. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9106. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9107. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9108. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9109. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9110. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9111. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9112. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9113. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9114. }
  9115. else
  9116. {
  9117. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9118. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9119. }
  9120. json_object_put(data);
  9121. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9122. json_object_put(response);
  9123. }
  9124. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9125. {
  9126. json_object *data;
  9127. data = json_tokener_parse(tempdata);
  9128. if(!is_error(data))
  9129. {
  9130. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9131. if(json_object_object_get(data, "idToken") != NULL)
  9132. {
  9133. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9134. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9135. }
  9136. if(json_object_object_get(data, "price") != NULL)
  9137. {
  9138. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9139. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9140. }
  9141. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9142. }
  9143. else
  9144. {
  9145. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9146. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9147. }
  9148. json_object_put(data);
  9149. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9150. json_object_put(response);
  9151. }
  9152. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9153. {
  9154. json_object *data;
  9155. data = json_tokener_parse(tempdata);
  9156. if(!is_error(data))
  9157. {
  9158. if(json_object_object_get(data, "txId") != NULL)
  9159. {
  9160. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9161. for(int idx = 0;idx<gunTotalNumber;idx++)
  9162. {
  9163. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9164. {
  9165. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9166. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9167. if(json_object_object_get(data, "description") != NULL)
  9168. {
  9169. // California pricing V1.0
  9170. DEBUG_INFO("California pricing V1.0\n");
  9171. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9172. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9173. }
  9174. else
  9175. {
  9176. // California pricing V1.1
  9177. DEBUG_INFO("California pricing V1.1\n");
  9178. if(json_object_object_get(data, "timestamp") != NULL)
  9179. {
  9180. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9181. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9182. }
  9183. if(json_object_object_get(data, "meterValue") != NULL)
  9184. {
  9185. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9186. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9187. }
  9188. if(json_object_object_get(data, "cost") != NULL)
  9189. {
  9190. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9191. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9192. }
  9193. if(json_object_object_get(data, "state") != NULL)
  9194. {
  9195. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9196. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9197. }
  9198. if(json_object_object_get(data, "chargingPrice") != NULL)
  9199. {
  9200. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9201. {
  9202. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9203. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9204. }
  9205. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9206. {
  9207. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9208. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9209. }
  9210. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9211. {
  9212. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9213. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9214. }
  9215. }
  9216. if(json_object_object_get(data, "idlePrice") != NULL)
  9217. {
  9218. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9219. {
  9220. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9221. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9222. }
  9223. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9224. {
  9225. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9226. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9227. }
  9228. }
  9229. if(json_object_object_get(data, "nextPeriod") != NULL)
  9230. {
  9231. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9232. {
  9233. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9234. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9235. }
  9236. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9237. {
  9238. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9239. {
  9240. 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")));
  9241. ShmOCPP16DataPH->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"));
  9242. }
  9243. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9244. {
  9245. 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")));
  9246. ShmOCPP16DataPH->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"));
  9247. }
  9248. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9249. {
  9250. 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")));
  9251. ShmOCPP16DataPH->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"));
  9252. }
  9253. }
  9254. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9255. {
  9256. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9257. {
  9258. 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")));
  9259. ShmOCPP16DataPH->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"));
  9260. }
  9261. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9262. {
  9263. 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")));
  9264. ShmOCPP16DataPH->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"));
  9265. }
  9266. }
  9267. }
  9268. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9269. {
  9270. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9271. {
  9272. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9273. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9274. }
  9275. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9276. {
  9277. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9278. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9279. }
  9280. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9281. {
  9282. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9283. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9284. }
  9285. }
  9286. }
  9287. }
  9288. }
  9289. }
  9290. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9291. }
  9292. else
  9293. {
  9294. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9295. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9296. }
  9297. json_object_put(data);
  9298. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9299. json_object_put(response);
  9300. }
  9301. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9302. {
  9303. json_object *data;
  9304. data = json_tokener_parse(tempdata);
  9305. if(!is_error(data))
  9306. {
  9307. if(json_object_object_get(data, "txId") != NULL)
  9308. {
  9309. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9310. for(int idx = 0;idx<gunTotalNumber;idx++)
  9311. {
  9312. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9313. {
  9314. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9315. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9316. if(json_object_object_get(data, "description") != NULL)
  9317. {
  9318. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9319. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9320. }
  9321. }
  9322. }
  9323. }
  9324. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9325. }
  9326. else
  9327. {
  9328. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9329. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9330. }
  9331. json_object_put(data);
  9332. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9333. json_object_put(response);
  9334. }
  9335. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9336. {
  9337. json_object *data;
  9338. data = json_tokener_parse(tempdata);
  9339. if(!is_error(data))
  9340. {
  9341. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9342. if(json_object_object_get(data, "Content_Type") != NULL)
  9343. {
  9344. 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))
  9345. {
  9346. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9347. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9348. {
  9349. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9350. }
  9351. }
  9352. else
  9353. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9354. }
  9355. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9356. }
  9357. else
  9358. {
  9359. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9360. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9361. }
  9362. json_object_put(data);
  9363. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9364. json_object_put(response);
  9365. }
  9366. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9367. {
  9368. json_object *data;
  9369. data = json_tokener_parse(tempdata);
  9370. if(!is_error(data))
  9371. {
  9372. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9373. if(json_object_object_get(data, "ConnectorId") != NULL)
  9374. {
  9375. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9376. }
  9377. if(json_object_object_get(data, "SerialNo") != NULL)
  9378. {
  9379. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9380. }
  9381. if(json_object_object_get(data, "Page_Index") != NULL)
  9382. {
  9383. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9384. }
  9385. if(json_object_object_get(data, "Duration") != NULL)
  9386. {
  9387. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9388. }
  9389. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9390. }
  9391. else
  9392. {
  9393. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9394. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9395. }
  9396. json_object_put(data);
  9397. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9398. json_object_put(response);
  9399. }
  9400. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9401. {
  9402. json_object *data;
  9403. data = json_tokener_parse(tempdata);
  9404. if(!is_error(data))
  9405. {
  9406. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9407. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9408. {
  9409. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9410. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9411. else
  9412. {
  9413. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9414. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9415. }
  9416. }
  9417. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9418. {
  9419. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9420. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9421. else
  9422. {
  9423. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9424. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9425. }
  9426. }
  9427. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9428. {
  9429. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9430. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9431. else
  9432. {
  9433. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9434. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9435. }
  9436. }
  9437. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9438. {
  9439. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9440. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9441. else
  9442. {
  9443. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9444. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9445. }
  9446. }
  9447. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9448. {
  9449. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9450. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9451. else
  9452. {
  9453. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9454. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9455. }
  9456. }
  9457. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9458. {
  9459. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9460. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9461. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9462. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9463. else
  9464. {
  9465. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9466. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9467. }
  9468. }
  9469. if(json_object_object_get(data, "isAuthentication") != NULL)
  9470. {
  9471. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9472. {
  9473. case 0:
  9474. case 1:
  9475. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9476. break;
  9477. default:
  9478. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9479. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9480. break;
  9481. }
  9482. }
  9483. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9484. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9485. }
  9486. else
  9487. {
  9488. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9489. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9490. }
  9491. json_object_put(data);
  9492. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9493. json_object_put(response);
  9494. }
  9495. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9496. {
  9497. json_object *data;
  9498. data = json_tokener_parse(tempdata);
  9499. if(!is_error(data))
  9500. {
  9501. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9502. if(json_object_object_get(data, "stationName") != NULL)
  9503. {
  9504. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9505. }
  9506. else
  9507. {
  9508. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9509. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9510. }
  9511. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9512. {
  9513. ShmOCPP16DataPH->TcciCustomData.ChargerInfoReq = 1;
  9514. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9515. ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name);
  9516. }
  9517. }
  9518. else
  9519. {
  9520. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9521. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9522. }
  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, "ID_Weather_Info") != NULL)
  9527. {
  9528. json_object *data;
  9529. data = json_tokener_parse(tempdata);
  9530. if(!is_error(data))
  9531. {
  9532. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9533. if(json_object_object_get(data, "weatherId") != NULL)
  9534. {
  9535. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9536. }
  9537. else
  9538. {
  9539. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9540. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9541. }
  9542. if(json_object_object_get(data, "Temperature") != NULL)
  9543. {
  9544. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9545. }
  9546. else
  9547. {
  9548. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9549. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9550. }
  9551. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9552. {
  9553. ShmOCPP16DataPH->TcciCustomData.WeatherInfoReq = 1;
  9554. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9555. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId,
  9556. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature);
  9557. }
  9558. }
  9559. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9560. {
  9561. json_object *data;
  9562. data = json_tokener_parse(tempdata);
  9563. if(!is_error(data))
  9564. {
  9565. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9566. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9567. {
  9568. ShmOCPP16DataPH->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9569. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9570. }
  9571. else
  9572. {
  9573. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9574. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9575. }
  9576. }
  9577. else
  9578. {
  9579. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9580. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9581. }
  9582. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9583. json_object_put(response);
  9584. }
  9585. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  9586. {
  9587. json_object *data;
  9588. data = json_tokener_parse(tempdata);
  9589. if(!is_error(data))
  9590. {
  9591. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9592. {
  9593. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  9594. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9595. if(gun_index < gunTotalNumber)
  9596. {
  9597. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9598. {
  9599. json_object *responsedata = json_object_new_object();
  9600. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId));
  9601. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  9602. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16DataPH->TcciCustomData.SerialNo[gun_index]));
  9603. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp));
  9604. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  9605. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  9606. }
  9607. else
  9608. {
  9609. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9610. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  9611. }
  9612. }
  9613. else
  9614. {
  9615. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9616. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  9617. }
  9618. }
  9619. else
  9620. {
  9621. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9622. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9623. }
  9624. }
  9625. else
  9626. {
  9627. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9628. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9629. }
  9630. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9631. json_object_put(response);
  9632. }
  9633. else
  9634. {
  9635. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9636. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9637. }
  9638. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9639. json_object_put(response);
  9640. }
  9641. else
  9642. {
  9643. // Can not find valid message id
  9644. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9645. }
  9646. }
  9647. else
  9648. {
  9649. // Payload is null
  9650. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9651. }
  9652. LWS_Send(message);
  9653. return result;
  9654. }
  9655. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9656. {
  9657. mtrace();
  9658. int result = FAIL;
  9659. int connectorIdInt, durationInt;
  9660. char chargingRateUnitStr[4]={0};
  9661. char comfirmstr[20];
  9662. int confirmPeriods = 0;
  9663. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9664. json_object *GetCompositeSchedule;
  9665. GetCompositeSchedule = json_tokener_parse(payload);
  9666. if(!is_error(GetCompositeSchedule))
  9667. {
  9668. // Required data
  9669. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9670. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9671. else
  9672. connectorIdInt = -1;
  9673. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9674. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9675. else
  9676. durationInt = 86400;
  9677. // Optional data
  9678. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9679. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9680. }
  9681. json_object_put(GetCompositeSchedule);
  9682. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9683. if((connectorIdInt == 0) ||
  9684. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9685. {
  9686. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9687. struct StructChargingProfile tmpProfile[1];
  9688. if(strstr(chargingRateUnitStr, "W") != NULL)
  9689. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9690. else
  9691. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9692. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9693. {
  9694. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9695. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9696. }
  9697. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9698. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9699. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9700. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9701. {
  9702. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9703. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9704. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9705. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9706. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9707. {
  9708. confirmPeriods = idx;
  9709. break;
  9710. }
  9711. }
  9712. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9713. {
  9714. confirmPeriods += 1;
  9715. }
  9716. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9717. }
  9718. else
  9719. {
  9720. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9721. }
  9722. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9723. return result;
  9724. }
  9725. int handleGetConfigurationRequest(char *uuid, char *payload)
  9726. {
  9727. mtrace();
  9728. int result = FAIL;
  9729. int MaxKeySupported = 0;
  9730. int n_keys = 0;
  9731. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9732. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9733. json_object *GetConfiguration;
  9734. GetConfiguration = json_tokener_parse(payload);
  9735. if(!is_error(GetConfiguration))
  9736. {
  9737. // Optional data
  9738. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9739. {
  9740. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9741. {
  9742. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9743. n_keys = idx + 1;
  9744. }
  9745. }
  9746. }
  9747. json_object_put(GetConfiguration);
  9748. UnknownKeynum = 0;
  9749. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9750. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9751. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9752. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9753. if(n_keys != 0)
  9754. {
  9755. for(int i=0;i<n_keys;i++)
  9756. {
  9757. getKeyValue(requestKey[i]);
  9758. }
  9759. }
  9760. else
  9761. {
  9762. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9763. getKeyValue("");
  9764. }
  9765. processUnkownKey();
  9766. sendGetConfigurationConfirmation(uuid);
  9767. return result;
  9768. }
  9769. static char fnamePlusPath[100]={0};
  9770. static char fnamePWithNoPath[60]={0};
  9771. void checkUploadLog(void)
  9772. {
  9773. FILE *fp;
  9774. /* Open the command for reading. */
  9775. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9776. if (fp == NULL) {
  9777. DEBUG_WARN("Failed to run command\n" );
  9778. exit(1);
  9779. }
  9780. int ftppathlen = 0;
  9781. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9782. int i = 0;
  9783. /* Read the output a line at a time - output it. */
  9784. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9785. if(i==0)
  9786. {
  9787. ftppathlen = strlen(fnamePlusPath);
  9788. DEBUG_INFO("%s\n", fnamePlusPath);
  9789. fnamePlusPath[ftppathlen]='\0';
  9790. break;
  9791. }
  9792. i= i+1;
  9793. }
  9794. /* close */
  9795. pclose(fp);
  9796. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9797. {
  9798. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9799. {
  9800. fnamePlusPath[k]='\0';
  9801. }
  9802. }
  9803. i=1;
  9804. //char fname[60]={0};
  9805. while(i < ftppathlen)
  9806. {
  9807. int len=ftppathlen-i;
  9808. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9809. {
  9810. DEBUG_INFO("compare '/' all right\n");
  9811. break;
  9812. }
  9813. i=i+1;
  9814. }
  9815. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9816. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9817. fnamePWithNoPath[i+1] = '\0';
  9818. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9819. {
  9820. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9821. {
  9822. fnamePWithNoPath[j]='\0';
  9823. }
  9824. }
  9825. FILE* fp1 = fopen(fnamePlusPath, "r");
  9826. if (fp1)
  9827. {
  9828. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9829. // file exists
  9830. fclose(fp1);
  9831. }
  9832. else
  9833. {
  9834. // file doesn't exist
  9835. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9836. }
  9837. }
  9838. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9839. {
  9840. mtrace();
  9841. int result = FAIL;
  9842. time_t CurrentTime;
  9843. struct tm *tm;
  9844. pthread_t th_Status;
  9845. CurrentTime = time(NULL);
  9846. tm = localtime(&CurrentTime);
  9847. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  9848. sprintf((char*)ShmOCPP16DataPH->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);
  9849. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9850. if(!interLock.isGetDiagnosticGoing)
  9851. {
  9852. interLock.isGetDiagnosticGoing = 1;
  9853. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9854. sleep(1);
  9855. }
  9856. else
  9857. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9858. return result;
  9859. }
  9860. void* GetDiagnosticsProcess(void* data)
  9861. {
  9862. pthread_detach(pthread_self());
  9863. mtrace();
  9864. int retriesInt=0, retryIntervalInt=0;
  9865. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9866. char protocol[10]={0}, user[64]={0},password[128]={0},host[128]={0}, path[512]={0}, ftppath[512]={0},host1[128]={0},path1[512]={0};
  9867. int port=0;
  9868. int isSuccess = FALSE;
  9869. char ftpbuf[200]={0};
  9870. char cmdBuf[2048];
  9871. struct tm *tmNow;
  9872. time_t CurrentTime;
  9873. struct tm tmStart;
  9874. struct tm tmStop;
  9875. CurrentTime = time(NULL);
  9876. tmNow=localtime(&CurrentTime);
  9877. uint16_t targetYear, targetMonth;
  9878. json_object *GetDiagnostics;
  9879. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9880. GetDiagnostics = json_tokener_parse(data);
  9881. if(!is_error(GetDiagnostics))
  9882. {
  9883. // Required data
  9884. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9885. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9886. // Optional data
  9887. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9888. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9889. else
  9890. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9891. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9892. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9893. else
  9894. retryIntervalInt = 30;
  9895. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9896. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9897. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9898. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9899. }
  9900. json_object_put(GetDiagnostics);
  9901. // Pack log to compress file
  9902. 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) &&
  9903. (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))
  9904. {
  9905. // Pack system log
  9906. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9907. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9908. targetYear = tmStart.tm_year;
  9909. targetMonth = tmStart.tm_mon;
  9910. do
  9911. {
  9912. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9913. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9914. if(targetMonth+1>=13)
  9915. {
  9916. targetYear += 1;
  9917. targetMonth = 1;
  9918. }
  9919. else
  9920. {
  9921. targetMonth += 1;
  9922. }
  9923. }while((targetYear < (tmNow->tm_year+1900)) ||
  9924. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9925. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9926. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9927. system(cmdBuf);
  9928. // Pack charging & event log
  9929. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9930. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9931. targetYear = tmStart.tm_year;
  9932. targetMonth = tmStart.tm_mon;
  9933. do
  9934. {
  9935. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9936. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9937. if(targetMonth+1>=13)
  9938. {
  9939. targetYear += 1;
  9940. targetMonth = 1;
  9941. }
  9942. else
  9943. {
  9944. targetMonth += 1;
  9945. }
  9946. }while((targetYear < (tmNow->tm_year+1900)) ||
  9947. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9948. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9949. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9950. system(cmdBuf);
  9951. // Combine log file
  9952. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9953. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9954. }
  9955. else
  9956. {
  9957. system("exec /root/logPackTools 'log' 6");
  9958. }
  9959. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9960. system(cmdBuf);
  9961. checkUploadLog();
  9962. //****************location*******************/
  9963. if(strcmp(locationstr,"")==0)
  9964. {
  9965. DEBUG_INFO("location is <Empty>!\n");
  9966. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9967. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9968. goto end;
  9969. }
  9970. memset(protocol, 0, ARRAY_SIZE(protocol));
  9971. memset(user, 0, ARRAY_SIZE(user) );
  9972. memset(password, 0, ARRAY_SIZE(password));
  9973. memset(host, 0, ARRAY_SIZE(host));
  9974. memset(path, 0, ARRAY_SIZE(path));
  9975. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9976. memset(host1, 0, ARRAY_SIZE(host1));
  9977. memset(path1, 0, ARRAY_SIZE(path1));
  9978. /*location: ftp://user:password@host:port/path*/
  9979. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9980. if((access(fnamePlusPath,F_OK))!=-1)
  9981. {
  9982. DEBUG_INFO("fnamePlusPath exist.\n");
  9983. }
  9984. else
  9985. {
  9986. DEBUG_INFO("fnamePlusPath not exist!\n");
  9987. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9988. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9989. goto end;
  9990. }
  9991. if(strchr(locationstr,'@')==NULL)
  9992. {
  9993. sscanf(locationstr,
  9994. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9995. protocol, host, &port, path);
  9996. strcpy(user,"anonymous");
  9997. strcpy(password,"");
  9998. }
  9999. else
  10000. {
  10001. //DEBUG_INFO("pch=%s\n", pch);
  10002. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10003. protocol, user, password, host, &port, path);
  10004. }
  10005. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10006. {
  10007. DEBUG_INFO("protocol is not ftp/http ! \n");
  10008. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10009. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10010. goto end;
  10011. }
  10012. if(strncmp(locationstr,"http", 4) == 0)
  10013. {
  10014. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10015. sprintf(ftppath,"/%s", path);
  10016. do
  10017. {
  10018. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10019. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10020. sleep(3);
  10021. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10022. if(!isSuccess)
  10023. {
  10024. DEBUG_INFO("Diagnostics fail.\n");
  10025. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10026. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10027. sleep(retryIntervalInt);
  10028. }
  10029. else
  10030. {
  10031. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10032. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10033. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10034. }
  10035. retriesInt--;
  10036. }while((isSuccess == 0)&&(retriesInt >= 0));
  10037. }
  10038. else
  10039. {
  10040. sscanf(host,"%[^/]%s",host1, path1);
  10041. if(strlen(path) > 0)
  10042. sprintf(ftppath,"/%s", path);
  10043. else
  10044. sprintf(ftppath,"/%s", path1);
  10045. int ftppathlen=strlen(ftppath);
  10046. int i=1;
  10047. char filenametemp[50];
  10048. while(i < ftppathlen)
  10049. {
  10050. int len=ftppathlen-i;
  10051. if(ftppath[len]== 47) // '/' ascll code: 47
  10052. {
  10053. DEBUG_INFO("find '/' all right\n");
  10054. break;
  10055. }
  10056. i=i+1;
  10057. }
  10058. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10059. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10060. filenametemp[i+1] = 0;
  10061. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10062. if(port == 0)
  10063. port = 21;
  10064. do
  10065. {
  10066. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10067. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10068. sleep(3);
  10069. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10070. if(!isSuccess)
  10071. {
  10072. DEBUG_INFO("Diagnostics fail.\n");
  10073. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10074. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10075. sleep(retryIntervalInt);
  10076. }
  10077. else
  10078. {
  10079. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10080. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10081. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10082. }
  10083. retriesInt--;
  10084. }while((!isSuccess)&&(retriesInt >= 0));
  10085. }
  10086. end:
  10087. system("rm -f /mnt/*");
  10088. sleep(5);
  10089. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10090. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10091. interLock.isGetDiagnosticGoing = 0;
  10092. pthread_exit(NULL);
  10093. }
  10094. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10095. {
  10096. mtrace();
  10097. int result = FAIL;
  10098. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10099. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10100. {
  10101. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10102. locallistVersion = -1;
  10103. }
  10104. else
  10105. {
  10106. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10107. locallistVersion = 0;
  10108. OCPP_getListVerion();
  10109. }
  10110. //from db.OCPP_getListVerion
  10111. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10112. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  10113. sendGetLocalListVersionConfirmation(uuid,"");
  10114. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  10115. return result;
  10116. }
  10117. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10118. {
  10119. mtrace();
  10120. int result = FAIL;
  10121. int connectorIdInt=-1;
  10122. int tempIndex = 0;
  10123. int connectorIdIsNULL, chargingProfileIsNULL;
  10124. char comfirmstr[20]={0};
  10125. char cmdBuf[512];
  10126. json_object *RemoteStartTransaction;
  10127. FILE *fp;
  10128. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10129. if(server_pending == TRUE)
  10130. {
  10131. return 0;
  10132. }
  10133. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10134. RemoteStartTransaction = json_tokener_parse(payload);
  10135. if(!is_error(RemoteStartTransaction))
  10136. {
  10137. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10138. {
  10139. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10140. }
  10141. else
  10142. {
  10143. connectorIdIsNULL = TRUE;
  10144. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10145. {
  10146. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10147. {
  10148. connectorIdIsNULL = FALSE;
  10149. connectorIdInt = (gun_index+1);
  10150. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10151. break;
  10152. }
  10153. }
  10154. }
  10155. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10156. {
  10157. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10158. // Required data
  10159. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10160. // Optional data
  10161. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10162. {
  10163. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10164. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10165. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10166. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10167. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10168. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10169. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10170. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10171. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10172. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10173. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10174. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10175. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10176. {
  10177. sprintf((char*)ShmOCPP16DataPH->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")));
  10178. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10179. ShmOCPP16DataPH->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"));
  10180. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10181. ShmOCPP16DataPH->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"));
  10182. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10183. sprintf((char*)ShmOCPP16DataPH->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")));
  10184. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10185. {
  10186. 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++)
  10187. {
  10188. ShmOCPP16DataPH->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"));
  10189. ShmOCPP16DataPH->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"));
  10190. 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)
  10191. ShmOCPP16DataPH->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"));
  10192. }
  10193. }
  10194. }
  10195. }
  10196. else
  10197. {
  10198. chargingProfileIsNULL = TRUE;
  10199. }
  10200. }
  10201. }
  10202. else
  10203. {
  10204. connectorIdIsNULL = TRUE;
  10205. }
  10206. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10207. {
  10208. DEBUG_WARN("Connector id is NULL\n.");
  10209. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10210. goto end;
  10211. }
  10212. /*
  10213. enum _SYSTEM_STATUS
  10214. {
  10215. S_BOOTING = 0,
  10216. S_IDLE, = 1
  10217. S_AUTHORIZING, = 2
  10218. S_REASSIGN_CHECK, = 3
  10219. S_REASSIGN, = 4
  10220. S_PRECHARGE, = 5
  10221. S_PREPARING_FOR_EV, = 6
  10222. S_PREPARING_FOR_EVSE, = 7
  10223. S_CHARGING, = 8
  10224. S_TERMINATING, = 9
  10225. S_COMPLETE, = 10
  10226. S_ALARM, = 11
  10227. S_FAULT = 12
  10228. }
  10229. */
  10230. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10231. {
  10232. //check Transaction active
  10233. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10234. {
  10235. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10236. {
  10237. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10238. }
  10239. else
  10240. {
  10241. tempIndex = connectorIdInt -1;
  10242. }
  10243. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10244. {
  10245. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10246. {
  10247. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10248. {
  10249. //Reserved
  10250. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10251. }
  10252. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10253. {
  10254. //Reserved
  10255. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10256. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10257. goto end;
  10258. }
  10259. else
  10260. {
  10261. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10262. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10263. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10264. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10265. {
  10266. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10267. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10268. goto end;
  10269. }
  10270. }//END FOR ELSE
  10271. }
  10272. }// END FOR CHAdeMO_QUANTITY
  10273. }
  10274. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10275. {
  10276. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10277. {
  10278. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10279. }
  10280. else
  10281. {
  10282. tempIndex = connectorIdInt -1;
  10283. }
  10284. for (int index = 0; index < CCS_QUANTITY; index++)
  10285. {
  10286. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10287. {
  10288. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10289. {
  10290. //Reserved
  10291. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10292. }
  10293. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10294. {
  10295. //Reserved
  10296. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10297. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10298. goto end;
  10299. }
  10300. else
  10301. {
  10302. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10303. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10304. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10305. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10306. {
  10307. DEBUG_WARN("CCS connector not allow start\n.");
  10308. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10309. goto end;
  10310. }
  10311. }// END FOR ELSE
  10312. }
  10313. }// END FOR CCS_QUANTITY
  10314. }
  10315. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10316. {
  10317. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10318. {
  10319. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10320. }
  10321. else
  10322. {
  10323. tempIndex = connectorIdInt -1;
  10324. }
  10325. for (int index = 0; index < GB_QUANTITY; index++)
  10326. {
  10327. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10328. {
  10329. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10330. {
  10331. //Reserved
  10332. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10333. }
  10334. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10335. {
  10336. //Reserved
  10337. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10338. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10339. goto end;
  10340. }
  10341. else
  10342. {
  10343. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10344. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10345. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10346. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10347. {
  10348. DEBUG_WARN("GB connector not allow start\n.");
  10349. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10350. goto end;
  10351. }
  10352. }// END FOR ELSE
  10353. }
  10354. } // END FOR GB_QUANTITY
  10355. }
  10356. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10357. {
  10358. tempIndex = connectorIdInt -1;
  10359. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10360. {
  10361. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10362. {
  10363. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10364. {
  10365. //Reserved
  10366. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10367. }
  10368. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10369. {
  10370. //Reserved
  10371. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10372. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10373. goto end;
  10374. }
  10375. else
  10376. {
  10377. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10378. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10379. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10380. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10381. {
  10382. DEBUG_WARN("GB connector not allow start\n.");
  10383. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10384. goto end;
  10385. }
  10386. }// END FOR ELSE
  10387. }
  10388. } // END FOR GB_QUANTITY
  10389. }
  10390. else
  10391. {
  10392. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10393. {
  10394. tempIndex = 2;
  10395. }
  10396. else
  10397. {
  10398. tempIndex = connectorIdInt -1;
  10399. }
  10400. for (int index = 0; index < AC_QUANTITY; index++)
  10401. {
  10402. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10403. {
  10404. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10405. {
  10406. //Reserved
  10407. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10408. }
  10409. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10410. {
  10411. //Reserved
  10412. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10413. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10414. goto end;
  10415. }
  10416. else
  10417. {
  10418. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10419. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10420. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10421. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10422. {
  10423. DEBUG_WARN("AC connector not allow start\n.");
  10424. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10425. goto end;
  10426. }
  10427. }//END FOR ELSE
  10428. }
  10429. }// END FOR AC_QUANTITY
  10430. }
  10431. if(chargingProfileIsNULL == FALSE)
  10432. {
  10433. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10434. {
  10435. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10436. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10437. //memset idTag
  10438. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10439. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10440. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10441. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10442. // Save profile to file
  10443. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10444. system(cmdBuf);
  10445. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10446. fp = fopen(cmdBuf, "w");
  10447. 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));
  10448. fclose(fp);
  10449. }
  10450. else
  10451. {
  10452. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10453. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10454. }
  10455. }
  10456. else
  10457. {
  10458. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10459. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10460. //memset idTag
  10461. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10462. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10463. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10464. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10465. }
  10466. }
  10467. else
  10468. {
  10469. DEBUG_WARN("Connector id over\n.");
  10470. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10471. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10472. }
  10473. end:
  10474. json_object_put(RemoteStartTransaction);
  10475. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10476. {
  10477. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10478. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10479. }
  10480. //OCPP send RemoteStartConfirmation by first.
  10481. sendRemoteStartConfirmation(uuid, comfirmstr);
  10482. return result;
  10483. }
  10484. int handleRemoteStartRequest(char *uuid, char *payload)
  10485. {
  10486. mtrace();
  10487. int result = PASS;
  10488. int connectorIdInt=-1;
  10489. int tempIndex = 0;
  10490. char comfirmstr[20]={0};
  10491. char cmdBuf[512];
  10492. json_object *RemoteStartTransaction;
  10493. FILE *fp;
  10494. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10495. if(server_pending == TRUE)
  10496. {
  10497. result = FAIL;
  10498. }
  10499. RemoteStartTransaction = json_tokener_parse(payload);
  10500. if(!is_error(RemoteStartTransaction))
  10501. {
  10502. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10503. {
  10504. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10505. }
  10506. else
  10507. {
  10508. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10509. {
  10510. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10511. {
  10512. connectorIdInt = (gun_index+1);
  10513. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10514. break;
  10515. }
  10516. }
  10517. }
  10518. if(connectorIdInt == 0)
  10519. {
  10520. DEBUG_WARN("Connector id shall not equal 0.\n");
  10521. result = FAIL;
  10522. }
  10523. else if(connectorIdInt == -1)
  10524. {
  10525. DEBUG_INFO("Connector id does not specific.\n");
  10526. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10527. {
  10528. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10529. // Required data
  10530. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10531. // Optional data
  10532. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10533. {
  10534. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10535. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10536. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10537. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10538. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10539. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10540. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10541. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10542. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10543. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10544. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10545. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10546. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10547. {
  10548. sprintf((char*)ShmOCPP16DataPH->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")));
  10549. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10550. ShmOCPP16DataPH->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"));
  10551. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10552. ShmOCPP16DataPH->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"));
  10553. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10554. sprintf((char*)ShmOCPP16DataPH->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")));
  10555. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10556. {
  10557. 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++)
  10558. {
  10559. ShmOCPP16DataPH->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"));
  10560. ShmOCPP16DataPH->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"));
  10561. 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)
  10562. ShmOCPP16DataPH->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"));
  10563. }
  10564. }
  10565. }
  10566. }
  10567. else
  10568. {
  10569. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10570. }
  10571. }
  10572. }
  10573. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10574. {
  10575. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10576. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10577. // Required data
  10578. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10579. // Optional data
  10580. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10581. {
  10582. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10583. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10584. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10585. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10586. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10587. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10588. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10589. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10590. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10591. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10592. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10593. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10594. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10595. {
  10596. sprintf((char*)ShmOCPP16DataPH->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")));
  10597. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10598. ShmOCPP16DataPH->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"));
  10599. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10600. ShmOCPP16DataPH->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"));
  10601. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10602. sprintf((char*)ShmOCPP16DataPH->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")));
  10603. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10604. {
  10605. 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++)
  10606. {
  10607. ShmOCPP16DataPH->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"));
  10608. ShmOCPP16DataPH->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"));
  10609. 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)
  10610. ShmOCPP16DataPH->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"));
  10611. }
  10612. }
  10613. }
  10614. }
  10615. else
  10616. {
  10617. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10618. }
  10619. }
  10620. else
  10621. {
  10622. DEBUG_WARN("Connector id is over maximun value.\n");
  10623. result = FAIL;
  10624. }
  10625. }
  10626. if(result == PASS)
  10627. {
  10628. if(connectorIdInt > 0)
  10629. {
  10630. //check Transaction active
  10631. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10632. {
  10633. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10634. {
  10635. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10636. }
  10637. else
  10638. {
  10639. tempIndex = connectorIdInt -1;
  10640. }
  10641. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10642. {
  10643. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10644. {
  10645. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10646. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10647. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10648. {
  10649. //Reserved
  10650. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10651. }
  10652. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10653. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10654. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10655. {
  10656. //Reserved
  10657. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10658. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10659. goto end;
  10660. }
  10661. else
  10662. {
  10663. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10664. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10665. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10666. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10667. {
  10668. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10669. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10670. goto end;
  10671. }
  10672. }//END FOR ELSE
  10673. }
  10674. }// END FOR CHAdeMO_QUANTITY
  10675. }
  10676. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10677. {
  10678. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10679. {
  10680. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10681. }
  10682. else
  10683. {
  10684. tempIndex = connectorIdInt -1;
  10685. }
  10686. for (int index = 0; index < CCS_QUANTITY; index++)
  10687. {
  10688. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10689. {
  10690. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10691. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10692. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10693. {
  10694. //Reserved
  10695. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10696. }
  10697. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10698. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10699. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10700. {
  10701. //Reserved
  10702. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10703. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10704. goto end;
  10705. }
  10706. else
  10707. {
  10708. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10709. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10710. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10711. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10712. {
  10713. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10714. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10715. goto end;
  10716. }
  10717. }// END FOR ELSE
  10718. }
  10719. }// END FOR CCS_QUANTITY
  10720. }
  10721. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10722. {
  10723. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10724. {
  10725. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10726. }
  10727. else
  10728. {
  10729. tempIndex = connectorIdInt -1;
  10730. }
  10731. for (int index = 0; index < GB_QUANTITY; index++)
  10732. {
  10733. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10734. {
  10735. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10736. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10737. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10738. {
  10739. //Reserved
  10740. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10741. }
  10742. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10743. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10744. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10745. {
  10746. //Reserved
  10747. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10748. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10749. goto end;
  10750. }
  10751. else
  10752. {
  10753. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10754. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10755. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10756. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10757. {
  10758. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10759. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10760. goto end;
  10761. }
  10762. }// END FOR ELSE
  10763. }
  10764. } // END FOR GB_QUANTITY
  10765. }
  10766. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10767. {
  10768. tempIndex = connectorIdInt -1;
  10769. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10770. {
  10771. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10772. {
  10773. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10774. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10775. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10776. {
  10777. //Reserved
  10778. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10779. }
  10780. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10781. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10782. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10783. {
  10784. //Reserved
  10785. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10786. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10787. goto end;
  10788. }
  10789. else
  10790. {
  10791. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10792. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10793. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10794. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10795. {
  10796. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10797. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10798. goto end;
  10799. }
  10800. }// END FOR ELSE
  10801. }
  10802. } // END FOR GB_QUANTITY
  10803. }
  10804. else
  10805. {
  10806. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10807. {
  10808. tempIndex = 2;
  10809. }
  10810. else
  10811. {
  10812. tempIndex = connectorIdInt -1;
  10813. }
  10814. for (int index = 0; index < AC_QUANTITY; index++)
  10815. {
  10816. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10817. {
  10818. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10819. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10820. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10821. {
  10822. //Reserved
  10823. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10824. }
  10825. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10826. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10827. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10828. {
  10829. //Reserved
  10830. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10831. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10832. goto end;
  10833. }
  10834. else
  10835. {
  10836. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10837. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10838. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10839. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10840. {
  10841. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10842. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10843. goto end;
  10844. }
  10845. }//END FOR ELSE
  10846. }
  10847. }// END FOR AC_QUANTITY
  10848. }
  10849. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10850. {
  10851. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10852. {
  10853. // Save profile to file
  10854. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10855. system(cmdBuf);
  10856. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10857. fp = fopen(cmdBuf, "w");
  10858. 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));
  10859. fclose(fp);
  10860. }
  10861. else
  10862. {
  10863. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10864. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10865. goto end;
  10866. }
  10867. }
  10868. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10869. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10870. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10871. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10872. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10873. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10874. }
  10875. else
  10876. {
  10877. uint8_t isHasIdleConnector = FALSE;
  10878. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10879. {
  10880. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10881. {
  10882. isHasIdleConnector = TRUE;
  10883. break;
  10884. }
  10885. }
  10886. if(isHasIdleConnector == TRUE)
  10887. {
  10888. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10889. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10890. {
  10891. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10892. {
  10893. // Save profile to file
  10894. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  10895. system(cmdBuf);
  10896. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  10897. fp = fopen(cmdBuf, "w");
  10898. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10899. fclose(fp);
  10900. refreshStartTimer(&clientTime.RemoteStartWait);
  10901. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10902. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10903. }
  10904. else
  10905. {
  10906. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10907. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10908. }
  10909. }
  10910. else
  10911. {
  10912. refreshStartTimer(&clientTime.RemoteStartWait);
  10913. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10914. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10915. }
  10916. }
  10917. else
  10918. {
  10919. DEBUG_INFO("There is not any connector is idle.\n");
  10920. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10921. }
  10922. }
  10923. }
  10924. else
  10925. {
  10926. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10927. }
  10928. end:
  10929. json_object_put(RemoteStartTransaction);
  10930. sendRemoteStartConfirmation(uuid, comfirmstr);
  10931. return result;
  10932. }
  10933. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10934. {
  10935. mtrace();
  10936. int result = FAIL;
  10937. int match = FALSE;
  10938. int GunNO = 0;
  10939. int tempIndex = 0;
  10940. int transactionIdInt=0;
  10941. int transactionIdIsNULL= TRUE;
  10942. char comfirmstr[20];
  10943. json_object *RemoteStopTransaction;
  10944. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10945. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10946. if(server_pending == TRUE)
  10947. {
  10948. return 0;
  10949. }
  10950. RemoteStopTransaction = json_tokener_parse(payload);
  10951. if(!is_error(RemoteStopTransaction))
  10952. {
  10953. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10954. {
  10955. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10956. transactionIdIsNULL = FALSE;
  10957. }
  10958. }
  10959. json_object_put(RemoteStopTransaction);
  10960. if(transactionIdIsNULL == FALSE)
  10961. {
  10962. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10963. {
  10964. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10965. {
  10966. //check Transaction active
  10967. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10968. {
  10969. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10970. {
  10971. tempIndex = ((gun_index==2) ? 1: 0);
  10972. }
  10973. else
  10974. {
  10975. tempIndex = gun_index;
  10976. }
  10977. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10978. {
  10979. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10980. {
  10981. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10982. {
  10983. match = TRUE;
  10984. GunNO = gun_index;
  10985. }
  10986. }
  10987. }// END FOR CHAdeMO_QUANTITY
  10988. }
  10989. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10990. {
  10991. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10992. {
  10993. tempIndex = ((gun_index==2) ? 1: 0);
  10994. }
  10995. else
  10996. {
  10997. tempIndex = gun_index;
  10998. }
  10999. for (int index = 0; index < CCS_QUANTITY; index++)
  11000. {
  11001. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11002. {
  11003. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11004. {
  11005. match = TRUE;
  11006. GunNO = gun_index;
  11007. }
  11008. }
  11009. }// END FOR CCS_QUANTITY
  11010. }
  11011. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11012. {
  11013. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11014. {
  11015. tempIndex = ((gun_index==2) ? 1: 0);
  11016. }
  11017. else
  11018. {
  11019. tempIndex = gun_index;
  11020. }
  11021. for (int index = 0; index < GB_QUANTITY; index++)
  11022. {
  11023. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11024. {
  11025. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11026. {
  11027. match = TRUE;
  11028. GunNO = gun_index;
  11029. }
  11030. }
  11031. }// END FOR GB_QUANTITY
  11032. }
  11033. else if(gunType[gun_index] == GUN_TYPE_DO)
  11034. {
  11035. tempIndex = gun_index;
  11036. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11037. {
  11038. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11039. {
  11040. 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
  11041. {
  11042. match = TRUE;
  11043. GunNO = gun_index;
  11044. }
  11045. }
  11046. }// END FOR GB_QUANTITY
  11047. }
  11048. else
  11049. {
  11050. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11051. {
  11052. tempIndex = 2;
  11053. }
  11054. else
  11055. {
  11056. tempIndex = gun_index;
  11057. }
  11058. for (int index = 0; index < AC_QUANTITY; index++)
  11059. {
  11060. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11061. {
  11062. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11063. {
  11064. match = TRUE;
  11065. GunNO = gun_index;
  11066. }
  11067. }
  11068. }// END FOR CHAdeMO_QUANTITY
  11069. } // END FOR AC ELSE
  11070. }// CHECK IF ResponseTransactionId == transactionIdInt
  11071. }//END FOR
  11072. if( match == TRUE)
  11073. {
  11074. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11075. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11076. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11077. }
  11078. else
  11079. {
  11080. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11081. }
  11082. }
  11083. else
  11084. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11085. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11086. return result;
  11087. }
  11088. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11089. {
  11090. mtrace();
  11091. int result = FAIL;
  11092. int connectorIdInt=0, reservationIdInt=0;
  11093. int tempIndex = 0;
  11094. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11095. char comfirmstr[20]={0};
  11096. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11097. int c = 0;
  11098. char *loc;
  11099. //char *ptr;
  11100. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11101. strcpy(sstrtemp, stringtrimspace(payload));
  11102. //***(1)connectorId ****/
  11103. c=0;
  11104. loc = strstr(sstrtemp, "connectorId");
  11105. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11106. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11107. {
  11108. sstr[c] = loc[strlen("connectorId")+2+c];
  11109. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11110. c++;
  11111. }
  11112. sstr[c] = '\0';
  11113. connectorIdInt = atoi(sstr);
  11114. //***(2)expiryDate ****/
  11115. loc = strstr(sstrtemp, "expiryDate");
  11116. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11117. c = 0;
  11118. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11119. {
  11120. sstr[c] = loc[3+strlen("expiryDate")+c];
  11121. c++;
  11122. }
  11123. sstr[c] = '\0';
  11124. strcpy(expiryDatestr, sstr);
  11125. //***(3)idTag ****/
  11126. loc = strstr(sstrtemp, "idTag");
  11127. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11128. c = 0;
  11129. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11130. {
  11131. sstr[c] = loc[3+strlen("idTag")+c];
  11132. c++;
  11133. }
  11134. sstr[c] = '\0';
  11135. strcpy(idTagstr, sstr);
  11136. //***(4)parentIdTag ****/
  11137. loc = strstr(sstrtemp, "parentIdTag");
  11138. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11139. c = 0;
  11140. if(loc == NULL)
  11141. {
  11142. strcpy(parentIdTagstr, "");
  11143. }
  11144. else
  11145. {
  11146. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11147. {
  11148. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11149. c++;
  11150. }
  11151. sstr[c] = '\0';
  11152. strcpy(parentIdTagstr, sstr);
  11153. }
  11154. //***(5)reservationId ****/
  11155. c=0;
  11156. loc = strstr(sstrtemp, "reservationId");
  11157. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11158. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11159. {
  11160. sstr[c] = loc[strlen("reservationId")+2+c];
  11161. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11162. c++;
  11163. }
  11164. sstr[c] = '\0';
  11165. reservationIdInt = atoi(sstr);
  11166. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11167. /*
  11168. enum SYSTEM_STATUS
  11169. {
  11170. SYS_MODE_BOOTING = 0,
  11171. SYS_MODE_IDLE = 1,
  11172. SYS_MODE_AUTHORIZING = 2,
  11173. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11174. SYS_MODE_REASSIGN = 4,
  11175. SYS_MODE_PREPARING = 5,
  11176. SYS_MODE_PREPARE_FOR_EV = 6,
  11177. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11178. SYS_MODE_CHARGING = 8,
  11179. SYS_MODE_TERMINATING = 9,
  11180. SYS_MODE_COMPLETE = 10,
  11181. SYS_MODE_ALARM = 11,
  11182. SYS_MODE_FAULT = 12,
  11183. SYS_MODE_RESERVATION = 13,
  11184. SYS_MODE_BOOKING = 14,
  11185. SYS_MODE_MAINTAIN = 15,
  11186. SYS_MODE_DEBUG = 16,
  11187. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11188. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11189. SYS_MODE_UPDATE = 19
  11190. };
  11191. */
  11192. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11193. {
  11194. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11195. goto end;
  11196. }
  11197. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11198. {
  11199. //check Transaction active
  11200. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11201. {
  11202. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11203. {
  11204. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11205. }
  11206. else
  11207. {
  11208. tempIndex = connectorIdInt -1;
  11209. }
  11210. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11211. {
  11212. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11213. {
  11214. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11215. {
  11216. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11217. {
  11218. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11219. {
  11220. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11221. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11222. }
  11223. 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'))
  11224. {
  11225. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11226. }
  11227. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11228. {
  11229. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11230. }
  11231. else
  11232. {
  11233. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11234. }
  11235. }
  11236. 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
  11237. {
  11238. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11239. }
  11240. }
  11241. else
  11242. {
  11243. //replace reservation
  11244. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11245. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11246. }
  11247. }
  11248. } // END FOR CHAdeMO_QUANTITY
  11249. }
  11250. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11251. {
  11252. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11253. {
  11254. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11255. }
  11256. else
  11257. {
  11258. tempIndex = connectorIdInt -1;
  11259. }
  11260. for (int index = 0; index < CCS_QUANTITY; index++)
  11261. {
  11262. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11263. {
  11264. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11265. {
  11266. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11267. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11268. {
  11269. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11270. {
  11271. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11272. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11273. }
  11274. 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'))
  11275. {
  11276. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11277. }
  11278. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11279. {
  11280. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11281. }
  11282. else
  11283. {
  11284. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11285. }
  11286. }
  11287. 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
  11288. {
  11289. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11290. }
  11291. }
  11292. else
  11293. {
  11294. //replace reservation
  11295. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11296. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11297. }
  11298. }
  11299. } // END FOR CCS_QUANTITY
  11300. }
  11301. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11302. {
  11303. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11304. {
  11305. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11306. }
  11307. else
  11308. {
  11309. tempIndex = connectorIdInt -1;
  11310. }
  11311. for (int index = 0; index < GB_QUANTITY; index++)
  11312. {
  11313. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11314. {
  11315. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11316. {
  11317. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11318. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11319. {
  11320. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11321. {
  11322. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11323. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11324. }
  11325. 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'))
  11326. {
  11327. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11328. }
  11329. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11330. {
  11331. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11332. }
  11333. else
  11334. {
  11335. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11336. }
  11337. }
  11338. 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
  11339. {
  11340. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11341. }
  11342. }
  11343. else
  11344. {
  11345. //replace reservation
  11346. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11347. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11348. }
  11349. }
  11350. }// END FOR GB_QUANTITY
  11351. }
  11352. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11353. {
  11354. tempIndex = connectorIdInt -1;
  11355. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11356. {
  11357. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11358. {
  11359. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11360. {
  11361. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11362. 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
  11363. {
  11364. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11365. {
  11366. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11367. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11368. }
  11369. 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'))
  11370. {
  11371. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11372. }
  11373. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11374. {
  11375. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11376. }
  11377. else
  11378. {
  11379. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11380. }
  11381. }
  11382. 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
  11383. {
  11384. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11385. }
  11386. }
  11387. else
  11388. {
  11389. //replace reservation
  11390. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11391. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11392. }
  11393. }
  11394. }// END FOR GB_QUANTITY
  11395. }
  11396. else
  11397. {
  11398. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11399. {
  11400. tempIndex = 2;
  11401. }
  11402. else
  11403. {
  11404. tempIndex = (connectorIdInt -1);
  11405. }
  11406. for (int index = 0; index < AC_QUANTITY; index++)
  11407. {
  11408. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11409. {
  11410. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11411. {
  11412. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11413. {
  11414. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11415. {
  11416. 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))
  11417. {
  11418. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11419. }
  11420. else
  11421. {
  11422. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11423. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11424. }
  11425. }
  11426. 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'))
  11427. {
  11428. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11429. }
  11430. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11431. {
  11432. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11433. }
  11434. else
  11435. {
  11436. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11437. }
  11438. }
  11439. 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
  11440. {
  11441. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11442. }
  11443. }
  11444. else
  11445. {
  11446. //replace reservation
  11447. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11448. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11449. }
  11450. }
  11451. } // END FOR AC_QUANTITY
  11452. }
  11453. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11454. }
  11455. else if(connectorIdInt == 0)
  11456. {
  11457. //check Transaction active
  11458. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11459. {
  11460. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11461. {
  11462. 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'))
  11463. {
  11464. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11465. goto end;
  11466. }
  11467. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11468. {
  11469. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11470. goto end;
  11471. }
  11472. 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
  11473. {
  11474. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11475. goto end;
  11476. }
  11477. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11478. {
  11479. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11480. goto end;
  11481. }
  11482. }
  11483. }// END FOR CHAdeMO_QUANTITY
  11484. for (int index = 0; index < CCS_QUANTITY; index++)
  11485. {
  11486. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11487. {
  11488. 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'))
  11489. {
  11490. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11491. goto end;
  11492. }
  11493. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11494. {
  11495. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11496. goto end;
  11497. }
  11498. 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
  11499. {
  11500. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11501. goto end;
  11502. }
  11503. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11504. {
  11505. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11506. goto end;
  11507. }
  11508. }
  11509. } // END FOR CCS_QUANTITY
  11510. for (int index = 0; index < GB_QUANTITY; index++)
  11511. {
  11512. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11513. {
  11514. 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'))
  11515. {
  11516. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11517. goto end;
  11518. }
  11519. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11520. {
  11521. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11522. goto end;
  11523. }
  11524. 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
  11525. {
  11526. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11527. goto end;
  11528. }
  11529. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11530. {
  11531. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11532. goto end;
  11533. }
  11534. }
  11535. } // END FOR GB_QUANTITY
  11536. for (int index = 0; index < AC_QUANTITY; index++)
  11537. {
  11538. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11539. {
  11540. 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'))
  11541. {
  11542. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11543. goto end;
  11544. }
  11545. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11546. {
  11547. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11548. goto end;
  11549. }
  11550. 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
  11551. {
  11552. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11553. goto end;
  11554. }
  11555. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11556. {
  11557. 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))
  11558. {
  11559. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11560. goto end;
  11561. }
  11562. }
  11563. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11564. {
  11565. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11566. goto end;
  11567. }
  11568. }
  11569. }// END FOR AC_QUANTITY
  11570. //The connectorId is 0
  11571. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  11572. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11573. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11574. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  11575. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11576. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  11577. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11578. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  11579. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  11580. result = TRUE;
  11581. return result;
  11582. }
  11583. else
  11584. {
  11585. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11586. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11587. }
  11588. if(strcmp(comfirmstr,"Accepted") == 0)
  11589. {
  11590. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11591. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11592. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11593. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11594. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11595. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11596. result = TRUE;
  11597. return result;
  11598. }
  11599. end:
  11600. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11601. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11602. return result;
  11603. }
  11604. int handleResetRequest(char *uuid, char *payload)
  11605. {
  11606. mtrace();
  11607. int result = FAIL;
  11608. char sstr[10]={0},sstrtemp[30]={ 0 };
  11609. char typestr[10]={0};
  11610. char comfirmstr[20]={0};
  11611. int c = 0;
  11612. char *loc;
  11613. DEBUG_INFO("handleResetRequest...\n");
  11614. strcpy(sstrtemp, stringtrimspace(payload));
  11615. loc = strstr(sstrtemp, "type");
  11616. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11617. c = 0;
  11618. while (loc[3+strlen("type")+c] != '\"')
  11619. {
  11620. sstr[c] = loc[3+strlen("type")+c];
  11621. c++;
  11622. }
  11623. sstr[c] = '\0';
  11624. strcpy(typestr,sstr);
  11625. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11626. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11627. {
  11628. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11629. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11630. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11631. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11632. }
  11633. else
  11634. {
  11635. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11636. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11637. result = PASS;
  11638. }
  11639. sendResetConfirmation(uuid, comfirmstr);
  11640. return result;
  11641. }
  11642. int handleSendLocalListRequest(char *uuid, char *payload)
  11643. {
  11644. mtrace();
  11645. int result = FAIL;
  11646. char comfirmstr[20];
  11647. int checkState_Faulted = FALSE;
  11648. json_object *SendLocalList;
  11649. DEBUG_INFO("handleSendLocalListRequest...\n");
  11650. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11651. {
  11652. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11653. goto end;
  11654. }
  11655. //check Charge Point state
  11656. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11657. {
  11658. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11659. {
  11660. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11661. }
  11662. }
  11663. for (int index = 0; index < CCS_QUANTITY; index++)
  11664. {
  11665. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11666. {
  11667. checkState_Faulted = TRUE; //OCPP Status
  11668. }
  11669. }
  11670. for (int index = 0; index < GB_QUANTITY; index++)
  11671. {
  11672. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11673. {
  11674. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11675. }
  11676. }
  11677. //check Charge Point state
  11678. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11679. {
  11680. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11681. {
  11682. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11683. }
  11684. }
  11685. //check Charge Point state
  11686. for (int index = 0; index < AC_QUANTITY; index++)
  11687. {
  11688. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11689. {
  11690. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11691. }
  11692. }
  11693. if(checkState_Faulted == TRUE)
  11694. {
  11695. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11696. goto end;
  11697. }
  11698. // Parsing payload
  11699. SendLocalList = json_tokener_parse(payload);
  11700. if(!is_error(SendLocalList))
  11701. {
  11702. // Required data
  11703. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11704. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11705. // Optional data
  11706. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11707. {
  11708. //Check UpdateType
  11709. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11710. {
  11711. //Local list full update
  11712. DEBUG_INFO("Local list full update.\n");
  11713. locallistVersion = 0;
  11714. OCPP_getListVerion();
  11715. /*if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11716. {
  11717. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11718. goto end;
  11719. }*/
  11720. OCPP_cleanLocalList();
  11721. }
  11722. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11723. {
  11724. //Local list different update
  11725. DEBUG_INFO("Local list different update.\n");
  11726. locallistVersion = 0;
  11727. OCPP_getListVerion();
  11728. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11729. {
  11730. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11731. goto end;
  11732. }
  11733. }
  11734. else
  11735. {
  11736. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11737. goto end;
  11738. }
  11739. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11740. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11741. {
  11742. sprintf((char*)ShmOCPP16DataPH->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")));
  11743. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11744. {
  11745. sprintf((char*)ShmOCPP16DataPH->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")));
  11746. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11747. sprintf((char*)ShmOCPP16DataPH->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")));
  11748. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11749. sprintf((char*)ShmOCPP16DataPH->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")));
  11750. }
  11751. // Add to db
  11752. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11753. {
  11754. //Local list full update
  11755. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11756. idx,
  11757. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11758. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11759. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11760. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11761. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11762. // update list
  11763. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11764. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11765. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11766. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11767. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11768. }
  11769. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11770. {
  11771. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11772. idx,
  11773. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11774. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11775. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11776. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11777. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11778. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11779. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11780. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11781. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11782. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11783. }
  11784. }
  11785. }
  11786. else
  11787. {
  11788. //Check UpdateType
  11789. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11790. {
  11791. //Local list full update
  11792. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11793. OCPP_cleanLocalList();
  11794. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11795. goto end;
  11796. }
  11797. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11798. {
  11799. //Local list different update
  11800. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11801. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11802. goto end;
  11803. }
  11804. }
  11805. result = PASS;
  11806. }
  11807. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11808. end:
  11809. json_object_put(SendLocalList);
  11810. sendSendLocalListConfirmation(uuid, comfirmstr);
  11811. return result;
  11812. }
  11813. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11814. {
  11815. mtrace();
  11816. int result = FAIL;
  11817. struct StructSetChargingProfile SetProfileReq = {0};
  11818. int tempchargingProfileIdInt;
  11819. int tempstackLevelInt;
  11820. int chargingSchedulePeriodCount = 0;
  11821. char comfirmstr[20]={0};
  11822. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  11823. char rmFileCmd[128]={0};
  11824. int profileQuantity = 0;
  11825. int replaceableProfileCnt = 0;
  11826. json_object *SetChargingProfile;
  11827. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11828. SetChargingProfile = json_tokener_parse(payload);
  11829. if(!is_error(SetChargingProfile))
  11830. {
  11831. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11832. {
  11833. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11834. }
  11835. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11836. {
  11837. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11838. {
  11839. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11840. }
  11841. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11842. {
  11843. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11844. }
  11845. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11846. {
  11847. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11848. }
  11849. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11850. {
  11851. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11852. }
  11853. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11854. {
  11855. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11856. }
  11857. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11858. {
  11859. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11860. }
  11861. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11862. {
  11863. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11864. }
  11865. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11866. {
  11867. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11868. }
  11869. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11870. {
  11871. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11872. {
  11873. 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")));
  11874. }
  11875. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11876. {
  11877. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11878. }
  11879. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11880. {
  11881. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11882. }
  11883. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11884. {
  11885. 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")));
  11886. }
  11887. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11888. {
  11889. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11890. if(chargingSchedulePeriodCount <= 10)
  11891. {
  11892. 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++)
  11893. {
  11894. 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)
  11895. {
  11896. 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"));
  11897. }
  11898. 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)
  11899. {
  11900. 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"));
  11901. }
  11902. 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)
  11903. {
  11904. 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"));
  11905. }
  11906. }
  11907. }
  11908. }
  11909. }
  11910. }
  11911. }
  11912. // Profile periods quantity check
  11913. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11914. {
  11915. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11916. goto end;
  11917. }
  11918. // Check invalid limit
  11919. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0)
  11920. {
  11921. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11922. {
  11923. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11924. {
  11925. 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)))) ||
  11926. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11927. {
  11928. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11929. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11930. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11931. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11932. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11933. goto end;
  11934. }
  11935. }
  11936. }
  11937. else
  11938. {
  11939. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11940. {
  11941. 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) ||
  11942. (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)))
  11943. {
  11944. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11945. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11946. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11947. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11948. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11949. goto end;
  11950. }
  11951. }
  11952. }
  11953. }
  11954. // Profile purpose info check
  11955. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11956. {
  11957. FILE *fp;
  11958. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11959. if(SetProfileReq.ConnectorId != 0)
  11960. {
  11961. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11962. goto end;
  11963. }
  11964. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11965. if (!fp)
  11966. {
  11967. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11968. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11969. }
  11970. else
  11971. {
  11972. char *line = NULL;
  11973. size_t len = 0;
  11974. while(getline(&line, &len, fp) != -1)
  11975. {
  11976. json_object *obj = NULL;
  11977. obj = json_tokener_parse(line);
  11978. if(is_error(obj))
  11979. {
  11980. DEBUG_ERROR("Parse txProfile from file error.\n");
  11981. }
  11982. else
  11983. {
  11984. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  11985. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  11986. {
  11987. profileQuantity += 1;
  11988. }
  11989. else
  11990. replaceableProfileCnt += 1;
  11991. }
  11992. }
  11993. }
  11994. fclose(fp);
  11995. }
  11996. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11997. {
  11998. FILE *fp;
  11999. char filename[128]={0};
  12000. int tmpProfileQuantity;
  12001. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12002. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12003. {
  12004. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12005. goto end;
  12006. }
  12007. if(SetProfileReq.ConnectorId == 0)
  12008. {
  12009. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12010. {
  12011. tmpProfileQuantity = 0;
  12012. memset(filename, 0, ARRAY_SIZE(filename));
  12013. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12014. fp = fopen(filename, "r");
  12015. if (!fp)
  12016. {
  12017. DEBUG_INFO("%s does not create.\n", filename);
  12018. fp = fopen(filename, "w+");
  12019. }
  12020. else
  12021. {
  12022. char *line = NULL;
  12023. size_t len = 0;
  12024. while(getline(&line, &len, fp) != -1)
  12025. {
  12026. json_object *obj = NULL;
  12027. obj = json_tokener_parse(line);
  12028. if(is_error(obj))
  12029. {
  12030. DEBUG_ERROR("Parse txProfile from file error.\n");
  12031. }
  12032. else
  12033. {
  12034. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12035. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12036. {
  12037. tmpProfileQuantity += 1;
  12038. }
  12039. else
  12040. replaceableProfileCnt += 1;
  12041. }
  12042. }
  12043. }
  12044. fclose(fp);
  12045. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12046. }
  12047. }
  12048. else
  12049. {
  12050. memset(filename, 0, ARRAY_SIZE(filename));
  12051. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12052. fp = fopen(filename, "r");
  12053. if (!fp)
  12054. {
  12055. DEBUG_INFO("%s does not create.\n", filename);
  12056. fp = fopen(filename, "w+");
  12057. }
  12058. else
  12059. {
  12060. char *line = NULL;
  12061. size_t len = 0;
  12062. while(getline(&line, &len, fp) != -1)
  12063. {
  12064. json_object *obj = NULL;
  12065. obj = json_tokener_parse(line);
  12066. if(is_error(obj))
  12067. {
  12068. DEBUG_ERROR("Parse txProfile from file error.\n");
  12069. }
  12070. else
  12071. {
  12072. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12073. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12074. {
  12075. profileQuantity += 1;
  12076. }
  12077. else
  12078. replaceableProfileCnt += 1;
  12079. }
  12080. }
  12081. }
  12082. fclose(fp);
  12083. }
  12084. }
  12085. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12086. {
  12087. int isMatchTransactiodId= FALSE;
  12088. FILE *fp;
  12089. char filename[128]={0};
  12090. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12091. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12092. if(SetProfileReq.ConnectorId == 0)
  12093. {
  12094. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12095. goto end;
  12096. }
  12097. int tempIndex = 0;
  12098. //check Transaction active
  12099. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12100. {
  12101. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12102. {
  12103. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12104. }
  12105. else
  12106. {
  12107. tempIndex = SetProfileReq.ConnectorId -1;
  12108. }
  12109. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12110. {
  12111. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12112. {
  12113. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12114. {
  12115. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12116. {
  12117. isMatchTransactiodId = TRUE;
  12118. break;
  12119. }
  12120. }
  12121. }
  12122. }
  12123. }
  12124. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12125. {
  12126. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12127. {
  12128. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12129. }
  12130. else
  12131. {
  12132. tempIndex = SetProfileReq.ConnectorId -1;
  12133. }
  12134. for (int index = 0; index < CCS_QUANTITY; index++)
  12135. {
  12136. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12137. {
  12138. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12139. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12140. {
  12141. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12142. {
  12143. isMatchTransactiodId = TRUE;
  12144. break;
  12145. }
  12146. }
  12147. }
  12148. }
  12149. }
  12150. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12151. {
  12152. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12153. {
  12154. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12155. }
  12156. else
  12157. {
  12158. tempIndex = SetProfileReq.ConnectorId -1;
  12159. }
  12160. for (int index = 0; index < GB_QUANTITY; index++)
  12161. {
  12162. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12163. {
  12164. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12165. {
  12166. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12167. {
  12168. isMatchTransactiodId = TRUE;
  12169. break;
  12170. }
  12171. }
  12172. }
  12173. }
  12174. }
  12175. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12176. {
  12177. tempIndex = SetProfileReq.ConnectorId -1;
  12178. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12179. {
  12180. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12181. {
  12182. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12183. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12184. {
  12185. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12186. {
  12187. isMatchTransactiodId = TRUE;
  12188. break;
  12189. }
  12190. }
  12191. }
  12192. }
  12193. }
  12194. else
  12195. {
  12196. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12197. {
  12198. tempIndex = 2;
  12199. }
  12200. else
  12201. {
  12202. tempIndex = (SetProfileReq.ConnectorId -1);
  12203. }
  12204. for (int index = 0; index < AC_QUANTITY; index++)
  12205. {
  12206. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12207. {
  12208. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12209. {
  12210. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12211. {
  12212. isMatchTransactiodId = TRUE;
  12213. break;
  12214. }
  12215. }
  12216. }
  12217. }
  12218. }
  12219. //check Transaction active
  12220. if(isMatchTransactiodId == FALSE)
  12221. {
  12222. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12223. goto end;
  12224. }
  12225. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12226. {
  12227. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12228. goto end;
  12229. }
  12230. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12231. fp = fopen(filename, "r");
  12232. if (!fp)
  12233. {
  12234. DEBUG_INFO("%s does not create.\n", filename);
  12235. fp = fopen(filename, "w+");
  12236. }
  12237. else
  12238. {
  12239. char *line = NULL;
  12240. size_t len = 0;
  12241. while(getline(&line, &len, fp) != -1)
  12242. {
  12243. json_object *obj = NULL;
  12244. obj = json_tokener_parse(line);
  12245. if(is_error(obj))
  12246. {
  12247. DEBUG_ERROR("Parse txProfile from file error.\n");
  12248. }
  12249. else
  12250. {
  12251. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12252. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12253. {
  12254. profileQuantity += 1;
  12255. }
  12256. else
  12257. replaceableProfileCnt += 1;
  12258. }
  12259. }
  12260. }
  12261. fclose(fp);
  12262. }
  12263. // Check ChargeProfileMaxStackLevel
  12264. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12265. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12266. {
  12267. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12268. goto end;
  12269. }
  12270. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12271. {
  12272. FILE *fp;
  12273. char dataLine[4096]={0};
  12274. char fnametemp[128]={0};
  12275. int tmpProfileQuantity;
  12276. //Check ChargePointMaxProfile.json exit
  12277. profileQuantity = 0;
  12278. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  12279. {
  12280. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  12281. //Check Charging Profile Count
  12282. tmpProfileQuantity = 0;
  12283. while(fscanf(fp, "%s", dataLine) != EOF)
  12284. {
  12285. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12286. {
  12287. profileQuantity += 1;
  12288. tmpProfileQuantity += 1;
  12289. }
  12290. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12291. }
  12292. fclose(fp);
  12293. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12294. }
  12295. //Check TxDefaultProfile_%d.json
  12296. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12297. {
  12298. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12299. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12300. if((access(fnametemp,F_OK))!=-1)
  12301. {
  12302. fp = fopen(fnametemp, "r");
  12303. //Check Charging Profile Count
  12304. tmpProfileQuantity = 0;
  12305. while(fscanf(fp, "%s", dataLine) != EOF)
  12306. {
  12307. //DEBUG_INFO("word=%s\n",word);
  12308. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12309. {
  12310. profileQuantity += 1;
  12311. tmpProfileQuantity += 1;
  12312. }
  12313. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12314. }
  12315. fclose(fp);
  12316. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12317. }
  12318. }
  12319. //Check TxProfile_%d.json
  12320. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12321. {
  12322. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12323. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  12324. if((access(fnametemp,F_OK))!=-1)
  12325. {
  12326. fp = fopen(fnametemp, "r");
  12327. //Check Charging Profile Count
  12328. tmpProfileQuantity = 0;
  12329. while(fscanf(fp, "%s", dataLine) != EOF)
  12330. {
  12331. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12332. {
  12333. profileQuantity += 1;
  12334. tmpProfileQuantity += 1;
  12335. }
  12336. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12337. }
  12338. fclose(fp);
  12339. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12340. }
  12341. }
  12342. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12343. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  12344. // To check total Profile quantity
  12345. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  12346. {
  12347. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12348. {
  12349. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12350. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12351. goto end;
  12352. }
  12353. }
  12354. else
  12355. {
  12356. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12357. {
  12358. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12359. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12360. goto end;
  12361. }
  12362. }
  12363. }
  12364. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12365. //**********************************Write to File********************************************************/
  12366. {
  12367. FILE *infile;
  12368. FILE *outfile;
  12369. char dataLine[4096]={0};
  12370. char filename[128]={0};
  12371. int chkChar=0;
  12372. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12373. {
  12374. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12375. {
  12376. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12377. }
  12378. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12379. {
  12380. if(SetProfileReq.ConnectorId==0)
  12381. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12382. else
  12383. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12384. }
  12385. else
  12386. {
  12387. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12388. }
  12389. infile = fopen (filename, "r");
  12390. outfile = fopen (tempfile, "w");
  12391. chkChar = fgetc(infile);
  12392. rewind(infile);
  12393. if(chkChar == EOF)
  12394. {
  12395. // Profile is empty
  12396. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12397. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12398. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12399. fclose(infile);
  12400. fclose(outfile);
  12401. sprintf(rmFileCmd,"rm -f %s",filename);
  12402. system(rmFileCmd);
  12403. rename(tempfile, filename);
  12404. }
  12405. else
  12406. {
  12407. // Profile is not empty
  12408. int ChargingProfileAdded = FALSE;
  12409. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12410. {
  12411. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12412. json_object *tmpChargingProfile;
  12413. tmpChargingProfile = json_tokener_parse(dataLine);
  12414. if(!is_error(SetChargingProfile))
  12415. {
  12416. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12417. {
  12418. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12419. {
  12420. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12421. }
  12422. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12423. {
  12424. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  12425. }
  12426. }
  12427. }
  12428. json_object_put(tmpChargingProfile);
  12429. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12430. {
  12431. if(ChargingProfileAdded == FALSE)
  12432. {
  12433. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12434. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12435. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12436. ChargingProfileAdded = TRUE;
  12437. }
  12438. }
  12439. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  12440. {
  12441. if(ChargingProfileAdded == FALSE)
  12442. {
  12443. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12444. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12445. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12446. ChargingProfileAdded = TRUE;
  12447. }
  12448. }
  12449. else
  12450. {
  12451. fprintf(outfile,"%s\n",dataLine);
  12452. if(ChargingProfileAdded == FALSE)
  12453. {
  12454. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12455. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12456. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12457. ChargingProfileAdded = TRUE;
  12458. }
  12459. }
  12460. } // end of while loop
  12461. fclose(infile);
  12462. fclose(outfile);
  12463. sprintf(rmFileCmd,"rm -f %s",filename);
  12464. system(rmFileCmd);
  12465. rename(tempfile, filename);
  12466. }
  12467. }
  12468. sleep(1);
  12469. result = TRUE;
  12470. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12471. }
  12472. end:
  12473. json_object_put(SetChargingProfile);
  12474. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12475. {
  12476. if(SetProfileReq.ConnectorId == 0)
  12477. {
  12478. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12479. {
  12480. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  12481. }
  12482. }
  12483. else
  12484. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12485. }
  12486. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12487. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12488. return result;
  12489. }
  12490. int handleTriggerMessageRequest(char *uuid, char *payload)
  12491. {
  12492. mtrace();
  12493. int result = FAIL;
  12494. int connectorIdIsNULL = FALSE;
  12495. int connectorIdInt =0;
  12496. char sstr[40]={0},sstrtemp[100]={ 0 };
  12497. char requestedMessagestr[40]={0};
  12498. char comfirmstr[20]={0};
  12499. int c = 0;
  12500. char *loc;
  12501. DEBUG_INFO("handleTriggerMessageRequest\n");
  12502. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12503. strcpy(sstrtemp, stringtrimspace(payload));
  12504. c = 0;
  12505. loc = strstr(sstrtemp, "requestedMessage");
  12506. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12507. {
  12508. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12509. c++;
  12510. }
  12511. sstr[c] = '\0';
  12512. strcpy(requestedMessagestr, sstr);
  12513. c = 0;
  12514. loc = strstr(sstrtemp, "connectorId");
  12515. if(loc == NULL)
  12516. {
  12517. connectorIdIsNULL = TRUE;
  12518. }
  12519. else
  12520. {
  12521. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12522. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12523. {
  12524. sstr[c] = loc[strlen("connectorId")+2+c];
  12525. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12526. c++;
  12527. }
  12528. sstr[c] = '\0';
  12529. connectorIdInt = atoi(sstr);
  12530. }
  12531. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12532. {
  12533. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12534. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12535. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12536. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12537. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12538. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12539. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12540. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12541. {
  12542. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12543. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12544. return TRUE;
  12545. }
  12546. else
  12547. {
  12548. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12549. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12550. }
  12551. }
  12552. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12553. {
  12554. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12555. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12556. return TRUE;
  12557. }
  12558. //==========================
  12559. // Trigger message
  12560. //==========================
  12561. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12562. {
  12563. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12564. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12565. {
  12566. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12567. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12568. }
  12569. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12570. }
  12571. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12572. {
  12573. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  12574. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12575. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12576. }
  12577. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12578. {
  12579. //sendBootNotificationRequest();
  12580. server_sign = FALSE;
  12581. }
  12582. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12583. {
  12584. refreshStartTimer(&clientTime.Heartbeat);
  12585. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12586. }
  12587. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12588. {
  12589. if(connectorIdIsNULL == FALSE)
  12590. {
  12591. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12592. {
  12593. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12594. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12595. }
  12596. }
  12597. else
  12598. {
  12599. for(int idx=0;idx< gunTotalNumber;idx++)
  12600. {
  12601. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12602. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12603. }
  12604. }
  12605. }
  12606. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12607. {
  12608. if(connectorIdIsNULL == FALSE)
  12609. {
  12610. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12611. {
  12612. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12613. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  12614. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12615. }
  12616. }
  12617. else
  12618. {
  12619. for(int idx=0;idx< gunTotalNumber;idx++)
  12620. {
  12621. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  12622. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12623. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12624. }
  12625. }
  12626. }
  12627. return result;
  12628. }
  12629. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12630. {
  12631. mtrace();
  12632. int result = FAIL;
  12633. int connectorIdInt =0;
  12634. char comfirmstr[20]={0};
  12635. int tempIndex = 0;
  12636. json_object *UnlockConnector;
  12637. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12638. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12639. UnlockConnector = json_tokener_parse(payload);
  12640. if(!is_error(UnlockConnector))
  12641. {
  12642. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12643. {
  12644. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12645. }
  12646. }
  12647. json_object_put(UnlockConnector);
  12648. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12649. if(gunTotalNumber == 0)
  12650. {
  12651. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12652. goto end;
  12653. }
  12654. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12655. {
  12656. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12657. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12658. goto end;
  12659. }
  12660. else
  12661. {
  12662. //check Transaction active
  12663. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12664. {
  12665. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12666. {
  12667. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12668. }
  12669. else
  12670. {
  12671. tempIndex = connectorIdInt -1;
  12672. }
  12673. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12674. {
  12675. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12676. {
  12677. //stop Transaction
  12678. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12679. }
  12680. }
  12681. }
  12682. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12683. {
  12684. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12685. {
  12686. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12687. }
  12688. else
  12689. {
  12690. tempIndex = connectorIdInt -1;
  12691. }
  12692. for (int index = 0; index < CCS_QUANTITY; index++)
  12693. {
  12694. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12695. {
  12696. //stop Transaction
  12697. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12698. }
  12699. }
  12700. }
  12701. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12702. {
  12703. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12704. {
  12705. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12706. }
  12707. else
  12708. {
  12709. tempIndex = connectorIdInt -1;
  12710. }
  12711. for (int index = 0; index < GB_QUANTITY; index++)
  12712. {
  12713. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12714. {
  12715. //stop Transaction
  12716. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12717. }
  12718. }
  12719. }
  12720. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12721. {
  12722. tempIndex = connectorIdInt -1;
  12723. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12724. {
  12725. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12726. {
  12727. //stop Transaction
  12728. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12729. }
  12730. }
  12731. }
  12732. else
  12733. {
  12734. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12735. {
  12736. tempIndex = 2;
  12737. }
  12738. else
  12739. {
  12740. tempIndex = connectorIdInt-1;
  12741. }
  12742. for (int index = 0; index < AC_QUANTITY; index++)
  12743. {
  12744. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12745. {
  12746. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12747. }
  12748. }
  12749. }
  12750. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12751. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  12752. result = TRUE;
  12753. return result;
  12754. }
  12755. end:
  12756. //json_object_put(obj); --- remove temporally
  12757. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12758. return result;
  12759. }
  12760. static char UpdateFirmwarepayloadData[300]={0};
  12761. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12762. {
  12763. mtrace();
  12764. int result = FAIL;
  12765. pthread_t t;
  12766. sendUpdateFirmwareConfirmation(uuid);
  12767. memset(UpdateFirmwarepayloadData, 0, 300);
  12768. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12769. if(!interLock.isUpdateFirmwareGoing)
  12770. {
  12771. interLock.isUpdateFirmwareGoing = 1;
  12772. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12773. sleep(1);
  12774. }
  12775. else
  12776. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12777. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  12778. return result;
  12779. }
  12780. void *UpdateFirmwareProcess(void *data)
  12781. {
  12782. pthread_detach(pthread_self());
  12783. mtrace();
  12784. int retriesInt =0, retryIntervalInt=0;
  12785. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  12786. int port=0;
  12787. char locationstr[512]={0}, retrieveDatestr[36]={0};
  12788. int isSuccess = 0;
  12789. char ftpbuf[512];
  12790. char temp[100];
  12791. char * pch;
  12792. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12793. json_object *UpdateFirmware;
  12794. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12795. if(!is_error(UpdateFirmware))
  12796. {
  12797. // Required data
  12798. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12799. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12800. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12801. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12802. // Optional data
  12803. if(json_object_object_get(UpdateFirmware, "retries"))
  12804. {
  12805. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12806. }
  12807. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12808. {
  12809. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12810. }
  12811. }
  12812. json_object_put(UpdateFirmware);
  12813. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12814. memset(path, 0, ARRAY_SIZE(path));
  12815. // Wait retrieveData
  12816. if(strlen(retrieveDatestr) > 10)
  12817. {
  12818. do
  12819. {
  12820. sleep(1);
  12821. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12822. }
  12823. // Ready to download
  12824. system("rm -f /mnt/*");
  12825. if(strncmp(locationstr,"http", 4) == 0)
  12826. {
  12827. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12828. sprintf(ftppath,"/%s", path);
  12829. DEBUG_INFO("locationstr: %s\n", locationstr);
  12830. DEBUG_INFO("protocol: %s\n",protocol);
  12831. DEBUG_INFO("host: %s\n",host);
  12832. DEBUG_INFO("path: %s\n",path);
  12833. DEBUG_INFO("ftppath: %s\n",ftppath);
  12834. int ftppathlen=strlen(ftppath);
  12835. int i=1;
  12836. char filenametemp[50];
  12837. while(i < ftppathlen)
  12838. {
  12839. int len=ftppathlen-i;
  12840. if(ftppath[len]== 47) // '/' ascll code: 47
  12841. {
  12842. DEBUG_INFO("compare '/' all right\n");
  12843. break;
  12844. }
  12845. i=i+1;
  12846. }
  12847. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12848. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12849. filenametemp[i+1] = 0;
  12850. do
  12851. {
  12852. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12853. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12854. sleep(1);
  12855. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12856. if(!isSuccess)
  12857. {
  12858. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12859. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12860. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12861. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12862. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12863. }
  12864. else
  12865. {
  12866. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12867. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12868. }
  12869. retriesInt--;
  12870. }while((isSuccess == 0)&&(retriesInt >= 0));
  12871. }
  12872. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12873. {
  12874. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12875. memset(temp, 0, ARRAY_SIZE(temp));
  12876. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12877. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12878. int ftppathlen=strlen(ftpbuf);
  12879. int i=1;
  12880. char filenametemp[50];
  12881. while(i < ftppathlen)
  12882. {
  12883. int len=ftppathlen-i;
  12884. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12885. {
  12886. DEBUG_INFO(" compare '/' all right\n");
  12887. break;
  12888. }
  12889. i=i+1;
  12890. }
  12891. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12892. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12893. filenametemp[i+1] = 0;
  12894. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12895. pch=strchr(temp,'@');
  12896. if(pch==NULL)
  12897. {
  12898. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12899. protocol, host, &port, path);
  12900. strcpy(user,"anonymous");
  12901. strcpy(password,"");
  12902. }
  12903. else
  12904. {
  12905. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12906. protocol, user, password, host, &port, path);
  12907. }
  12908. sscanf(host,"%[^/]%s",host1, path1);
  12909. sprintf(ftppath,"%s", path1);
  12910. //DEBUG_INFO("protocol =%s\n",protocol);
  12911. //DEBUG_INFO("user =%s\n",user);
  12912. //DEBUG_INFO("password =%s\n",password);
  12913. //DEBUG_INFO("host1 =%s\n",host1);
  12914. //DEBUG_INFO("port =%d\n",port);
  12915. //DEBUG_INFO("path1 =%s\n",path1);
  12916. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12917. //ftpFile(host, user, password, port, ftppath, fname);
  12918. //download firmware pthred
  12919. if(port == 0)
  12920. {
  12921. port = 21;
  12922. }
  12923. do
  12924. {
  12925. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12926. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12927. sleep(1);
  12928. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12929. if(!isSuccess)
  12930. {
  12931. //BulldogUtil.sleepMs(interval*1000);
  12932. DEBUG_INFO("Update firmware request and download file fail.\n");
  12933. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12934. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12935. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12936. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12937. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12938. }
  12939. else
  12940. {
  12941. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12942. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12943. }
  12944. retriesInt--;
  12945. }while((!isSuccess)&&(retriesInt >= 0));
  12946. }
  12947. else
  12948. {
  12949. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12950. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12951. sleep(1);
  12952. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12953. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12954. }
  12955. // OCPPPH only, must announce CSU upgrade firmware
  12956. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12957. interLock.isUpdateFirmwareGoing = 0;
  12958. pthread_exit(NULL);
  12959. }
  12960. int handleCertificateSignedRequest(char *uuid, char *payload)
  12961. {
  12962. mtrace();
  12963. int result = PASS;
  12964. json_object *CertificateSigned;
  12965. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12966. CertificateSigned = json_tokener_parse(payload);
  12967. if(!is_error(CertificateSigned))
  12968. {
  12969. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  12970. }
  12971. json_object_put(CertificateSigned);
  12972. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  12973. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  12974. fclose(fp);
  12975. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12976. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  12977. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  12978. sendCertificateSignedConfirmation(uuid);
  12979. return result;
  12980. }
  12981. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12982. {
  12983. mtrace();
  12984. int result = PASS;
  12985. json_object *DeleteCertificate;
  12986. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12987. DeleteCertificate = json_tokener_parse(payload);
  12988. if(!is_error(DeleteCertificate))
  12989. {
  12990. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12991. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12992. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12993. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12994. }
  12995. json_object_put(DeleteCertificate);
  12996. /*
  12997. * TODO: Delete certificateSigned process
  12998. */
  12999. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  13000. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  13001. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  13002. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  13003. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  13004. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  13005. sendDeleteCertificateConfirmation(uuid);
  13006. return result;
  13007. }
  13008. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13009. {
  13010. mtrace();
  13011. int result = PASS;
  13012. json_object *ExtendedTriggerMessage;
  13013. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13014. ExtendedTriggerMessage = json_tokener_parse(payload);
  13015. if(!is_error(ExtendedTriggerMessage))
  13016. {
  13017. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13018. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13019. {
  13020. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13021. }
  13022. else
  13023. {
  13024. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  13025. }
  13026. }
  13027. json_object_put(ExtendedTriggerMessage);
  13028. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  13029. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  13030. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13031. {
  13032. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13033. }
  13034. else
  13035. {
  13036. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13037. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13038. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13039. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13040. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13041. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13042. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13043. {
  13044. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13045. }
  13046. else
  13047. {
  13048. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13049. }
  13050. }
  13051. sendExtendedTriggerMessageConfirmation(uuid);
  13052. //==========================
  13053. // Trigger message
  13054. //==========================
  13055. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13056. {
  13057. //sendBootNotificationRequest();
  13058. server_sign = FALSE;
  13059. }
  13060. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13061. {
  13062. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  13063. }
  13064. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13065. {
  13066. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  13067. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13068. {
  13069. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13070. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13071. }
  13072. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13073. }
  13074. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13075. {
  13076. refreshStartTimer(&clientTime.Heartbeat);
  13077. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  13078. }
  13079. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13080. {
  13081. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13082. {
  13083. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13084. }
  13085. else
  13086. {
  13087. for(int idx=0;idx< gunTotalNumber;idx++)
  13088. {
  13089. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13090. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13091. }
  13092. }
  13093. }
  13094. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13095. {
  13096. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  13097. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  13098. {
  13099. system("openssl req -newkey rsa:2048 -out /Storage/OCPP_PH/certCP.csr -nodes -keyout /Storage/OCPP_PH/certCP.key -subj \"/C=TW/ST=Taiwan/L=Taoyuan/O=Phihong Technology/OU=IT/CN=phihong.com\" &");
  13100. }
  13101. }
  13102. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13103. {
  13104. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13105. {
  13106. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13107. }
  13108. else
  13109. {
  13110. for(int idx=0;idx< gunTotalNumber;idx++)
  13111. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13112. }
  13113. }
  13114. return result;
  13115. }
  13116. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13117. {
  13118. mtrace();
  13119. int result = PASS;
  13120. json_object *GetInstalledCertificateIds;
  13121. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13122. GetInstalledCertificateIds = json_tokener_parse(payload);
  13123. if(!is_error(GetInstalledCertificateIds))
  13124. {
  13125. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13126. }
  13127. json_object_put(GetInstalledCertificateIds);
  13128. /*
  13129. * TODO: Return installed certificate process
  13130. */
  13131. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13132. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  13133. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13134. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  13135. sendGetInstalledCertificateIdsConfirmation(uuid);
  13136. return result;
  13137. }
  13138. int handleGetLogRequest(char *uuid, char *payload)
  13139. {
  13140. mtrace();
  13141. int result = PASS;
  13142. json_object *GetLog;
  13143. DEBUG_INFO("handleGetLogRequest...\n");
  13144. GetLog = json_tokener_parse(payload);
  13145. if(!is_error(GetLog))
  13146. {
  13147. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13148. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13149. if(json_object_object_get(GetLog, "retries") != NULL)
  13150. {
  13151. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13152. }
  13153. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13154. {
  13155. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13156. }
  13157. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13158. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13159. {
  13160. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13161. }
  13162. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13163. {
  13164. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13165. }
  13166. }
  13167. json_object_put(GetLog);
  13168. /*
  13169. * TODO: Upload log process
  13170. */
  13171. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  13172. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  13173. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  13174. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  13175. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  13176. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  13177. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  13178. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  13179. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  13180. sendGetLogConfirmation(uuid);
  13181. return result;
  13182. }
  13183. int handleInstallCertificateRequest(char *uuid, char *payload)
  13184. {
  13185. mtrace();
  13186. int result = PASS;
  13187. json_object *InstallCertificate;
  13188. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13189. InstallCertificate = json_tokener_parse(payload);
  13190. if(!is_error(InstallCertificate))
  13191. {
  13192. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13193. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13194. /*
  13195. * TODO: Install certificate process
  13196. */
  13197. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  13198. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  13199. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  13200. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  13201. sendInstallCertificateConfirmation(uuid);
  13202. }
  13203. json_object_put(InstallCertificate);
  13204. return result;
  13205. }
  13206. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13207. {
  13208. mtrace();
  13209. int result = PASS;
  13210. json_object *SignedUpdateFirmware;
  13211. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13212. SignedUpdateFirmware = json_tokener_parse(payload);
  13213. if(!is_error(SignedUpdateFirmware))
  13214. {
  13215. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13216. {
  13217. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13218. }
  13219. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13220. {
  13221. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13222. }
  13223. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13224. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13225. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13226. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13227. {
  13228. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13229. }
  13230. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13231. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13232. }
  13233. json_object_put(SignedUpdateFirmware);
  13234. /*
  13235. * TODO: Upgrade firmware process
  13236. */
  13237. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13238. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  13239. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  13240. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  13241. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  13242. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  13243. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  13244. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  13245. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  13246. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  13247. sendInstallCertificateConfirmation(uuid);
  13248. return result;
  13249. }
  13250. int handleUnknownRequest(char *uuid, char *payload)
  13251. {
  13252. mtrace();
  13253. int result = PASS;
  13254. DEBUG_INFO("handleUnknownRequest...\n");
  13255. sendUnknownConfirmation(uuid);
  13256. result = PASS;
  13257. return result;
  13258. }
  13259. //==========================================
  13260. // Handle server response routine
  13261. //==========================================
  13262. void handleAuthorizeResponse(char *payload, int gun_index)
  13263. {
  13264. mtrace();
  13265. char expiryDatestr[36]={0};
  13266. char parentIdTagstr[21]={0};
  13267. char statusstr[20]={0};
  13268. int expiryDateISNULL=FALSE;
  13269. int parentIdTagISNULL=FALSE;
  13270. DEBUG_INFO("handleAuthorizeResponse...\n");
  13271. json_object *Authorize;
  13272. Authorize = json_tokener_parse(payload);
  13273. if(!is_error(Authorize))
  13274. {
  13275. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13276. {
  13277. // Required data
  13278. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13279. // Optional data
  13280. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13281. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13282. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13283. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13284. }
  13285. }
  13286. json_object_put(Authorize);
  13287. if(expiryDateISNULL == FALSE)
  13288. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13289. if(parentIdTagISNULL == FALSE)
  13290. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13291. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  13292. //Update idTag information to authorization cache if supproted
  13293. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13294. {
  13295. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13296. }
  13297. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  13298. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13299. authorizeRetryTimes = 0;
  13300. }
  13301. void handleBootNotificationResponse(char *payload, int gun_index)
  13302. {
  13303. mtrace();
  13304. char statusStr[12]={0};
  13305. char currentTimeStr[30]={0};
  13306. int intervalInt = 0;
  13307. DEBUG_INFO("handleBootNotificationResponse...\n");
  13308. json_object *BootNotification;
  13309. BootNotification = json_tokener_parse(payload);
  13310. if(!is_error(BootNotification))
  13311. {
  13312. // Required data
  13313. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13314. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13315. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13316. }
  13317. json_object_put(BootNotification);
  13318. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13319. BootNotificationInterval = intervalInt;
  13320. //write back to ShmOCPP16DataPH->BootNotification
  13321. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  13322. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13323. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  13324. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13325. {
  13326. BootNotificationInterval = 0;
  13327. if((intervalInt == 0) || (intervalInt >= 10))
  13328. {
  13329. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13330. HeartBeatWaitTime = intervalInt;
  13331. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13332. }
  13333. server_sign = TRUE;
  13334. server_pending =FALSE;
  13335. }
  13336. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13337. {
  13338. server_pending = TRUE;
  13339. }
  13340. //syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  13341. srand(time(NULL));
  13342. refreshStartTimer(&clientTime.Heartbeat);
  13343. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13344. SetOcppConnStatus(TRUE);
  13345. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  13346. }
  13347. void handleDataTransferResponse(char *payload, int gun_index)
  13348. {
  13349. json_object *DataTransfer = json_tokener_parse(payload);
  13350. if(!is_error(DataTransfer))
  13351. {
  13352. // Required data
  13353. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13354. // Optional data
  13355. if(json_object_object_get(DataTransfer, "data") != NULL)
  13356. {
  13357. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13358. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13359. if(!is_error(Data))
  13360. {
  13361. if(json_object_object_get(Data, "msgId") != NULL)
  13362. {
  13363. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13364. {
  13365. 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")));
  13366. }
  13367. }
  13368. }
  13369. json_object_put(Data);
  13370. }
  13371. }
  13372. json_object_put(DataTransfer);
  13373. }
  13374. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13375. {
  13376. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13377. //struct json_object *obj;
  13378. // obj = json_tokener_parse(payload);
  13379. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13380. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13381. //No fields are defined.
  13382. }
  13383. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13384. {
  13385. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13386. //struct json_object *obj;
  13387. // obj = json_tokener_parse(payload);
  13388. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13389. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13390. //No fields are defined.
  13391. }
  13392. void handleHeartbeatResponse(char *payload, int gun_index)
  13393. {
  13394. mtrace();
  13395. DEBUG_INFO("handleHeartbeatResponse...\n");
  13396. json_object *Heartbeat;
  13397. Heartbeat = json_tokener_parse(payload);
  13398. if(!is_error(Heartbeat))
  13399. {
  13400. // Required data
  13401. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13402. }
  13403. json_object_put(Heartbeat);
  13404. if(FirstHeartBeat == 0)
  13405. {
  13406. FirstHeartBeat = 1;
  13407. DEBUG_INFO("FirstHeartBeat \n");
  13408. }
  13409. HeartBeatWithNOResponse = 0;
  13410. refreshStartTimer(&clientTime.Heartbeat);
  13411. //syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  13412. }
  13413. void handleMeterValuesResponse(char *payload, int gun_index)
  13414. {
  13415. mtrace();
  13416. DEBUG_INFO("handleMeterValuesResponse...\n");
  13417. isQueueSendable = 1;
  13418. }
  13419. void handleStartTransactionResponse(char *payload, int gun_index)
  13420. {
  13421. mtrace();
  13422. //int transactionIdInt = 0;
  13423. FILE *outfile;
  13424. char data[100]={0};
  13425. DEBUG_INFO("handleStartTransactionResponse...\n");
  13426. json_object *StartTransaction;
  13427. StartTransaction = json_tokener_parse(payload);
  13428. if(!is_error(StartTransaction))
  13429. {
  13430. // Required data
  13431. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13432. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13433. // Optional data
  13434. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13435. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13436. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13437. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13438. }
  13439. json_object_put(StartTransaction);
  13440. isQueueSendable = 1;
  13441. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13442. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13443. //-----------Start : write to the Queue TransactionId file -----------------//
  13444. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  13445. {}
  13446. else
  13447. {
  13448. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  13449. if(log == NULL)
  13450. {
  13451. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13452. return ;
  13453. }
  13454. else
  13455. {
  13456. fclose(log);
  13457. }
  13458. }
  13459. // open file for writing
  13460. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13461. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  13462. {
  13463. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  13464. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13465. fputs(data, outfile);
  13466. fclose (outfile);
  13467. }
  13468. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13469. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13470. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13471. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  13472. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13473. }
  13474. void handleStatusNotificationResponse(char *payload, int gun_index)
  13475. {
  13476. mtrace();
  13477. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13478. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13479. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13480. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13481. }
  13482. void handleStopTransactionnResponse(char *payload, int gun_index)
  13483. {
  13484. mtrace();
  13485. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13486. json_object *StopTransaction;
  13487. StopTransaction = json_tokener_parse(payload);
  13488. if(!is_error(StopTransaction))
  13489. {
  13490. // Optional data
  13491. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13492. {
  13493. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13494. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13495. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13496. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13497. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13498. }
  13499. }
  13500. json_object_put(StopTransaction);
  13501. isQueueSendable = 1;
  13502. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13503. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13504. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13505. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13506. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13507. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13508. }
  13509. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13510. {
  13511. mtrace();
  13512. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13513. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  13514. }
  13515. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13516. {
  13517. mtrace();
  13518. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13519. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  13520. }
  13521. void handleSignCertificateResponse(char *payload, int gun_index)
  13522. {
  13523. mtrace();
  13524. DEBUG_INFO("handleSignCertificateResponse...\n");
  13525. json_object *SignCertificate;
  13526. SignCertificate = json_tokener_parse(payload);
  13527. if(!is_error(SignCertificate))
  13528. {
  13529. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13530. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  13531. }
  13532. json_object_put(SignCertificate);
  13533. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  13534. }
  13535. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13536. {
  13537. mtrace();
  13538. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13539. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13540. }
  13541. //==========================================
  13542. // Handle Error routine
  13543. //==========================================
  13544. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13545. {
  13546. mtrace();
  13547. #ifdef SystemLogMessage
  13548. DEBUG_INFO("errorCode: %s\n", errorCode);
  13549. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13550. DEBUG_INFO("errorDetails: %s\n", payload);
  13551. #endif
  13552. }
  13553. //===============================================
  13554. // Common routine
  13555. //===============================================
  13556. int initialConfigurationTable(void)
  13557. {
  13558. //clock_t start_t, end_t, total_t;
  13559. FILE *fp;
  13560. FILE *outfile;
  13561. char str[512]={0};
  13562. char sstr[256]={0};
  13563. int c = 0;
  13564. char *loc;
  13565. int confVersion = 14;
  13566. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13567. //start_t = clock();
  13568. //printf("Starting of the program, start_t = %ld\n", start_t);
  13569. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13570. // Check configuration file size is correct
  13571. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  13572. {
  13573. struct stat st;
  13574. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  13575. if(st.st_size < 3100)
  13576. {
  13577. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  13578. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13579. }
  13580. }
  13581. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  13582. {
  13583. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13584. if(outfile == NULL)
  13585. {
  13586. DEBUG_INFO("Error opening file\n");
  13587. return FALSE;
  13588. }
  13589. /*Core Profile*/
  13590. //AllowOfflineTxForUnknownId
  13591. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13592. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13593. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13594. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13595. //AuthorizationCacheEnabled
  13596. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13597. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13598. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13599. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13600. //AuthorizeRemoteTxRequests
  13601. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13602. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13603. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13604. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13605. //BlinkRepeat
  13606. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13607. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13608. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13609. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13610. //ClockAlignedDataInterval
  13611. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13612. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13613. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13614. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13615. //ConnectionTimeOut
  13616. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13617. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13618. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13619. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13620. //GetConfigurationMaxKeys
  13621. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13622. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13623. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13624. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13625. // HeartbeatInterval
  13626. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13627. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13628. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13629. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13630. // LightIntensity
  13631. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13632. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13633. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13634. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13635. // LocalAuthorizeOffline
  13636. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13637. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13638. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13639. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13640. // LocalPreAuthorize
  13641. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13642. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13643. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13644. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13645. // MaxEnergyOnInvalidId
  13646. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13647. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13648. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13649. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13650. // MeterValuesAlignedData
  13651. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13652. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13653. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13654. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC,Current.Offered,Power.Offered" );
  13655. else
  13656. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13657. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13658. // MeterValuesAlignedDataMaxLength
  13659. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13660. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13661. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13662. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13663. else
  13664. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13665. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13666. // MeterValuesSampledData
  13667. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13668. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13669. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13670. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC,Current.Offered,Power.Offered" );
  13671. else
  13672. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13673. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13674. // MeterValuesSampledDataMaxLength
  13675. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13676. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13677. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13678. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13679. else
  13680. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13681. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13682. // MeterValueSampleInterval
  13683. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13684. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13685. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13686. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13687. // MinimumStatusDuration
  13688. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13689. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13690. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13691. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13692. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13693. // NumberOfConnectors
  13694. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13695. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13696. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13697. {
  13698. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13699. }
  13700. else
  13701. {
  13702. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13703. }
  13704. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13705. // ResetRetries
  13706. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13707. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13708. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13709. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13710. // ConnectorPhaseRotation
  13711. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13712. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13713. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13714. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13715. // ConnectorPhaseRotationMaxLength
  13716. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13717. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13718. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13719. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13720. // StopTransactionOnEVSideDisconnect
  13721. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13722. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13723. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13724. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13725. // StopTransactionOnInvalidId
  13726. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13727. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13728. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13729. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13730. // StopTxnAlignedData
  13731. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13732. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13733. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13734. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13735. // StopTxnAlignedDataMaxLength
  13736. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13737. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13738. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13739. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13740. // StopTxnSampledData
  13741. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13742. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13743. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13744. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13745. else
  13746. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13747. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13748. // StopTxnSampledDataMaxLength
  13749. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13750. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13751. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13752. {
  13753. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13754. }
  13755. else
  13756. {
  13757. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13758. }
  13759. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13760. // SupportedFeatureProfiles
  13761. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13762. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13763. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13764. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13765. // SupportedFeatureProfilesMaxLength
  13766. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13767. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13768. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13769. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13770. // TransactionMessageAttempts
  13771. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13772. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13773. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13774. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13775. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13776. // TransactionMessageRetryInterval
  13777. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13778. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13779. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13780. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13781. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13782. // UnlockConnectorOnEVSideDisconnect
  13783. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13784. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13785. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13786. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13787. // WebSocketPingInterval
  13788. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13789. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13790. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13791. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13792. // QueueOffLineMeterValues
  13793. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13794. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13795. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13796. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13797. // AuthorizationKey
  13798. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13799. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13800. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword );
  13801. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13802. // SecurityProfile
  13803. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13804. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13805. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13806. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13807. // DefaultPrice
  13808. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13809. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13810. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13811. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13812. // CustomDisplayCostAndPrice
  13813. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13814. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13815. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13816. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13817. // CustomIdleFeeAfterStop
  13818. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13819. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13820. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13821. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13822. // SystemUptimeSec
  13823. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13824. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13825. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13826. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13827. // FreeVend
  13828. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13829. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13830. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13831. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13832. // FreeVendIdtag
  13833. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  13834. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  13835. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  13836. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  13837. // OcppServer
  13838. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13839. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13840. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13841. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13842. // MaintainServer
  13843. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13844. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13845. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13846. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13847. // StatusNotificationPeriodically
  13848. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  13849. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  13850. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  13851. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  13852. // StatusNotificationInterval
  13853. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  13854. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  13855. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  13856. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  13857. // isEnableLocalPowerSharing
  13858. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  13859. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  13860. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  13861. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  13862. // PowerSharingServerIP
  13863. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  13864. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  13865. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  13866. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  13867. // EVCCID_PREFIX
  13868. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  13869. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  13870. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  13871. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  13872. // Configuration Version
  13873. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13874. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13875. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13876. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13877. //* Local Auth List Management Profile*/
  13878. #if 0
  13879. //For OCTT Test Case
  13880. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13881. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13882. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13883. #endif
  13884. #if 1
  13885. //LocalAuthListEnabled
  13886. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13887. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13888. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13890. #endif
  13891. //LocalAuthListMaxLength
  13892. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13893. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13894. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13895. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13896. //SendLocalListMaxLength
  13897. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13898. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13899. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  13900. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13901. //ReserveConnectorZeroSupported
  13902. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13903. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13904. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13905. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13906. //* Smart Charging Profile */
  13907. //ChargeProfileMaxStackLevel
  13908. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13909. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13910. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13911. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13912. // ChargingScheduleAllowedChargingRateUnit
  13913. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13914. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13915. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13916. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13917. // ChargingScheduleMaxPeriods
  13918. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13919. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13920. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13921. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13922. // ConnectorSwitch3to1PhaseSupported
  13923. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13924. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13925. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13926. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13927. // MaxChargingProfilesInstalled
  13928. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13929. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13930. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13931. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13932. fclose(outfile);
  13933. }
  13934. else
  13935. {
  13936. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  13937. char keystr[60]={0};
  13938. char readonlystr[10]={0};
  13939. char valuestr[256]={0};
  13940. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  13941. if(fp == NULL) {
  13942. DEBUG_INFO("Error opening file");
  13943. return FALSE;
  13944. }
  13945. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13946. {
  13947. //DEBUG_INFO("Get Configuration \n");
  13948. if(strlen(str) > 0)
  13949. {
  13950. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13951. //*************************key*********************************/
  13952. if(strstr(str, "key") != NULL)
  13953. {
  13954. loc = strstr(str, "key");
  13955. c = 0;
  13956. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13957. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13958. {
  13959. sstr[c] = loc[strlen("key")+3+c];
  13960. c++;
  13961. }
  13962. sstr[c] = '\0';
  13963. strcpy(keystr,sstr);
  13964. }
  13965. //*************************readonly*********************************/
  13966. if(strstr(str, "readonly") != NULL)
  13967. {
  13968. loc = strstr(str, "readonly");
  13969. c = 0;
  13970. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13971. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13972. {
  13973. sstr[c] = loc[strlen("readonly")+2+c];
  13974. c++;
  13975. }
  13976. sstr[c] = '\0';
  13977. strcpy(readonlystr,sstr);
  13978. }
  13979. //*************************value*********************************/
  13980. if(strstr(str, "value") != NULL)
  13981. {
  13982. loc = strstr(str, "value");
  13983. c = 0;
  13984. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13985. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13986. {
  13987. sstr[c] = loc[strlen("value")+3+c];
  13988. c++;
  13989. }
  13990. sstr[c] = '\0';
  13991. strcpy(valuestr,sstr);
  13992. }
  13993. // DEBUG_INFO("keystr=%s\n",keystr);
  13994. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13995. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13996. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13997. {
  13998. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13999. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14000. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14001. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14002. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14003. }
  14004. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14005. {
  14006. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14007. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14008. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14009. }
  14010. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14011. {
  14012. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14013. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14014. }
  14015. if(strcmp(keystr, "BlinkRepeat") == 0)
  14016. {
  14017. //Charger.BlinkRepeat = Integer.parseInt(value);
  14018. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14019. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14020. }
  14021. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14022. {
  14023. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14024. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14025. }
  14026. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14027. {
  14028. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14029. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14030. }
  14031. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14032. {
  14033. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14034. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14035. }
  14036. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14037. {
  14038. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14039. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14040. HeartBeatWaitTime = atoi(valuestr);
  14041. }
  14042. if(strcmp(keystr, "LightIntensity") == 0)
  14043. {
  14044. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14045. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14046. }
  14047. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14048. {
  14049. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14050. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14051. }
  14052. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14053. {
  14054. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14055. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14056. }
  14057. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14058. {
  14059. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14060. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14061. }
  14062. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14063. {
  14064. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14065. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14066. }
  14067. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14068. {
  14069. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14070. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14071. }
  14072. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14073. {
  14074. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14075. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14076. }
  14077. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14078. {
  14079. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14080. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14081. }
  14082. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14083. {
  14084. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14085. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14086. }
  14087. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14088. {
  14089. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14090. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14091. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14092. }
  14093. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14094. {
  14095. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14096. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14097. }
  14098. if(strcmp(keystr, "ResetRetries") == 0)
  14099. {
  14100. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14101. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14102. }
  14103. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14104. {
  14105. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14106. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14107. }
  14108. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14109. {
  14110. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14111. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14112. }
  14113. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14114. {
  14115. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14116. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14117. }
  14118. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14119. {
  14120. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14121. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14122. }
  14123. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14124. {
  14125. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14126. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14127. }
  14128. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14129. {
  14130. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14131. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14132. }
  14133. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14134. {
  14135. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14136. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14137. }
  14138. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14139. {
  14140. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14141. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14142. }
  14143. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14144. {
  14145. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14146. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14147. }
  14148. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14149. {
  14150. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14151. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14152. }
  14153. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14154. {
  14155. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14156. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14157. TransactionMessageAttemptsValue = atoi(valuestr);
  14158. }
  14159. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14160. {
  14161. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14162. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14163. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14164. }
  14165. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14166. {
  14167. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14168. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14169. }
  14170. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14171. {
  14172. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14173. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14174. }
  14175. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14176. {
  14177. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14178. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14179. }
  14180. if(strcmp(keystr, "AuthorizationKey") == 0)
  14181. {
  14182. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14183. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14184. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword);
  14185. }
  14186. if(strcmp(keystr, "SecurityProfile") == 0)
  14187. {
  14188. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14189. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  14190. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  14191. }
  14192. if(strcmp(keystr, "DefaultPrice") == 0)
  14193. {
  14194. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14195. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14196. }
  14197. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14198. {
  14199. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14200. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14201. }
  14202. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14203. {
  14204. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14205. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14206. }
  14207. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14208. {
  14209. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14210. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  14211. }
  14212. if(strcmp(keystr, "FreeVend") == 0)
  14213. {
  14214. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14215. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14216. }
  14217. if(strcmp(keystr, "FreeVendIdtag") == 0)
  14218. {
  14219. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14220. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  14221. }
  14222. if(strcmp(keystr, "OcppServer") == 0)
  14223. {
  14224. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14225. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14226. }
  14227. if(strcmp(keystr, "MaintainServer") == 0)
  14228. {
  14229. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14230. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14231. }
  14232. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14233. {
  14234. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14235. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14236. }
  14237. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14238. {
  14239. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14240. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14241. }
  14242. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  14243. {
  14244. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14245. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  14246. }
  14247. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  14248. {
  14249. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14250. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  14251. }
  14252. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  14253. {
  14254. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14255. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  14256. }
  14257. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14258. {
  14259. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14260. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14261. }
  14262. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14263. {
  14264. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14265. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14266. }
  14267. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14268. {
  14269. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14270. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14271. }
  14272. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14273. {
  14274. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14275. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14276. }
  14277. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14278. {
  14279. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14280. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14281. }
  14282. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14283. {
  14284. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14285. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14286. }
  14287. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14288. {
  14289. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14290. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14291. }
  14292. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14293. {
  14294. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14295. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14296. }
  14297. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14298. {
  14299. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14300. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14301. }
  14302. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14303. {
  14304. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14305. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14306. }
  14307. }
  14308. }
  14309. fclose(fp);
  14310. }
  14311. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14312. {
  14313. return PASS;
  14314. }
  14315. else
  14316. {
  14317. return FAIL;
  14318. }
  14319. }
  14320. void StoreConfigurationTable(void)
  14321. {
  14322. FILE *outfile;
  14323. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  14324. if(outfile == NULL)
  14325. {
  14326. DEBUG_INFO("Error opening file");
  14327. return ;
  14328. }
  14329. /*Core Profile*/
  14330. //AllowOfflineTxForUnknownId
  14331. /*
  14332. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14333. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14334. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14335. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14336. */
  14337. //DEBUG_INFO("data=%s\n",data);
  14338. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14339. //AuthorizationCacheEnabled
  14340. /*
  14341. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14342. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14343. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14344. */
  14345. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14346. //AuthorizeRemoteTxRequests
  14347. /*
  14348. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14349. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14350. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14351. */
  14352. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14353. //BlinkRepeat
  14354. /*
  14355. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14356. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14357. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14358. */
  14359. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14360. //ClockAlignedDataInterval
  14361. /*
  14362. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14363. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14364. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14365. */
  14366. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14367. //ConnectionTimeOut
  14368. /*
  14369. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14370. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14371. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14372. */
  14373. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14374. //GetConfigurationMaxKeys
  14375. /*
  14376. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14377. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14378. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14379. */
  14380. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14381. // HeartbeatInterval
  14382. /*
  14383. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14384. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14385. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14386. */
  14387. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14388. // LightIntensity
  14389. /*
  14390. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14391. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14392. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14393. */
  14394. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14395. // LocalAuthorizeOffline
  14396. /*
  14397. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14398. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14399. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14400. */
  14401. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14402. // LocalPreAuthorize
  14403. /*
  14404. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14405. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14406. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14407. */
  14408. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14409. // MaxEnergyOnInvalidId
  14410. /*
  14411. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14412. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14413. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14414. */
  14415. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14416. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14417. // MeterValuesAlignedData
  14418. /*
  14419. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14420. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14421. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14422. */
  14423. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14424. // MeterValuesAlignedDataMaxLength
  14425. /*
  14426. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14427. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14428. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14429. */
  14430. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14431. // MeterValuesSampledData
  14432. /*
  14433. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14434. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14435. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14436. */
  14437. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14438. // MeterValuesSampledDataMaxLength
  14439. /*
  14440. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14441. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14442. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14443. */
  14444. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14445. // MeterValueSampleInterval
  14446. /*
  14447. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14448. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14449. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14450. */
  14451. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14452. // MinimumStatusDuration
  14453. /*
  14454. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14455. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14456. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14457. */
  14458. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14459. // NumberOfConnectors
  14460. /*
  14461. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14462. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14463. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14464. {
  14465. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14466. }
  14467. else
  14468. {
  14469. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14470. }
  14471. */
  14472. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14473. // ResetRetries
  14474. /*
  14475. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14476. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14477. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14478. */
  14479. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14480. // ConnectorPhaseRotation
  14481. /*
  14482. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14483. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14484. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14485. */
  14486. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14487. // ConnectorPhaseRotationMaxLength
  14488. /*
  14489. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14490. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14491. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14492. */
  14493. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14494. // StopTransactionOnEVSideDisconnect
  14495. /*
  14496. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14497. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14498. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14499. */
  14500. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14501. // StopTransactionOnInvalidId
  14502. /*
  14503. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14504. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14505. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14506. */
  14507. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14508. // StopTxnAlignedData
  14509. /*
  14510. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14511. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14512. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14513. */
  14514. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14515. // StopTxnAlignedDataMaxLength
  14516. /*
  14517. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14518. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14519. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14520. */
  14521. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14522. // StopTxnSampledData
  14523. /*
  14524. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14525. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14526. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14527. */
  14528. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14529. // StopTxnSampledDataMaxLength
  14530. /*
  14531. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14532. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14533. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14534. */
  14535. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14536. // SupportedFeatureProfiles
  14537. /*
  14538. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14539. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14540. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14541. */
  14542. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14543. // SupportedFeatureProfilesMaxLength
  14544. /*
  14545. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14546. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14547. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14548. */
  14549. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14550. // TransactionMessageAttempts
  14551. /*
  14552. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14553. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14554. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14555. */
  14556. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14557. // TransactionMessageRetryInterval
  14558. /*
  14559. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14560. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14561. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14562. */
  14563. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14564. // UnlockConnectorOnEVSideDisconnect
  14565. /*
  14566. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14567. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14568. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14569. */
  14570. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14571. // WebSocketPingInterval
  14572. /*
  14573. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14574. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14575. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14576. */
  14577. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14578. // QueueOffLineMeterValues
  14579. /*
  14580. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14581. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14582. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14583. */
  14584. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14585. // AuthorizationKey
  14586. /*
  14587. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14588. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14589. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14590. */
  14591. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14592. // SecurityProfile
  14593. /*
  14594. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14595. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14596. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14597. */
  14598. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14599. // DefaultPrice
  14600. /*
  14601. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14602. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14603. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14604. */
  14605. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14606. // CustomDisplayCostAndPrice
  14607. /*
  14608. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14609. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14610. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14611. */
  14612. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14613. // CustomIdleFeeAfterStop
  14614. /*
  14615. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14616. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14617. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14618. */
  14619. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14620. // SystemUptimeSec
  14621. /*
  14622. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14623. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14624. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14625. */
  14626. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14627. // FreeVend
  14628. /*
  14629. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14630. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14631. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14632. */
  14633. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14634. // FreeVendIdtag
  14635. /*
  14636. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14637. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14638. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14639. */
  14640. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14641. // OcppServer
  14642. /*
  14643. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14644. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14645. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14646. */
  14647. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14648. // MaintainServer
  14649. /*
  14650. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14651. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14652. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14653. */
  14654. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14655. // StatusNotificationPeriodically
  14656. /*
  14657. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14658. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14659. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14660. */
  14661. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14662. // StatusNotificationInterval
  14663. /*
  14664. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14665. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14666. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14667. */
  14668. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14669. // isEnableLocalPowerSharing
  14670. /*
  14671. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  14672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  14673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  14674. */
  14675. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  14676. // PowerSharingServerIP
  14677. /*
  14678. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  14679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  14680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  14681. */
  14682. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  14683. // EVCCID_PREFIX
  14684. /*
  14685. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  14686. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  14687. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  14688. */
  14689. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  14690. // ConfigurationVersion
  14691. /*
  14692. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14693. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14694. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14695. */
  14696. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14697. //* Local Auth List Management Profile*/
  14698. //LocalAuthListEnabled
  14699. /*
  14700. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14701. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14702. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14703. */
  14704. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14705. //LocalAuthListMaxLength
  14706. /*
  14707. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14708. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14709. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14710. */
  14711. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14712. //SendLocalListMaxLength
  14713. /*
  14714. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14715. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14716. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14717. */
  14718. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14719. //ReserveConnectorZeroSupported
  14720. /*
  14721. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14722. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14723. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14724. */
  14725. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14726. //* Smart Charging Profile */
  14727. //ChargeProfileMaxStackLevel
  14728. /*
  14729. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14730. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14731. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14732. */
  14733. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14734. // ChargingScheduleAllowedChargingRateUnit
  14735. /*
  14736. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14737. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14738. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14739. */
  14740. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14741. // ChargingScheduleMaxPeriods
  14742. /*
  14743. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14744. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14745. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14746. */
  14747. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14748. // ConnectorSwitch3to1PhaseSupported
  14749. /*
  14750. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14751. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14752. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14753. */
  14754. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14755. // MaxChargingProfilesInstalled
  14756. /*
  14757. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14758. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14759. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14760. */
  14761. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14762. fclose(outfile);
  14763. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14764. }
  14765. void getKeyValue(char *keyReq)
  14766. {
  14767. int isEmpty = FALSE;
  14768. int isKnowKey = FALSE;
  14769. DEBUG_INFO("keyReq = %s\n", keyReq);
  14770. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14771. isEmpty = TRUE;
  14772. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14773. {
  14774. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14775. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14776. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14777. {
  14778. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14779. }
  14780. else
  14781. {
  14782. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14783. }
  14784. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14785. isKnowKey = TRUE;
  14786. }
  14787. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14788. {
  14789. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14790. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14791. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14792. {
  14793. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14794. }
  14795. else
  14796. {
  14797. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14798. }
  14799. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14800. isKnowKey = TRUE;
  14801. }
  14802. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14803. {
  14804. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14805. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14806. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14807. {
  14808. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14809. }
  14810. else
  14811. {
  14812. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14813. }
  14814. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14815. isKnowKey = TRUE;
  14816. }
  14817. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14818. {
  14819. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14820. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14821. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14822. {
  14823. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14824. }
  14825. else
  14826. {
  14827. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14828. }
  14829. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14830. isKnowKey = TRUE;
  14831. }
  14832. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14833. {
  14834. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14835. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14836. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14837. {
  14838. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14839. }
  14840. else
  14841. {
  14842. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14843. }
  14844. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14845. isKnowKey = TRUE;
  14846. }
  14847. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14848. {
  14849. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14850. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14851. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14852. {
  14853. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14854. }
  14855. else
  14856. {
  14857. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14858. }
  14859. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14860. isKnowKey = TRUE;
  14861. }
  14862. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14863. {
  14864. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14865. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14866. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14867. {
  14868. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14869. }
  14870. else
  14871. {
  14872. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14873. }
  14874. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14875. isKnowKey = TRUE;
  14876. }
  14877. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14878. {
  14879. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14880. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14881. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14882. {
  14883. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14884. }
  14885. else
  14886. {
  14887. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14888. }
  14889. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14890. isKnowKey = TRUE;
  14891. }
  14892. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14893. {
  14894. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14895. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14896. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14897. {
  14898. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14899. }
  14900. else
  14901. {
  14902. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14903. }
  14904. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14905. isKnowKey = TRUE;
  14906. }
  14907. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14908. {
  14909. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14910. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14911. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14912. {
  14913. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14914. }
  14915. else
  14916. {
  14917. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14918. }
  14919. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14920. isKnowKey = TRUE;
  14921. }
  14922. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14923. {
  14924. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14925. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14926. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14927. {
  14928. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14929. }
  14930. else
  14931. {
  14932. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14933. }
  14934. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14935. isKnowKey = TRUE;
  14936. }
  14937. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14938. {
  14939. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14940. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14941. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14942. {
  14943. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14944. }
  14945. else
  14946. {
  14947. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14948. }
  14949. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14950. isKnowKey = TRUE;
  14951. }
  14952. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14953. {
  14954. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14955. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14956. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14957. {
  14958. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14959. }
  14960. else
  14961. {
  14962. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14963. }
  14964. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14965. isKnowKey = TRUE;
  14966. }
  14967. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14968. {
  14969. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14970. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14971. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14972. {
  14973. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14974. }
  14975. else
  14976. {
  14977. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14978. }
  14979. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14980. isKnowKey = TRUE;
  14981. }
  14982. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14983. {
  14984. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14985. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14986. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14987. {
  14988. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14989. }
  14990. else
  14991. {
  14992. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14993. }
  14994. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14995. isKnowKey = TRUE;
  14996. }
  14997. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14998. {
  14999. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  15000. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  15001. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15002. {
  15003. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15004. }
  15005. else
  15006. {
  15007. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15008. }
  15009. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  15010. isKnowKey = TRUE;
  15011. }
  15012. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  15013. {
  15014. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  15015. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  15016. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15017. {
  15018. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  15019. }
  15020. else
  15021. {
  15022. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  15023. }
  15024. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  15025. isKnowKey = TRUE;
  15026. }
  15027. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  15028. {
  15029. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  15030. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  15031. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15032. {
  15033. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  15034. }
  15035. else
  15036. {
  15037. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  15038. }
  15039. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  15040. isKnowKey = TRUE;
  15041. }
  15042. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  15043. {
  15044. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  15045. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  15046. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15047. {
  15048. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  15049. }
  15050. else
  15051. {
  15052. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15053. }
  15054. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15055. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15056. isKnowKey = TRUE;
  15057. }
  15058. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15059. {
  15060. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15061. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15062. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15063. {
  15064. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15065. }
  15066. else
  15067. {
  15068. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15069. }
  15070. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15071. isKnowKey = TRUE;
  15072. }
  15073. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15074. {
  15075. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15076. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15077. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15078. {
  15079. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15080. }
  15081. else
  15082. {
  15083. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15084. }
  15085. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15086. isKnowKey = TRUE;
  15087. }
  15088. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15089. {
  15090. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15091. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15092. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15093. {
  15094. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15095. }
  15096. else
  15097. {
  15098. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15099. }
  15100. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15101. isKnowKey = TRUE;
  15102. }
  15103. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15104. {
  15105. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15106. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15107. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15108. {
  15109. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15110. }
  15111. else
  15112. {
  15113. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15114. }
  15115. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15116. isKnowKey = TRUE;
  15117. }
  15118. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15119. {
  15120. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15121. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15122. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15123. {
  15124. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15125. }
  15126. else
  15127. {
  15128. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15129. }
  15130. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15131. isKnowKey = TRUE;
  15132. }
  15133. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15134. {
  15135. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15136. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15137. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15138. {
  15139. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15140. }
  15141. else
  15142. {
  15143. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15144. }
  15145. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15146. isKnowKey = TRUE;
  15147. }
  15148. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15149. {
  15150. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15151. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15152. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15153. {
  15154. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15155. }
  15156. else
  15157. {
  15158. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15159. }
  15160. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15161. isKnowKey = TRUE;
  15162. }
  15163. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15164. {
  15165. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15166. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15167. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15168. {
  15169. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15170. }
  15171. else
  15172. {
  15173. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15174. }
  15175. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15176. isKnowKey = TRUE;
  15177. }
  15178. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15179. {
  15180. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15181. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15182. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15183. {
  15184. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15185. }
  15186. else
  15187. {
  15188. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15189. }
  15190. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15191. isKnowKey = TRUE;
  15192. }
  15193. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15194. {
  15195. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15196. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15197. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15198. {
  15199. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15200. }
  15201. else
  15202. {
  15203. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15204. }
  15205. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15206. isKnowKey = TRUE;
  15207. }
  15208. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15209. {
  15210. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15211. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15212. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15213. {
  15214. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15215. }
  15216. else
  15217. {
  15218. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15219. }
  15220. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15221. isKnowKey = TRUE;
  15222. }
  15223. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15224. {
  15225. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15226. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15227. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15228. {
  15229. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15230. }
  15231. else
  15232. {
  15233. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15234. }
  15235. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15236. isKnowKey = TRUE;
  15237. }
  15238. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15239. {
  15240. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15241. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15242. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15243. {
  15244. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15245. }
  15246. else
  15247. {
  15248. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15249. }
  15250. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15251. isKnowKey = TRUE;
  15252. }
  15253. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15254. {
  15255. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15256. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15257. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15258. {
  15259. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15260. }
  15261. else
  15262. {
  15263. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15264. }
  15265. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15266. isKnowKey = TRUE;
  15267. }
  15268. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15269. {
  15270. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15271. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15272. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15273. {
  15274. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15275. }
  15276. else
  15277. {
  15278. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15279. }
  15280. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15281. isKnowKey = TRUE;
  15282. }
  15283. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15284. {
  15285. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15286. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15287. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15288. {
  15289. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15290. }
  15291. else
  15292. {
  15293. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15294. }
  15295. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15296. isKnowKey = TRUE;
  15297. }
  15298. /*
  15299. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15300. {
  15301. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15302. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15303. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15304. {
  15305. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15306. }
  15307. else
  15308. {
  15309. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15310. }
  15311. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15312. isKnowKey = TRUE;
  15313. }*/
  15314. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15315. {
  15316. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15317. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15318. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15319. {
  15320. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15321. }
  15322. else
  15323. {
  15324. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15325. }
  15326. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15327. isKnowKey = TRUE;
  15328. }
  15329. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15330. {
  15331. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15332. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15333. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15334. {
  15335. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15336. }
  15337. else
  15338. {
  15339. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15340. }
  15341. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15342. isKnowKey = TRUE;
  15343. }
  15344. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15345. {
  15346. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15347. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15348. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15349. {
  15350. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15351. }
  15352. else
  15353. {
  15354. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15355. }
  15356. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15357. isKnowKey = TRUE;
  15358. }
  15359. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15360. {
  15361. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15362. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15363. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15364. {
  15365. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15366. }
  15367. else
  15368. {
  15369. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15370. }
  15371. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15372. isKnowKey = TRUE;
  15373. }
  15374. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15375. {
  15376. struct sysinfo s_info;
  15377. int error = sysinfo(&s_info);
  15378. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15379. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15380. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15381. {
  15382. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15383. }
  15384. else
  15385. {
  15386. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15387. }
  15388. if(error != 0)
  15389. {
  15390. DEBUG_WARN("System uptime get error: %d\n", error);
  15391. }
  15392. else
  15393. {
  15394. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15395. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15396. }
  15397. isKnowKey = TRUE;
  15398. }
  15399. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15400. {
  15401. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15402. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15403. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15404. {
  15405. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15406. }
  15407. else
  15408. {
  15409. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15410. }
  15411. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15412. isKnowKey = TRUE;
  15413. }
  15414. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  15415. {
  15416. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  15417. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  15418. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  15419. {
  15420. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  15421. }
  15422. else
  15423. {
  15424. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  15425. }
  15426. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15427. isKnowKey = TRUE;
  15428. }
  15429. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15430. {
  15431. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15432. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15433. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15434. {
  15435. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15436. }
  15437. else
  15438. {
  15439. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15440. }
  15441. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15442. isKnowKey = TRUE;
  15443. }
  15444. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15445. {
  15446. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15447. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15448. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15449. {
  15450. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15451. }
  15452. else
  15453. {
  15454. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15455. }
  15456. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15457. isKnowKey = TRUE;
  15458. }
  15459. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15460. {
  15461. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15462. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15463. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15464. {
  15465. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15466. }
  15467. else
  15468. {
  15469. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15470. }
  15471. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15472. isKnowKey = TRUE;
  15473. }
  15474. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15475. {
  15476. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15477. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15478. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15479. {
  15480. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15481. }
  15482. else
  15483. {
  15484. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15485. }
  15486. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15487. isKnowKey = TRUE;
  15488. }
  15489. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  15490. {
  15491. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  15492. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  15493. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  15494. {
  15495. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  15496. }
  15497. else
  15498. {
  15499. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  15500. }
  15501. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  15502. isKnowKey = TRUE;
  15503. }
  15504. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  15505. {
  15506. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  15507. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  15508. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  15509. {
  15510. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  15511. }
  15512. else
  15513. {
  15514. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  15515. }
  15516. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  15517. isKnowKey = TRUE;
  15518. }
  15519. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  15520. {
  15521. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  15522. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  15523. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  15524. {
  15525. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  15526. }
  15527. else
  15528. {
  15529. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  15530. }
  15531. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  15532. isKnowKey = TRUE;
  15533. }
  15534. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15535. {
  15536. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15537. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15538. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15539. {
  15540. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15541. }
  15542. else
  15543. {
  15544. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15545. }
  15546. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15547. isKnowKey = TRUE;
  15548. }
  15549. #if 1
  15550. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15551. {
  15552. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15553. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15554. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15555. {
  15556. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15557. }
  15558. else
  15559. {
  15560. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15561. }
  15562. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15563. isKnowKey = TRUE;
  15564. }
  15565. #endif
  15566. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15567. {
  15568. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15569. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15570. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15571. {
  15572. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15573. }
  15574. else
  15575. {
  15576. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15577. }
  15578. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15579. isKnowKey = TRUE;
  15580. }
  15581. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15582. {
  15583. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15584. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15585. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15586. {
  15587. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15588. }
  15589. else
  15590. {
  15591. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15592. }
  15593. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15594. isKnowKey = TRUE;
  15595. }
  15596. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15597. {
  15598. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15599. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15600. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15601. {
  15602. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15603. }
  15604. else
  15605. {
  15606. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15607. }
  15608. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15609. isKnowKey = TRUE;
  15610. }
  15611. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15612. {
  15613. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15614. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15615. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15616. {
  15617. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15618. }
  15619. else
  15620. {
  15621. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15622. }
  15623. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15624. isKnowKey = TRUE;
  15625. }
  15626. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15627. {
  15628. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15629. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15630. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15631. {
  15632. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15633. }
  15634. else
  15635. {
  15636. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15637. }
  15638. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15639. isKnowKey = TRUE;
  15640. }
  15641. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15642. {
  15643. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15644. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15645. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15646. {
  15647. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15648. }
  15649. else
  15650. {
  15651. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15652. }
  15653. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15654. isKnowKey = TRUE;
  15655. }
  15656. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15657. {
  15658. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15659. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15660. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15661. {
  15662. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15663. }
  15664. else
  15665. {
  15666. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15667. }
  15668. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15669. isKnowKey = TRUE;
  15670. }
  15671. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15672. {
  15673. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15674. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15675. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15676. {
  15677. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15678. }
  15679. else
  15680. {
  15681. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15682. }
  15683. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15684. isKnowKey = TRUE;
  15685. }
  15686. //=========================================================
  15687. if(!isEmpty && !isKnowKey)
  15688. {
  15689. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15690. strcpy(unknownkey[UnknownKeynum], keyReq);
  15691. UnknownKeynum = UnknownKeynum + 1;
  15692. }
  15693. }
  15694. void processUnkownKey(void)
  15695. {
  15696. DEBUG_INFO("processUnkownKey...\n");
  15697. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15698. for(int index=0; index < UnknownKeynum; index++)
  15699. {
  15700. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15701. {
  15702. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15703. }
  15704. }
  15705. }
  15706. int setKeyValue(char *key, char *value)
  15707. {
  15708. int isSuccess = NotSupported;
  15709. int check_ascii=0;
  15710. char str[501]={0};
  15711. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15712. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15713. {
  15714. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15715. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15716. {
  15717. strcpy(str, (const char*)value);
  15718. for(int i = 0; str[i]; i++){
  15719. str[i] = tolower(str[i]);
  15720. }
  15721. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15722. isSuccess = ConfigurationStatus_Accepted;
  15723. }
  15724. else
  15725. {
  15726. isSuccess = ConfigurationStatus_Rejected;
  15727. }
  15728. }
  15729. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15730. {
  15731. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15732. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15733. {
  15734. strcpy(str, (const char*)value);
  15735. for(int i = 0; str[i]; i++){
  15736. str[i] = tolower(str[i]);
  15737. }
  15738. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15739. isSuccess = ConfigurationStatus_Accepted;
  15740. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  15741. }
  15742. else
  15743. {
  15744. isSuccess = ConfigurationStatus_Rejected;
  15745. }
  15746. }
  15747. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15748. {
  15749. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15750. {
  15751. strcpy(str, (const char*)value);
  15752. for(int i = 0; str[i]; i++)
  15753. {
  15754. str[i] = tolower(str[i]);
  15755. }
  15756. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15757. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15758. isSuccess = ConfigurationStatus_Accepted;
  15759. }
  15760. else
  15761. {
  15762. isSuccess = ConfigurationStatus_Rejected;
  15763. }
  15764. }
  15765. if(strcmp(key, "BlinkRepeat") == 0)
  15766. {
  15767. //Charger.BlinkRepeat = Integer.parseInt(value);
  15768. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15769. {
  15770. check_ascii = value[0];
  15771. if( (check_ascii < 48) || (check_ascii > 57) )
  15772. {
  15773. isSuccess = ConfigurationStatus_Rejected;
  15774. }
  15775. else
  15776. {
  15777. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15778. isSuccess = ConfigurationStatus_Accepted;
  15779. }
  15780. }
  15781. else
  15782. {
  15783. isSuccess = ConfigurationStatus_Rejected;
  15784. }
  15785. }
  15786. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15787. {
  15788. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15789. {
  15790. check_ascii = value[0];
  15791. if( (check_ascii < 48) || (check_ascii > 57) )
  15792. {
  15793. isSuccess = ConfigurationStatus_Rejected;
  15794. }
  15795. else
  15796. {
  15797. if((atoi(value) == 0) || (atoi(value) >= 5))
  15798. {
  15799. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15800. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15801. isSuccess = ConfigurationStatus_Accepted;
  15802. }
  15803. else
  15804. isSuccess = ConfigurationStatus_Rejected;
  15805. }
  15806. }
  15807. else
  15808. {
  15809. isSuccess = ConfigurationStatus_Rejected;
  15810. }
  15811. }
  15812. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15813. {
  15814. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15815. {
  15816. check_ascii = value[0];
  15817. if( (check_ascii < 48) || (check_ascii > 57) )
  15818. {
  15819. isSuccess = ConfigurationStatus_Rejected;
  15820. }
  15821. else
  15822. {
  15823. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15824. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15825. isSuccess = ConfigurationStatus_Accepted;
  15826. }
  15827. }
  15828. else
  15829. {
  15830. isSuccess = ConfigurationStatus_Rejected;
  15831. }
  15832. }
  15833. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15834. {
  15835. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15836. {
  15837. check_ascii = value[0];
  15838. if( (check_ascii < 48) || (check_ascii > 57) )
  15839. {
  15840. isSuccess = ConfigurationStatus_Rejected;
  15841. }
  15842. else
  15843. {
  15844. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15845. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15846. isSuccess = ConfigurationStatus_Accepted;
  15847. }
  15848. }
  15849. else
  15850. {
  15851. isSuccess = ConfigurationStatus_Rejected;
  15852. }
  15853. }
  15854. if(strcmp(key, "HeartbeatInterval") == 0)
  15855. {
  15856. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15857. {
  15858. check_ascii = value[0];
  15859. if( (check_ascii < 48) || (check_ascii > 57) )
  15860. {
  15861. isSuccess = ConfigurationStatus_Rejected;
  15862. }
  15863. else
  15864. {
  15865. if((atoi(value) == 0) || (atoi(value) >= 10))
  15866. {
  15867. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15868. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15869. HeartBeatWaitTime = atoi(value);
  15870. isSuccess = ConfigurationStatus_Accepted;
  15871. }
  15872. else
  15873. {
  15874. isSuccess = ConfigurationStatus_Rejected;
  15875. }
  15876. }
  15877. }
  15878. else
  15879. {
  15880. isSuccess = ConfigurationStatus_Rejected;
  15881. }
  15882. }
  15883. if(strcmp(key, "LightIntensity") == 0)
  15884. {
  15885. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15886. {
  15887. check_ascii = value[0];
  15888. if( (check_ascii < 48) || (check_ascii > 57) )
  15889. {
  15890. isSuccess = ConfigurationStatus_Rejected;
  15891. }
  15892. else
  15893. {
  15894. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15895. isSuccess = ConfigurationStatus_Accepted;
  15896. }
  15897. }
  15898. else
  15899. {
  15900. isSuccess = ConfigurationStatus_Rejected;
  15901. }
  15902. }
  15903. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15904. {
  15905. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15906. {
  15907. strcpy(str, (const char*)value);
  15908. for(int i = 0; str[i]; i++)
  15909. {
  15910. str[i] = tolower(str[i]);
  15911. }
  15912. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15913. isSuccess = ConfigurationStatus_Accepted;
  15914. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15915. }
  15916. else
  15917. {
  15918. isSuccess = ConfigurationStatus_Rejected;
  15919. }
  15920. }
  15921. if(strcmp(key, "LocalPreAuthorize") == 0)
  15922. {
  15923. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15924. {
  15925. strcpy(str, (const char*)value);
  15926. for(int i = 0; str[i]; i++)
  15927. {
  15928. str[i] = tolower(str[i]);
  15929. }
  15930. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15931. isSuccess = ConfigurationStatus_Accepted;
  15932. }
  15933. else
  15934. {
  15935. isSuccess = ConfigurationStatus_Rejected;
  15936. }
  15937. }
  15938. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15939. {
  15940. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15941. {
  15942. check_ascii = value[0];
  15943. if( (check_ascii < 48) || (check_ascii > 57) )
  15944. {
  15945. isSuccess = ConfigurationStatus_Rejected;
  15946. }
  15947. else
  15948. {
  15949. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15950. isSuccess = ConfigurationStatus_Accepted;
  15951. }
  15952. }
  15953. else
  15954. {
  15955. isSuccess = ConfigurationStatus_Rejected;
  15956. }
  15957. }
  15958. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15959. {
  15960. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15961. {
  15962. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15963. isSuccess = ConfigurationStatus_Accepted;
  15964. }
  15965. else
  15966. {
  15967. isSuccess = ConfigurationStatus_Rejected;
  15968. }
  15969. }
  15970. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15971. {
  15972. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15973. {
  15974. check_ascii = value[0];
  15975. if( (check_ascii < 48) || (check_ascii > 57) )
  15976. {
  15977. isSuccess = ConfigurationStatus_Rejected;
  15978. }
  15979. else
  15980. {
  15981. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15982. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15983. isSuccess = ConfigurationStatus_Accepted;
  15984. }
  15985. }
  15986. else
  15987. {
  15988. isSuccess = ConfigurationStatus_Rejected;
  15989. }
  15990. }
  15991. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15992. {
  15993. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15994. {
  15995. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15996. isSuccess = ConfigurationStatus_Accepted;
  15997. }
  15998. else
  15999. {
  16000. isSuccess = ConfigurationStatus_Rejected;
  16001. }
  16002. }
  16003. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  16004. {
  16005. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16006. {
  16007. check_ascii = value[0];
  16008. if( (check_ascii < 48) || (check_ascii > 57) )
  16009. {
  16010. isSuccess = ConfigurationStatus_Rejected;
  16011. }
  16012. else
  16013. {
  16014. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16015. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  16016. isSuccess = ConfigurationStatus_Accepted;
  16017. }
  16018. }
  16019. else
  16020. {
  16021. isSuccess = ConfigurationStatus_Rejected;
  16022. }
  16023. }
  16024. if(strcmp(key, "MeterValueSampleInterval") == 0)
  16025. {
  16026. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16027. {
  16028. check_ascii = value[0];
  16029. if( (check_ascii < 48) || (check_ascii > 57) )
  16030. {
  16031. isSuccess = ConfigurationStatus_Rejected;
  16032. }
  16033. else
  16034. {
  16035. if((atoi(value) == 0) || (atoi(value) >= 3))
  16036. {
  16037. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16038. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  16039. isSuccess = ConfigurationStatus_Accepted;
  16040. }
  16041. else
  16042. {
  16043. isSuccess = ConfigurationStatus_Rejected;
  16044. }
  16045. }
  16046. }
  16047. else
  16048. {
  16049. isSuccess = ConfigurationStatus_Rejected;
  16050. }
  16051. }
  16052. if(strcmp(key, "MinimumStatusDuration") == 0)
  16053. {
  16054. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16055. {
  16056. check_ascii = value[0];
  16057. if( (check_ascii < 48) || (check_ascii > 57) )
  16058. {
  16059. isSuccess = ConfigurationStatus_Rejected;
  16060. }
  16061. else
  16062. {
  16063. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  16064. {
  16065. isSuccess = ConfigurationStatus_Rejected;
  16066. }
  16067. else
  16068. {
  16069. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16070. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16071. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16072. isSuccess = ConfigurationStatus_Accepted;
  16073. }
  16074. }
  16075. }
  16076. else
  16077. {
  16078. isSuccess = ConfigurationStatus_Rejected;
  16079. }
  16080. }
  16081. if(strcmp(key, "NumberOfConnectors") == 0)
  16082. {
  16083. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16084. {
  16085. check_ascii = value[0];
  16086. if( (check_ascii < 48) || (check_ascii > 57) )
  16087. {
  16088. isSuccess = ConfigurationStatus_Rejected;
  16089. }
  16090. else
  16091. {
  16092. //Charger.ResetRetries = Integer.parseInt(value);
  16093. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16094. isSuccess = ConfigurationStatus_Accepted;
  16095. }
  16096. }
  16097. else
  16098. {
  16099. isSuccess = ConfigurationStatus_Rejected;
  16100. }
  16101. }
  16102. if(strcmp(key, "ResetRetries") == 0)
  16103. {
  16104. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16105. {
  16106. check_ascii = value[0];
  16107. if( (check_ascii < 48) || (check_ascii > 57) )
  16108. {
  16109. isSuccess = ConfigurationStatus_Rejected;
  16110. }
  16111. else
  16112. {
  16113. //Charger.ResetRetries = Integer.parseInt(value);
  16114. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16115. isSuccess = ConfigurationStatus_Accepted;
  16116. }
  16117. }
  16118. else
  16119. {
  16120. isSuccess = ConfigurationStatus_Rejected;
  16121. }
  16122. }
  16123. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16124. {
  16125. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16126. {
  16127. strcpy(str, (const char*)value);
  16128. for(int i = 0; str[i]; i++)
  16129. {
  16130. str[i] = tolower(str[i]);
  16131. }
  16132. if(strcmp(str, "notapplicable")== 0)
  16133. {
  16134. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16135. isSuccess = ConfigurationStatus_Accepted;
  16136. }
  16137. else if(strcmp(str, "unknown")== 0)
  16138. {
  16139. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16140. isSuccess = ConfigurationStatus_Accepted;
  16141. }
  16142. else if(strcmp(str, "rst")== 0)
  16143. {
  16144. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16145. isSuccess = ConfigurationStatus_Accepted;
  16146. }
  16147. else if(strcmp(str, "rts")== 0)
  16148. {
  16149. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16150. isSuccess = ConfigurationStatus_Accepted;
  16151. }
  16152. else if(strcmp(str, "srt")== 0)
  16153. {
  16154. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16155. isSuccess = ConfigurationStatus_Accepted;
  16156. }
  16157. else if(strcmp(str, "str")== 0)
  16158. {
  16159. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16160. isSuccess = ConfigurationStatus_Accepted;
  16161. }
  16162. else if(strcmp(str, "trs")== 0)
  16163. {
  16164. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16165. isSuccess = ConfigurationStatus_Accepted;
  16166. }
  16167. else if(strcmp(str, "tsr")== 0)
  16168. {
  16169. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16170. isSuccess = ConfigurationStatus_Accepted;
  16171. }
  16172. else
  16173. {
  16174. isSuccess = ConfigurationStatus_Rejected;
  16175. }
  16176. }
  16177. else
  16178. {
  16179. isSuccess = ConfigurationStatus_Rejected;
  16180. }
  16181. }
  16182. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16183. {
  16184. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16185. {
  16186. check_ascii = value[0];
  16187. if( (check_ascii < 48) || (check_ascii > 57) )
  16188. {
  16189. isSuccess = ConfigurationStatus_Rejected;
  16190. }
  16191. else
  16192. {
  16193. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16194. isSuccess = ConfigurationStatus_Accepted;
  16195. }
  16196. }
  16197. else
  16198. {
  16199. isSuccess = ConfigurationStatus_Rejected;
  16200. }
  16201. }
  16202. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16203. {
  16204. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16205. {
  16206. strcpy(str, (const char*)value);
  16207. for(int i = 0; str[i]; i++)
  16208. {
  16209. str[i] = tolower(str[i]);
  16210. }
  16211. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16212. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16213. isSuccess = ConfigurationStatus_Accepted;
  16214. }
  16215. else
  16216. {
  16217. isSuccess = ConfigurationStatus_Rejected;
  16218. }
  16219. }
  16220. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16221. {
  16222. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16223. {
  16224. strcpy(str, (const char*)value);
  16225. for(int i = 0; str[i]; i++)
  16226. {
  16227. str[i] = tolower(str[i]);
  16228. }
  16229. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16230. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16231. isSuccess = ConfigurationStatus_Accepted;
  16232. }
  16233. else
  16234. {
  16235. isSuccess = ConfigurationStatus_Rejected;
  16236. }
  16237. }
  16238. if(strcmp(key, "StopTxnAlignedData") == 0)
  16239. {
  16240. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16241. {
  16242. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16243. isSuccess = ConfigurationStatus_Accepted;
  16244. }
  16245. else
  16246. {
  16247. isSuccess = ConfigurationStatus_Rejected;
  16248. }
  16249. }
  16250. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16251. {
  16252. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16253. {
  16254. check_ascii = value[0];
  16255. if( (check_ascii < 48) || (check_ascii > 57) )
  16256. {
  16257. isSuccess = ConfigurationStatus_Rejected;
  16258. }
  16259. else
  16260. {
  16261. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16262. isSuccess = ConfigurationStatus_Accepted;
  16263. }
  16264. }
  16265. else
  16266. {
  16267. isSuccess = ConfigurationStatus_Rejected;
  16268. }
  16269. }
  16270. if(strcmp(key, "StopTxnSampledData") == 0)
  16271. {
  16272. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16273. {
  16274. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16275. isSuccess = ConfigurationStatus_Accepted;
  16276. }
  16277. else
  16278. {
  16279. isSuccess = ConfigurationStatus_Rejected;
  16280. }
  16281. }
  16282. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16283. {
  16284. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16285. {
  16286. check_ascii = value[0];
  16287. if( (check_ascii < 48) || (check_ascii > 57) )
  16288. {
  16289. isSuccess = ConfigurationStatus_Rejected;
  16290. }
  16291. else
  16292. {
  16293. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16294. isSuccess = ConfigurationStatus_Accepted;
  16295. }
  16296. }
  16297. else
  16298. {
  16299. isSuccess = ConfigurationStatus_Rejected;
  16300. }
  16301. }
  16302. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16303. {
  16304. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16305. {
  16306. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16307. isSuccess = ConfigurationStatus_Accepted;
  16308. }
  16309. else
  16310. {
  16311. isSuccess = ConfigurationStatus_Rejected;
  16312. }
  16313. }
  16314. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16315. {
  16316. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16317. {
  16318. check_ascii = value[0];
  16319. if( (check_ascii < 48) || (check_ascii > 57) )
  16320. {
  16321. isSuccess = ConfigurationStatus_Rejected;
  16322. }
  16323. else
  16324. {
  16325. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16326. isSuccess = ConfigurationStatus_Accepted;
  16327. }
  16328. }
  16329. else
  16330. {
  16331. isSuccess = ConfigurationStatus_Rejected;
  16332. }
  16333. }
  16334. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16335. {
  16336. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16337. {
  16338. check_ascii = value[0];
  16339. if( (check_ascii < 48) || (check_ascii > 57) )
  16340. {
  16341. isSuccess = ConfigurationStatus_Rejected;
  16342. }
  16343. else
  16344. {
  16345. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16346. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16347. TransactionMessageAttemptsValue = atoi(value);
  16348. isSuccess = ConfigurationStatus_Accepted;
  16349. }
  16350. }
  16351. else
  16352. {
  16353. isSuccess = ConfigurationStatus_Rejected;
  16354. }
  16355. }
  16356. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16357. {
  16358. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16359. {
  16360. check_ascii = value[0];
  16361. if( (check_ascii < 48) || (check_ascii > 57) )
  16362. {
  16363. isSuccess = ConfigurationStatus_Rejected;
  16364. }
  16365. else
  16366. {
  16367. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16368. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16369. TransactionMessageRetryIntervalValue = atoi(value);
  16370. isSuccess = ConfigurationStatus_Accepted;
  16371. }
  16372. }
  16373. else
  16374. {
  16375. isSuccess = ConfigurationStatus_Rejected;
  16376. }
  16377. }
  16378. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16379. {
  16380. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].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. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16388. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16389. isSuccess = ConfigurationStatus_Accepted;
  16390. }
  16391. else
  16392. {
  16393. isSuccess = ConfigurationStatus_Rejected;
  16394. }
  16395. }
  16396. if(strcmp(key, "WebSocketPingInterval") == 0)
  16397. {
  16398. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16399. {
  16400. check_ascii = value[0];
  16401. if( (check_ascii < 48) || (check_ascii > 57) )
  16402. {
  16403. isSuccess = ConfigurationStatus_Rejected;
  16404. }
  16405. else
  16406. {
  16407. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16408. isSuccess = ConfigurationStatus_Accepted;
  16409. if((atoi(value) == 0) || (atoi(value) >= 10))
  16410. {
  16411. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16412. isSuccess = ConfigurationStatus_Accepted;
  16413. }
  16414. else
  16415. isSuccess = ConfigurationStatus_Rejected;
  16416. }
  16417. }
  16418. else
  16419. {
  16420. isSuccess = ConfigurationStatus_Rejected;
  16421. }
  16422. }
  16423. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16424. {
  16425. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16426. {
  16427. strcpy(str, (const char*)value);
  16428. for(int i = 0; str[i]; i++)
  16429. {
  16430. str[i] = tolower(str[i]);
  16431. }
  16432. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16433. isSuccess = ConfigurationStatus_Accepted;
  16434. }
  16435. else
  16436. {
  16437. isSuccess = ConfigurationStatus_Rejected;
  16438. }
  16439. }
  16440. if(strcmp(key, "AuthorizationKey") == 0)
  16441. {
  16442. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16443. {
  16444. strcpy(str, (const char*)value);
  16445. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16446. strcpy((char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16447. isSuccess = ConfigurationStatus_Accepted;
  16448. }
  16449. else
  16450. {
  16451. isSuccess = ConfigurationStatus_Rejected;
  16452. }
  16453. }
  16454. if(strcmp(key, "SecurityProfile") == 0)
  16455. {
  16456. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16457. {
  16458. check_ascii = value[0];
  16459. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16460. {
  16461. isSuccess = ConfigurationStatus_Rejected;
  16462. }
  16463. else if(check_ascii == 0x33)
  16464. {
  16465. isSuccess = NotSupported;
  16466. }
  16467. else
  16468. {
  16469. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16470. {
  16471. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16472. ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = atoi(value);
  16473. isSuccess = ConfigurationStatus_Accepted;
  16474. }
  16475. else
  16476. isSuccess = ConfigurationStatus_Rejected;
  16477. }
  16478. }
  16479. else
  16480. {
  16481. isSuccess = ConfigurationStatus_Rejected;
  16482. }
  16483. }
  16484. if(strcmp(key, "DefaultPrice") == 0)
  16485. {
  16486. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16487. {
  16488. strcpy(str, (const char*)value);
  16489. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16490. isSuccess = ConfigurationStatus_Accepted;
  16491. }
  16492. else
  16493. {
  16494. isSuccess = ConfigurationStatus_Rejected;
  16495. }
  16496. }
  16497. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16498. {
  16499. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16500. {
  16501. strcpy(str, (const char*)value);
  16502. for(int i = 0; str[i]; i++)
  16503. {
  16504. str[i] = tolower(str[i]);
  16505. }
  16506. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16507. isSuccess = ConfigurationStatus_Accepted;
  16508. }
  16509. else
  16510. {
  16511. isSuccess = ConfigurationStatus_Rejected;
  16512. }
  16513. }
  16514. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16515. {
  16516. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16517. {
  16518. strcpy(str, (const char*)value);
  16519. for(int i = 0; str[i]; i++)
  16520. {
  16521. str[i] = tolower(str[i]);
  16522. }
  16523. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16524. isSuccess = ConfigurationStatus_Accepted;
  16525. }
  16526. else
  16527. {
  16528. isSuccess = ConfigurationStatus_Rejected;
  16529. }
  16530. }
  16531. if(strcmp(key, "SystemUptimeSec") == 0)
  16532. {
  16533. isSuccess = NotSupported;
  16534. }
  16535. if(strcmp(key, "FreeVend") == 0)
  16536. {
  16537. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16538. {
  16539. strcpy(str, (const char*)value);
  16540. for(int i = 0; str[i]; i++)
  16541. {
  16542. str[i] = tolower(str[i]);
  16543. }
  16544. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16545. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16546. isSuccess = ConfigurationStatus_Accepted;
  16547. }
  16548. else
  16549. {
  16550. isSuccess = ConfigurationStatus_Rejected;
  16551. }
  16552. }
  16553. if(strcmp(key, "FreeVendIdtag") == 0)
  16554. {
  16555. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16556. {
  16557. strcpy(str, (const char*)value);
  16558. if(strlen(str) <= 20)
  16559. {
  16560. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  16561. isSuccess = ConfigurationStatus_Accepted;
  16562. }
  16563. else
  16564. {
  16565. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  16566. isSuccess = ConfigurationStatus_Rejected;
  16567. }
  16568. }
  16569. else
  16570. {
  16571. isSuccess = ConfigurationStatus_Rejected;
  16572. }
  16573. }
  16574. if(strcmp(key, "OcppServer") == 0)
  16575. {
  16576. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16577. {
  16578. strcpy(str, (const char*)value);
  16579. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16580. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16581. isSuccess = ConfigurationStatus_Accepted;
  16582. }
  16583. else
  16584. {
  16585. isSuccess = ConfigurationStatus_Rejected;
  16586. }
  16587. }
  16588. if(strcmp(key, "MaintainServer") == 0)
  16589. {
  16590. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16591. {
  16592. strcpy(str, (const char*)value);
  16593. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16594. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16595. isSuccess = ConfigurationStatus_Accepted;
  16596. }
  16597. else
  16598. {
  16599. isSuccess = ConfigurationStatus_Rejected;
  16600. }
  16601. }
  16602. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  16603. {
  16604. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16605. {
  16606. strcpy(str, (const char*)value);
  16607. for(int i = 0; str[i]; i++)
  16608. {
  16609. str[i] = tolower(str[i]);
  16610. }
  16611. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  16612. isSuccess = ConfigurationStatus_Accepted;
  16613. }
  16614. else
  16615. {
  16616. isSuccess = ConfigurationStatus_Rejected;
  16617. }
  16618. }
  16619. if(strcmp(key, "StatusNotificationInterval") == 0)
  16620. {
  16621. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16622. {
  16623. check_ascii = value[0];
  16624. if( (check_ascii < 48) || (check_ascii > 57) )
  16625. {
  16626. isSuccess = ConfigurationStatus_Rejected;
  16627. }
  16628. else
  16629. {
  16630. if((atoi(value) == 0) || (atoi(value) >= 10))
  16631. {
  16632. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16633. isSuccess = ConfigurationStatus_Accepted;
  16634. }
  16635. else
  16636. isSuccess = ConfigurationStatus_Rejected;
  16637. }
  16638. }
  16639. else
  16640. {
  16641. isSuccess = ConfigurationStatus_Rejected;
  16642. }
  16643. }
  16644. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  16645. {
  16646. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  16647. {
  16648. check_ascii = value[0];
  16649. if( (check_ascii < 48) || (check_ascii > 57) )
  16650. {
  16651. isSuccess = ConfigurationStatus_Rejected;
  16652. }
  16653. else
  16654. {
  16655. if(atoi(value) >= 0)
  16656. {
  16657. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value) );
  16658. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  16659. isSuccess = ConfigurationStatus_Accepted;
  16660. }
  16661. else
  16662. isSuccess = ConfigurationStatus_Rejected;
  16663. }
  16664. }
  16665. else
  16666. {
  16667. isSuccess = ConfigurationStatus_Rejected;
  16668. }
  16669. }
  16670. if(strcmp(key, "PowerSharingServerIP") == 0)
  16671. {
  16672. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  16673. {
  16674. strcpy(str, (const char*)value);
  16675. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  16676. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  16677. isSuccess = ConfigurationStatus_Accepted;
  16678. }
  16679. else
  16680. {
  16681. isSuccess = ConfigurationStatus_Rejected;
  16682. }
  16683. }
  16684. if(strcmp(key, "EVCCID_PREFIX") == 0)
  16685. {
  16686. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  16687. {
  16688. strcpy(str, (const char*)value);
  16689. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  16690. isSuccess = ConfigurationStatus_Accepted;
  16691. }
  16692. else
  16693. {
  16694. isSuccess = ConfigurationStatus_Rejected;
  16695. }
  16696. }
  16697. #if 0
  16698. //For OCPP Test Case
  16699. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16700. {
  16701. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16702. {
  16703. strcpy(str, (const char*)value);
  16704. for(int i = 0; str[i]; i++)
  16705. {
  16706. str[i] = tolower(str[i]);
  16707. }
  16708. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16709. isSuccess = ConfigurationStatus_Accepted;
  16710. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16711. }
  16712. else
  16713. {
  16714. isSuccess = ConfigurationStatus_Rejected;
  16715. }
  16716. }
  16717. #endif
  16718. #if 1
  16719. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16720. {
  16721. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16722. {
  16723. strcpy(str, (const char*)value);
  16724. for(int i = 0; str[i]; i++)
  16725. {
  16726. str[i] = tolower(str[i]);
  16727. }
  16728. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16729. isSuccess = ConfigurationStatus_Accepted;
  16730. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16731. }
  16732. else
  16733. {
  16734. isSuccess = ConfigurationStatus_Rejected;
  16735. }
  16736. }
  16737. #endif
  16738. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16739. {
  16740. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16741. {
  16742. check_ascii = value[0];
  16743. if( (check_ascii < 48) || (check_ascii > 57) )
  16744. {
  16745. isSuccess = ConfigurationStatus_Rejected;
  16746. }
  16747. else
  16748. {
  16749. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16750. isSuccess = ConfigurationStatus_Accepted;
  16751. }
  16752. }
  16753. else
  16754. {
  16755. isSuccess = ConfigurationStatus_Rejected;
  16756. }
  16757. }
  16758. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16759. {
  16760. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16761. {
  16762. check_ascii = value[0];
  16763. if( (check_ascii < 48) || (check_ascii > 57) )
  16764. {
  16765. isSuccess = ConfigurationStatus_Rejected;
  16766. }
  16767. else
  16768. {
  16769. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16770. isSuccess = ConfigurationStatus_Accepted;
  16771. }
  16772. }
  16773. else
  16774. {
  16775. isSuccess = ConfigurationStatus_Rejected;
  16776. }
  16777. }
  16778. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16779. {
  16780. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16781. {
  16782. strcpy(str, (const char*)value);
  16783. for(int i = 0; str[i]; i++)
  16784. {
  16785. str[i] = tolower(str[i]);
  16786. }
  16787. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16788. isSuccess = ConfigurationStatus_Accepted;
  16789. }
  16790. else
  16791. {
  16792. isSuccess = ConfigurationStatus_Rejected;
  16793. }
  16794. }
  16795. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16796. {
  16797. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16798. {
  16799. check_ascii = value[0];
  16800. if( (check_ascii < 48) || (check_ascii > 57) )
  16801. {
  16802. isSuccess = ConfigurationStatus_Rejected;
  16803. }
  16804. else
  16805. {
  16806. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16807. isSuccess = ConfigurationStatus_Accepted;
  16808. }
  16809. }
  16810. else
  16811. {
  16812. isSuccess = ConfigurationStatus_Rejected;
  16813. }
  16814. }
  16815. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16816. {
  16817. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16818. {
  16819. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16820. isSuccess = ConfigurationStatus_Accepted;
  16821. }
  16822. else
  16823. {
  16824. isSuccess = ConfigurationStatus_Rejected;
  16825. }
  16826. }
  16827. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16828. {
  16829. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16830. {
  16831. check_ascii = value[0];
  16832. if( (check_ascii < 48) || (check_ascii > 57) )
  16833. {
  16834. isSuccess = ConfigurationStatus_Rejected;
  16835. }
  16836. else
  16837. {
  16838. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16839. isSuccess = ConfigurationStatus_Accepted;
  16840. }
  16841. }
  16842. else
  16843. {
  16844. isSuccess = ConfigurationStatus_Rejected;
  16845. }
  16846. }
  16847. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16848. {
  16849. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16850. {
  16851. strcpy(str, (const char*)value);
  16852. for(int i = 0; str[i]; i++)
  16853. {
  16854. str[i] = tolower(str[i]);
  16855. }
  16856. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16857. isSuccess = ConfigurationStatus_Accepted;
  16858. }
  16859. else
  16860. {
  16861. isSuccess = ConfigurationStatus_Rejected;
  16862. }
  16863. }
  16864. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16865. {
  16866. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16867. {
  16868. check_ascii = value[0];
  16869. if( (check_ascii < 48) || (check_ascii > 57) )
  16870. {
  16871. isSuccess = ConfigurationStatus_Rejected;
  16872. }
  16873. else
  16874. {
  16875. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16876. isSuccess = ConfigurationStatus_Accepted;
  16877. }
  16878. }
  16879. else
  16880. {
  16881. isSuccess = ConfigurationStatus_Rejected;
  16882. }
  16883. }
  16884. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16885. return isSuccess;
  16886. }
  16887. int TransactionMessageAttemptsGet(void)
  16888. {
  16889. return TransactionMessageAttemptsValue;
  16890. }
  16891. int FirstHeartBeatResponse(void)
  16892. {
  16893. return FirstHeartBeat;
  16894. }
  16895. int TransactionMessageRetryIntervalGet(void)
  16896. {
  16897. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16898. }
  16899. int ReadHttpStatus(int sock)
  16900. {
  16901. //char c;
  16902. char buff[1024]="",*ptr=buff+1;
  16903. int bytes_received, status;
  16904. DEBUG_INFO("Begin Response ..\n");
  16905. while((bytes_received = recv(sock, ptr, 1, 0))){
  16906. if(bytes_received==-1){
  16907. perror("ReadHttpStatus");
  16908. exit(1);
  16909. }
  16910. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16911. ptr++;
  16912. }
  16913. *ptr=0;
  16914. ptr=buff+1;
  16915. sscanf(ptr,"%*s %d ", &status);
  16916. DEBUG_INFO("%s\n",ptr);
  16917. DEBUG_INFO("status=%d\n",status);
  16918. DEBUG_INFO("End Response ..\n");
  16919. return (bytes_received>0)?status:0;
  16920. }
  16921. //the only filed that it parsed is 'Content-Length'
  16922. int ParseHeader(int sock)
  16923. {
  16924. //char c;
  16925. char buff[1024]="",*ptr=buff+4;
  16926. int bytes_received;
  16927. DEBUG_INFO("Begin HEADER ..\n");
  16928. while((bytes_received = recv(sock, ptr, 1, 0))){
  16929. if(bytes_received==-1){
  16930. perror("Parse Header");
  16931. exit(1);
  16932. }
  16933. if(
  16934. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16935. (ptr[-1]=='\r') && (*ptr=='\n' )
  16936. ) break;
  16937. ptr++;
  16938. }
  16939. *ptr=0;
  16940. ptr=buff+4;
  16941. //printf("%s",ptr);
  16942. if(bytes_received){
  16943. ptr=strstr(ptr,"Content-Length:");
  16944. if(ptr){
  16945. sscanf(ptr,"%*s %d",&bytes_received);
  16946. }else
  16947. bytes_received=-1; //unknown size
  16948. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16949. }
  16950. DEBUG_INFO("End HEADER ..\n");
  16951. return bytes_received ;
  16952. }
  16953. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16954. {
  16955. int result = TRUE;
  16956. char rmFileCmd[100]={0};
  16957. char FilePath[100]={0};
  16958. char ftpbuf[200];
  16959. int systemresult;
  16960. sprintf(FilePath,"/mnt/%s",filename);
  16961. system("ping 8.8.8.8 &");
  16962. if((access(FilePath,F_OK))!=-1)
  16963. {
  16964. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16965. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16966. system(rmFileCmd);
  16967. }
  16968. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16969. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16970. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16971. systemresult = system(ftpbuf);
  16972. if(systemresult != 0)
  16973. {
  16974. DEBUG_INFO("http DownLoad error!\n");
  16975. result = FALSE;
  16976. }
  16977. system("pkill ping");
  16978. return result;
  16979. }
  16980. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16981. {
  16982. int result = TRUE;
  16983. char rmFileCmd[100]={0};
  16984. char FilePath[100]={0};
  16985. char ftpbuf[200];
  16986. int systemresult;
  16987. sprintf(FilePath,"/mnt/%s",filename);
  16988. system("ping 8.8.8.8 &");
  16989. if((access(FilePath,F_OK))!=-1)
  16990. {
  16991. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16992. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16993. system(rmFileCmd);
  16994. }
  16995. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16996. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  16997. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16998. systemresult = system(ftpbuf);
  16999. if(systemresult != 0)
  17000. {
  17001. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  17002. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17003. systemresult = system(ftpbuf);
  17004. if(systemresult != 0)
  17005. {
  17006. DEBUG_WARN("wget error!\n");
  17007. result = FALSE;
  17008. }
  17009. }
  17010. system("pkill ping");
  17011. return result;
  17012. }
  17013. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17014. {
  17015. char rmFileCmd[100]={0};
  17016. char FilePath[100]={0};
  17017. char buf[512];
  17018. int systemresult = 0;
  17019. //DEBUG_INFO("filename=%s\n",filename);
  17020. //DEBUG_INFO("url=%s\n",url);
  17021. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17022. if((access(FilePath,F_OK))!=-1)
  17023. {
  17024. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17025. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17026. system(rmFileCmd);
  17027. }
  17028. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17029. if(fp == NULL)
  17030. {
  17031. DEBUG_INFO("log is NULL\n");
  17032. return FALSE;
  17033. }
  17034. else
  17035. {
  17036. fprintf(fp, "%s\n", url);
  17037. fprintf(fp, "%s\n", filename);
  17038. fclose(fp);
  17039. }
  17040. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  17041. if(phpFP == NULL)
  17042. {
  17043. DEBUG_INFO("PHP upload fail.\n");
  17044. return FALSE;
  17045. }
  17046. else
  17047. {
  17048. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17049. {
  17050. if(strstr(buf, "result") != NULL)
  17051. {
  17052. sscanf(buf, "result: %d", &systemresult);
  17053. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17054. }
  17055. }
  17056. pclose(phpFP);
  17057. }
  17058. if(systemresult != 1)
  17059. {
  17060. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  17061. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  17062. if(phpFP == NULL)
  17063. {
  17064. DEBUG_WARN("PHP PUT upload fail.\n");
  17065. return FALSE;
  17066. }
  17067. else
  17068. {
  17069. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17070. {
  17071. if(strstr(buf, "result") != NULL)
  17072. {
  17073. sscanf(buf, "result: %d", &systemresult);
  17074. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  17075. }
  17076. }
  17077. pclose(phpFP);
  17078. }
  17079. }
  17080. if(systemresult != 1)
  17081. {
  17082. DEBUG_WARN("PHP PUT upload fail.\n");
  17083. return FALSE;
  17084. }
  17085. return TRUE;
  17086. }
  17087. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17088. {
  17089. int result = FALSE;
  17090. char ftpbuf[200];
  17091. int systemresult;
  17092. /*
  17093. // Domaind name transfer to IP address
  17094. struct hostent* server;
  17095. char *IPbuffer;
  17096. server = gethostbyname(location);
  17097. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17098. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17099. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17100. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  17101. systemresult = system(ftpbuf);
  17102. if(systemresult != 0)
  17103. {
  17104. DEBUG_INFO("ftpput error!\n");
  17105. }
  17106. else
  17107. {
  17108. result = TRUE;
  17109. DEBUG_INFO("ftpput OK!\n");
  17110. }
  17111. return result;
  17112. }
  17113. int GetOcppServerURL()
  17114. {
  17115. int result = FALSE;
  17116. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  17117. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  17118. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  17119. struct yuarel url;
  17120. char urlStr[512];
  17121. // OCPPPH only
  17122. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  17123. if((ShmSysConfigAndInfo->SysConfig.MaintainServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) )
  17124. {
  17125. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  17126. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17127. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17128. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.MaintainServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  17129. if(yuarel_parse(&url, urlStr) != -1)
  17130. {
  17131. sprintf(OcppProtocol, "%s", url.scheme);
  17132. sprintf(OcppHost, "%s", url.host);
  17133. if(url.path == NULL)
  17134. OcppTempPath[0] = '\0';
  17135. else
  17136. sprintf(OcppTempPath, "%s", url.path);
  17137. if(url.port == 0)
  17138. {
  17139. if(strcmp(OcppProtocol, "wss") == 0)
  17140. OcppPort = 443;
  17141. else
  17142. OcppPort = 80;
  17143. }
  17144. else
  17145. OcppPort = url.port;
  17146. result = TRUE;
  17147. }
  17148. }
  17149. else
  17150. {
  17151. strcpy(OcppHost,"");
  17152. }
  17153. return result;
  17154. }
  17155. int GetOcppPath()
  17156. {
  17157. int result = FALSE;
  17158. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  17159. {
  17160. if(OcppTempPath == NULL)
  17161. {
  17162. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  17163. }
  17164. else
  17165. {
  17166. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  17167. }
  17168. result = TRUE;
  17169. goto End;
  17170. }
  17171. else
  17172. {
  17173. strcpy(OcppPath,"");
  17174. }
  17175. End:
  17176. return result;
  17177. }
  17178. int GetOcppPort()
  17179. {
  17180. return OcppPort;
  17181. }
  17182. int GetOcppConnStatus(void)
  17183. {
  17184. return ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus;
  17185. }
  17186. void SetOcppConnStatus(uint8_t status)
  17187. {
  17188. ShmOCPP16DataPH->OcppConnStatus = status;
  17189. ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus = status;
  17190. }
  17191. int GetHeartBeatWithNOResponse(void)
  17192. {
  17193. return HeartBeatWithNOResponse;
  17194. }
  17195. void SetHeartBeatWithNOResponse(void)
  17196. {
  17197. HeartBeatWithNOResponse = 0;
  17198. }
  17199. void GetStartTransactionIdTag(int gun_index)
  17200. {
  17201. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17202. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  17203. }
  17204. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17205. {
  17206. char ch;
  17207. FILE *fptr1;
  17208. int temptransactionId;
  17209. char str[100]={0};
  17210. temptransactionId = 0;
  17211. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17212. {
  17213. DEBUG_INFO("IdTag is empty.\n");
  17214. return temptransactionId;
  17215. }
  17216. /*------ Read the file ----------------*/
  17217. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  17218. if (!fptr1)
  17219. {
  17220. DEBUG_INFO("QueueTransactionId file open error.\n");
  17221. //printf(" File not found or unable to open the input file!!\n");
  17222. return temptransactionId;
  17223. }
  17224. ch=fgetc(fptr1);
  17225. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  17226. rewind(fptr1);
  17227. if(ch!=EOF)
  17228. {
  17229. // printf("%c",ch);
  17230. while (fgets(str, 100, fptr1) != NULL)
  17231. {
  17232. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17233. if(str[0]=='\0')
  17234. {
  17235. break;
  17236. }
  17237. char *revbuf[8] = {0}; // Variable store string split
  17238. int num = 0;// Quantity after string split
  17239. DEBUG_INFO("Transaction queue data= %s\n", str);
  17240. splitstring(str,",",revbuf,&num); // String split
  17241. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17242. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17243. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17244. DEBUG_INFO("------------------------------\n");
  17245. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17246. {
  17247. if(isStopTransaction)
  17248. {
  17249. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17250. {
  17251. temptransactionId = atoi(revbuf[2]);
  17252. //break;
  17253. }
  17254. }
  17255. else
  17256. {
  17257. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17258. {
  17259. temptransactionId = atoi(revbuf[2]);
  17260. //break;
  17261. }
  17262. }
  17263. }
  17264. }
  17265. }
  17266. else
  17267. DEBUG_INFO("EOF\n");
  17268. fclose(fptr1);
  17269. /*------- End of reading ---------------*/
  17270. return temptransactionId;
  17271. }
  17272. void SetTransactionIdZero(int transactionId)
  17273. {
  17274. char ch;
  17275. FILE *fptr1, *fptr2;
  17276. int temptransactionId = 0;
  17277. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  17278. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  17279. if (!fptr1)
  17280. {
  17281. //printf(" File not found or unable to open the input file!!\n");
  17282. return ;
  17283. }
  17284. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17285. if (!fptr2)
  17286. {
  17287. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17288. fclose(fptr1);
  17289. return ;
  17290. }
  17291. ch=fgetc(fptr1);
  17292. rewind(fptr1);
  17293. if(ch!=EOF)
  17294. {
  17295. // copy all contents to the temporary file except the specific line
  17296. while (fgets(str, 100, fptr1) != NULL)
  17297. {
  17298. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17299. if(str[0]=='\0')
  17300. {
  17301. break;
  17302. }
  17303. char *revbuf[8] = {0};
  17304. int num = 0;
  17305. strcpy(strtemp, str);
  17306. splitstring(str,",",revbuf,&num);
  17307. if(revbuf[2][0] != '\0')
  17308. {
  17309. temptransactionId = atoi(revbuf[2]);
  17310. if(transactionId != temptransactionId)
  17311. {
  17312. fprintf(fptr2, "%s\n", strtemp);
  17313. }
  17314. }
  17315. }
  17316. }
  17317. fclose(fptr1);
  17318. fclose(fptr2);
  17319. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  17320. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  17321. /*------ Read the file ----------------*/
  17322. }
  17323. int InternetDisconnect(void)
  17324. {
  17325. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  17326. }
  17327. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17328. void storeTempStopTransaction(int gun_index)
  17329. {
  17330. char guid[37]={0};
  17331. int tempIndex = 0;
  17332. char TempStopTransaction[256];
  17333. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17334. DEBUG_INFO("storeTempStopTransaction...\n");
  17335. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  17336. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  17337. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  17338. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17339. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17340. {
  17341. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17342. {
  17343. tempIndex = ((gun_index==2) ? 1: 0);
  17344. }
  17345. else
  17346. {
  17347. tempIndex = gun_index;
  17348. }
  17349. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17350. {
  17351. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17352. {
  17353. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  17354. }
  17355. }// END OF CHAdeMO_QUANTITY
  17356. }
  17357. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17358. {
  17359. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17360. {
  17361. tempIndex = ((gun_index==2) ? 1: 0);
  17362. }
  17363. else
  17364. {
  17365. tempIndex = gun_index;
  17366. }
  17367. for (int index = 0; index < CCS_QUANTITY; index++)
  17368. {
  17369. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17370. {
  17371. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  17372. }
  17373. }// END OF CCS_QUANTITY
  17374. }
  17375. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17376. {
  17377. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17378. {
  17379. tempIndex = ((gun_index==2) ? 1: 0);
  17380. }
  17381. else
  17382. {
  17383. tempIndex = gun_index;
  17384. }
  17385. for (int index = 0; index < GB_QUANTITY; index++)
  17386. {
  17387. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17388. {
  17389. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17390. }
  17391. }// END OF GB_QUANTITY
  17392. }
  17393. else if(gunType[gun_index] == GUN_TYPE_DO)
  17394. {
  17395. tempIndex = gun_index;
  17396. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17397. {
  17398. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17399. {
  17400. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17401. }
  17402. }
  17403. }
  17404. else
  17405. {
  17406. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17407. {
  17408. tempIndex = 2;
  17409. }
  17410. else
  17411. {
  17412. tempIndex = gun_index;
  17413. }
  17414. for (int index = 0; index < AC_QUANTITY; index++)
  17415. {
  17416. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17417. {
  17418. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17419. }
  17420. }// END OF AC_QUANTITY
  17421. }
  17422. //Stop Transaction Time
  17423. struct timeval tmnow;
  17424. struct tm *tm;
  17425. char buf[28];//, usec_buf[6];
  17426. gettimeofday(&tmnow, NULL);
  17427. time_t t;
  17428. t = time(NULL);
  17429. /*UTC time and date*/
  17430. tm = gmtime(&t);
  17431. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17432. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  17433. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  17434. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  17435. random_uuid(guid);
  17436. /***********************************transactionData******************************************************/
  17437. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17438. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17439. //=================================
  17440. //1. Transaction_Begin
  17441. //=================================
  17442. //============================== Energy.Active.Import.Interval ===========================================
  17443. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17444. {
  17445. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  17446. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17447. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  17448. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  17449. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17450. 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))
  17451. {
  17452. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  17453. }
  17454. else
  17455. {
  17456. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  17457. }
  17458. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  17459. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17460. }
  17461. //=================================
  17462. //2. Transaction_End
  17463. //=================================
  17464. //2.1====================================== Current.Import L1 ==============================================
  17465. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17466. {
  17467. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17468. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17469. {
  17470. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17471. {
  17472. tempIndex = ((gun_index==2) ? 1: 0);
  17473. }
  17474. else
  17475. {
  17476. tempIndex = gun_index;
  17477. }
  17478. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17479. {
  17480. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17481. {
  17482. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17483. }
  17484. }// End of for CHAdeMO_QUANTITY
  17485. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17486. }
  17487. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17488. {
  17489. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17490. {
  17491. tempIndex = ((gun_index==2) ? 1: 0);
  17492. }
  17493. else
  17494. {
  17495. tempIndex = gun_index;
  17496. }
  17497. for (int index = 0; index < CCS_QUANTITY; index++)
  17498. {
  17499. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17500. {
  17501. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17502. }
  17503. }// End of for CCS_QUANTITY
  17504. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17505. }
  17506. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17507. {
  17508. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17509. {
  17510. tempIndex = ((gun_index==2) ? 1: 0);
  17511. }
  17512. else
  17513. {
  17514. tempIndex = gun_index;
  17515. }
  17516. for (int index = 0; index < GB_QUANTITY; index++)
  17517. {
  17518. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17519. {
  17520. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17521. }
  17522. }// End of for GB_QUANTITY
  17523. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17524. }
  17525. else if(gunType[gun_index] == GUN_TYPE_DO)
  17526. {
  17527. tempIndex = gun_index;
  17528. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17529. {
  17530. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17531. {
  17532. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17533. }
  17534. }
  17535. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17536. }
  17537. else
  17538. {
  17539. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17540. {
  17541. tempIndex = 2;
  17542. }
  17543. else
  17544. {
  17545. tempIndex = gun_index;
  17546. }
  17547. for (int index = 0; index < AC_QUANTITY; index++)
  17548. {
  17549. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17550. {
  17551. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  17552. }
  17553. }// End of for AC_QUANTITY
  17554. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17555. }
  17556. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17557. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  17558. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  17559. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17560. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  17561. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17562. }
  17563. //2.2===================================== Energy.Active.Import.Interval ==========================================
  17564. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17565. {
  17566. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17567. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17568. {
  17569. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17570. {
  17571. tempIndex = ((gun_index==2) ? 1: 0);
  17572. }
  17573. else
  17574. {
  17575. tempIndex = gun_index;
  17576. }
  17577. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17578. {
  17579. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17580. {
  17581. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17582. }
  17583. }// END OF CHAdeMO_QUANTITY
  17584. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17585. }
  17586. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17587. {
  17588. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17589. {
  17590. tempIndex = ((gun_index==2) ? 1: 0);
  17591. }
  17592. else
  17593. {
  17594. tempIndex = gun_index;
  17595. }
  17596. for (int index = 0; index < CCS_QUANTITY; index++)
  17597. {
  17598. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17599. {
  17600. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17601. }
  17602. }// END OF CCS_QUANTITY
  17603. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17604. }
  17605. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17606. {
  17607. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17608. {
  17609. tempIndex = ((gun_index==2) ? 1: 0);
  17610. }
  17611. else
  17612. {
  17613. tempIndex = gun_index;
  17614. }
  17615. for (int index = 0; index < GB_QUANTITY; index++)
  17616. {
  17617. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17618. {
  17619. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17620. }
  17621. }// END OF GB_QUANTITY
  17622. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17623. }
  17624. else if(gunType[gun_index] == GUN_TYPE_DO)
  17625. {
  17626. tempIndex = gun_index;
  17627. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17628. {
  17629. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17630. {
  17631. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17632. }
  17633. }
  17634. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17635. }
  17636. else
  17637. {
  17638. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17639. {
  17640. tempIndex = 2;
  17641. }
  17642. else
  17643. {
  17644. tempIndex = gun_index;
  17645. }
  17646. for (int index = 0; index < AC_QUANTITY; index++)
  17647. {
  17648. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17649. {
  17650. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17651. }
  17652. }// END OF AC_QUANTITY
  17653. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17654. }
  17655. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17656. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17657. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17658. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17659. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17660. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17661. }
  17662. //2.3====================================== Power.Active.Import =========================================
  17663. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17664. {
  17665. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17666. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17667. {
  17668. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17669. {
  17670. tempIndex = ((gun_index==2) ? 1: 0);
  17671. }
  17672. else
  17673. {
  17674. tempIndex = gun_index;
  17675. }
  17676. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17677. {
  17678. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17679. {
  17680. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17681. }
  17682. } // End for CHAdeMO_QUANTITY
  17683. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17684. }
  17685. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17686. {
  17687. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17688. {
  17689. tempIndex = ((gun_index==2) ? 1: 0);
  17690. }
  17691. else
  17692. {
  17693. tempIndex = gun_index;
  17694. }
  17695. for (int index = 0; index < CCS_QUANTITY; index++)
  17696. {
  17697. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17698. {
  17699. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17700. }
  17701. } // END for CCS_QUANTITY
  17702. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17703. }
  17704. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17705. {
  17706. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17707. {
  17708. tempIndex = ((gun_index==2) ? 1: 0);
  17709. }
  17710. else
  17711. {
  17712. tempIndex = gun_index;
  17713. }
  17714. for (int index = 0; index < GB_QUANTITY; index++)
  17715. {
  17716. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17717. {
  17718. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17719. }
  17720. }// END for GB_QUANTITY
  17721. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17722. }
  17723. else if(gunType[gun_index] == GUN_TYPE_DO)
  17724. {
  17725. tempIndex = gun_index;
  17726. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17727. {
  17728. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17729. {
  17730. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17731. }
  17732. }
  17733. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17734. }
  17735. else
  17736. {
  17737. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17738. {
  17739. tempIndex = 2;
  17740. }
  17741. else
  17742. {
  17743. tempIndex = gun_index;
  17744. }
  17745. for (int index = 0; index < AC_QUANTITY; index++)
  17746. {
  17747. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17748. {
  17749. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17750. }
  17751. } // END for AC_QUANTITY
  17752. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17753. }
  17754. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17755. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17756. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17757. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17758. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17759. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17760. }
  17761. //2.4====================================== Voltage L1 ====================================================
  17762. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17763. {
  17764. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17765. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17766. {
  17767. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17768. {
  17769. tempIndex = ((gun_index==2) ? 1: 0);
  17770. }
  17771. else
  17772. {
  17773. tempIndex = gun_index;
  17774. }
  17775. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17776. {
  17777. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17778. {
  17779. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17780. }
  17781. } // END OF FOR CHAdeMO_QUANTITY
  17782. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17783. }
  17784. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17785. {
  17786. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17787. {
  17788. tempIndex = ((gun_index==2) ? 1: 0);
  17789. }
  17790. else
  17791. {
  17792. tempIndex = gun_index;
  17793. }
  17794. for (int index = 0; index < CCS_QUANTITY; index++)
  17795. {
  17796. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17797. {
  17798. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17799. }
  17800. } // END OF FOR CCS_QUANTITY
  17801. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17802. }
  17803. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17804. {
  17805. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17806. {
  17807. tempIndex = ((gun_index==2) ? 1: 0);
  17808. }
  17809. else
  17810. {
  17811. tempIndex = gun_index;
  17812. }
  17813. for (int index = 0; index < GB_QUANTITY; index++)
  17814. {
  17815. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17816. {
  17817. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17818. }
  17819. } // END OF FOR GB_QUANTITY
  17820. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17821. }
  17822. else if(gunType[gun_index] == GUN_TYPE_DO)
  17823. {
  17824. tempIndex = gun_index;
  17825. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17826. {
  17827. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17828. {
  17829. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17830. }
  17831. }
  17832. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17833. }
  17834. else
  17835. {
  17836. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17837. {
  17838. tempIndex = 2;
  17839. }
  17840. else
  17841. {
  17842. tempIndex = gun_index;
  17843. }
  17844. for (int index = 0; index < AC_QUANTITY; index++)
  17845. {
  17846. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17847. {
  17848. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  17849. }
  17850. } // END OF FOR AC_QUANTITY
  17851. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17852. }
  17853. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17854. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17855. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17856. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17857. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17858. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17859. }
  17860. //2.5============================================== End SoC =========================================================
  17861. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17862. {
  17863. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17864. 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))
  17865. {
  17866. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17867. {
  17868. tempIndex = ((gun_index==2) ? 1: 0);
  17869. }
  17870. else
  17871. {
  17872. tempIndex = gun_index;
  17873. }
  17874. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17875. {
  17876. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17877. {
  17878. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17879. {
  17880. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17881. }
  17882. }
  17883. }
  17884. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17885. {
  17886. for (int index = 0; index < CCS_QUANTITY; index++)
  17887. {
  17888. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17889. {
  17890. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17891. }
  17892. }
  17893. }
  17894. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17895. {
  17896. for (int index = 0; index < GB_QUANTITY; index++)
  17897. {
  17898. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17899. {
  17900. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17901. }
  17902. }
  17903. }
  17904. else if(gunType[gun_index] == GUN_TYPE_DO)
  17905. {
  17906. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17907. {
  17908. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17909. {
  17910. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17911. }
  17912. }
  17913. }
  17914. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17915. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17916. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17917. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17918. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17919. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17920. } // END FOR DC CASE
  17921. }
  17922. //2.6====================================== Current.Import L2 ==============================================
  17923. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17924. {
  17925. // AC 3 phase L2 current
  17926. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17927. {
  17928. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17929. {
  17930. tempIndex = 2;
  17931. }
  17932. else
  17933. {
  17934. tempIndex = gun_index;
  17935. }
  17936. for (int index = 0; index < AC_QUANTITY; index++)
  17937. {
  17938. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17939. {
  17940. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17941. }
  17942. }// End of for AC_QUANTITY
  17943. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17944. }
  17945. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17946. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17947. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17948. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17949. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17950. }
  17951. //2.7====================================== Current.Import L3 ==============================================
  17952. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17953. {
  17954. // AC 3 phase L3 current
  17955. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17956. {
  17957. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17958. {
  17959. tempIndex = 2;
  17960. }
  17961. else
  17962. {
  17963. tempIndex = gun_index;
  17964. }
  17965. for (int index = 0; index < AC_QUANTITY; index++)
  17966. {
  17967. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17968. {
  17969. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  17970. }
  17971. }// End of for AC_QUANTITY
  17972. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  17973. }
  17974. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17975. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  17976. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  17977. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  17978. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17979. }
  17980. //2.9====================================== Voltage L2 ====================================================
  17981. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17982. {
  17983. // AC 3 phase L2 volatge
  17984. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17985. {
  17986. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17987. {
  17988. tempIndex = 2;
  17989. }
  17990. else
  17991. {
  17992. tempIndex = gun_index;
  17993. }
  17994. for (int index = 0; index < AC_QUANTITY; index++)
  17995. {
  17996. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17997. {
  17998. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  17999. }
  18000. } // END OF FOR AC_QUANTITY
  18001. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  18002. }
  18003. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18004. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  18005. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  18006. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  18007. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18008. }
  18009. //2.10====================================== Voltage L3 ====================================================
  18010. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18011. {
  18012. // AC 3 phase L3 volatge
  18013. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18014. {
  18015. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18016. {
  18017. tempIndex = 2;
  18018. }
  18019. else
  18020. {
  18021. tempIndex = gun_index;
  18022. }
  18023. for (int index = 0; index < AC_QUANTITY; index++)
  18024. {
  18025. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18026. {
  18027. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  18028. }
  18029. } // END OF FOR AC_QUANTITY
  18030. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  18031. }
  18032. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18033. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  18034. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  18035. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  18036. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18037. }
  18038. //====================== Start SoC ================================
  18039. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18040. {
  18041. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18042. 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))
  18043. {
  18044. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18045. {
  18046. tempIndex = ((gun_index==2) ? 1: 0);
  18047. }
  18048. else
  18049. {
  18050. tempIndex = gun_index;
  18051. }
  18052. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18053. {
  18054. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18055. {
  18056. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18057. {
  18058. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  18059. }
  18060. }
  18061. }
  18062. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18063. {
  18064. for (int index = 0; index < CCS_QUANTITY; index++)
  18065. {
  18066. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18067. {
  18068. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  18069. }
  18070. }
  18071. }
  18072. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18073. {
  18074. for (int index = 0; index < GB_QUANTITY; index++)
  18075. {
  18076. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18077. {
  18078. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  18079. }
  18080. }
  18081. }
  18082. else if(gunType[gun_index] == GUN_TYPE_DO)
  18083. {
  18084. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18085. {
  18086. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18087. {
  18088. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  18089. }
  18090. }
  18091. }
  18092. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18093. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  18094. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18095. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  18096. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  18097. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18098. } // END FOR DC CASE
  18099. }
  18100. //======================================== Message create ==============================================
  18101. json_object *StopTransaction = json_object_new_object();
  18102. json_object *transactionDatas = json_object_new_array();
  18103. json_object *sampledValues = json_object_new_array();
  18104. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  18105. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  18106. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  18107. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  18108. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  18109. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  18110. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  18111. {
  18112. json_object *transactionData = json_object_new_object();
  18113. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  18114. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  18115. {
  18116. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  18117. {
  18118. json_object *sampledValue = json_object_new_object();
  18119. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  18120. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  18121. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  18122. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  18123. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  18124. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  18125. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  18126. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  18127. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  18128. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  18129. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  18130. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  18131. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  18132. json_object_array_add(sampledValues, sampledValue);
  18133. }
  18134. }
  18135. json_object_object_add(transactionData, "sampledValue", sampledValues);
  18136. json_object_array_add(transactionDatas, transactionData);
  18137. }
  18138. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  18139. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  18140. ,MESSAGE_TYPE_CALL
  18141. ,guid
  18142. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  18143. json_object_put(StopTransaction);
  18144. // Check File "TempStopTransaction" Exist
  18145. if((access(TempStopTransaction,F_OK))!=-1)
  18146. {
  18147. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  18148. fclose(fopen(TempStopTransaction, "w"));
  18149. }
  18150. else
  18151. {
  18152. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  18153. FILE *log = fopen(TempStopTransaction, "w+");
  18154. if(log == NULL)
  18155. {
  18156. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  18157. return ;
  18158. }
  18159. else
  18160. {
  18161. fclose(log);
  18162. }
  18163. }
  18164. //Add TempStopTransaction | Update TempStopTransaction
  18165. // open file for writing
  18166. FILE *outfile;
  18167. outfile = fopen (TempStopTransaction, "a");
  18168. //DEBUG_INFO("data = %s\n", queuedata);
  18169. fputs(queuedata, outfile);
  18170. fputs("\n", outfile);
  18171. fclose (outfile);
  18172. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18173. }
  18174. void checkTempStopTransaction(int gun_index)
  18175. {
  18176. FILE *fptr1;
  18177. char ch;
  18178. char str[QUEUE_MESSAGE_LENGTH]={0};
  18179. char guid[37]={0};
  18180. char tempdata[65]={0};
  18181. char connectorStr[2]={0};
  18182. char TempStopTransaction[256];
  18183. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  18184. fptr1 = fopen(TempStopTransaction, "r");
  18185. //TempStopTransaction格式: 槍號,StopTransaction封包
  18186. if (!fptr1)
  18187. {
  18188. //printf(" File not found or unable to open the input file!!\n");
  18189. return ;
  18190. }
  18191. ch=fgetc(fptr1);
  18192. //printf(" Now the content of the file %s is : \n",fname);
  18193. rewind(fptr1);
  18194. if(ch!=EOF)
  18195. {
  18196. // copy all contents to the temporary file except the specific line
  18197. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18198. {
  18199. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18200. if(str[0]=='\0')
  18201. {
  18202. break;
  18203. }
  18204. //TempStopTransaction格式: 槍號,StopTransaction封包
  18205. strncpy(connectorStr, str, 1);
  18206. if(atoi(connectorStr) != (gun_index+1))
  18207. {
  18208. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18209. fclose(fptr1);
  18210. return ;
  18211. }
  18212. //random_uuid(guid);
  18213. strncpy(guid, str+6, 36); //copy guid
  18214. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18215. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18216. {
  18217. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18218. }
  18219. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18220. OCPP_insert_transaction_msg(NO, str);
  18221. memset(str,0,ARRAY_SIZE(str));
  18222. }
  18223. }
  18224. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18225. fclose(fptr1);
  18226. remove(TempStopTransaction); // remove the original file
  18227. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18228. }
  18229. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18230. {
  18231. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18232. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18233. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18234. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18235. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18236. }
  18237. int GetWebSocketPingInterval(void)
  18238. {
  18239. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18240. }
  18241. int GetServerSign(void)
  18242. {
  18243. return server_sign;
  18244. }
  18245. uint8_t GetOcppSecurityProfile()
  18246. {
  18247. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18248. }
  18249. void GetOcppChargerBoxId(uint8_t *data)
  18250. {
  18251. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  18252. }
  18253. void GetOcppSecurityPassword(uint8_t *data)
  18254. {
  18255. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18256. }
  18257. void SetOcppVersion(uint8_t *version)
  18258. {
  18259. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18260. DEBUG_INFO("ocpp version: %s\n", version);
  18261. if(strstr((char*)version, "ocpp1.6") != NULL)
  18262. {
  18263. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18264. }
  18265. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18266. {
  18267. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18268. system("pkill OcppBackend");
  18269. }
  18270. }
  18271. void SetServerSign(int value)
  18272. {
  18273. server_sign = value;
  18274. }
  18275. int GetBootNotificationInterval(void)
  18276. {
  18277. return BootNotificationInterval;
  18278. }
  18279. int GetInternetConn(void)
  18280. {
  18281. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18282. }
  18283. int GetBackendConnectionTimeout(void)
  18284. {
  18285. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18286. }
  18287. int isConnectorInitMode(int gun_index)
  18288. {
  18289. int tempIndex = 0;
  18290. int result = TRUE;
  18291. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18292. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18293. {
  18294. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18295. {
  18296. tempIndex = ((gun_index==2) ? 1: 0);
  18297. }
  18298. else
  18299. {
  18300. tempIndex = gun_index;
  18301. }
  18302. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18303. {
  18304. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18305. {
  18306. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18307. } //end of the same index
  18308. }//end of for CHAdeMO_QUANTITY
  18309. }
  18310. else if(gunType[gun_index] == GUN_TYPE_CCS)
  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 < CCS_QUANTITY; index++)
  18321. {
  18322. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18323. {
  18324. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18325. } //end of the same index
  18326. } // end of for CCS_QUANTITY
  18327. }
  18328. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18329. {
  18330. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18331. {
  18332. tempIndex = ((gun_index==2) ? 1: 0);
  18333. }
  18334. else
  18335. {
  18336. tempIndex = gun_index;
  18337. }
  18338. for (int index = 0; index < GB_QUANTITY; index++)
  18339. {
  18340. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18341. {
  18342. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18343. } //end of the same index
  18344. } // end of for GB_QUANTITY
  18345. }
  18346. else if(gunType[gun_index] == GUN_TYPE_DO)
  18347. {
  18348. tempIndex = gun_index;
  18349. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18350. {
  18351. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18352. {
  18353. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18354. } //end of the same index
  18355. }
  18356. }
  18357. else
  18358. {
  18359. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18360. {
  18361. tempIndex = 2;
  18362. }
  18363. else
  18364. {
  18365. tempIndex = gun_index;
  18366. }
  18367. for (int index = 0; index < AC_QUANTITY; index++)
  18368. {
  18369. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18370. {
  18371. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18372. }//end of the same index
  18373. }//end of for AC_QUANTITY
  18374. }
  18375. return result;
  18376. }
  18377. void refreshProcDogTimer()
  18378. {
  18379. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  18380. }
  18381. void InitialSystemValue(void)
  18382. {
  18383. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  18384. locallistVersion=0;
  18385. BootNotificationInterval = 0;
  18386. authorizeRetryTimes = 0;
  18387. GunStatusInterval = 10;
  18388. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18389. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18390. //Hear Beat
  18391. HeartBeatWithNOResponse = 0;
  18392. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18393. FirstHeartBeat = 0;
  18394. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18395. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18396. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18397. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18398. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18399. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18400. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18401. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18402. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18403. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18404. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18405. //Status && ConnectorPlugIn Setting
  18406. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18407. {
  18408. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18409. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18410. }
  18411. for (int index = 0; index < CCS_QUANTITY; index++)
  18412. {
  18413. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18414. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18415. }
  18416. for (int index = 0; index < GB_QUANTITY; index++)
  18417. {
  18418. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18419. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18420. }
  18421. for (int index = 0; index < AC_QUANTITY; index++)
  18422. {
  18423. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18424. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18425. }
  18426. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18427. {
  18428. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18429. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18430. }
  18431. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18432. {
  18433. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18434. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18435. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18436. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18437. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18438. }
  18439. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18440. refreshStartTimer(&clientTime.Heartbeat);
  18441. sleep(1);
  18442. }
  18443. void LWS_Send(char *str)
  18444. {
  18445. //=====================================================
  18446. // Check InternetConn 0: disconnected, 1: connected
  18447. //====================================================
  18448. if(GetOcppConnStatus() == 0)
  18449. {
  18450. DEBUG_INFO("offline now !!!\n");
  18451. return;
  18452. }
  18453. // Only disable isWebsocketSendable operation initiated by charger
  18454. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18455. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18456. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18457. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18458. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18459. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18460. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18461. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18462. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18463. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18464. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18465. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18466. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18467. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18468. {
  18469. isWebsocketSendable = 0;
  18470. }
  18471. pthread_mutex_lock(&lock_send);
  18472. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18473. sprintf((char *)SendBuffer, "%s", str);
  18474. SendBufLen = strlen(str);
  18475. pthread_mutex_unlock(&lock_send);
  18476. lws_callback_on_writable(wsi_client);
  18477. //lws_service(context, 0);
  18478. //sleep(1);
  18479. }
  18480. void LWS_SendNow(char *str)
  18481. {
  18482. //=====================================================
  18483. // Check InternetConn 0: disconnected, 1: connected
  18484. //====================================================
  18485. if(GetOcppConnStatus() == 0)
  18486. {
  18487. DEBUG_INFO("offline now !!!\n");
  18488. return;
  18489. }
  18490. // Only disable isWebsocketSendable operation initiated by charger
  18491. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18492. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18493. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18494. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18495. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18496. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18497. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18498. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18499. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18500. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18501. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18502. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18503. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18504. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18505. {
  18506. isWebsocketSendable = 0;
  18507. }
  18508. pthread_mutex_lock(&lock_send);
  18509. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18510. sprintf((char *)SendBuffer, "%s", str);
  18511. SendBufLen = strlen(str);
  18512. pthread_mutex_unlock(&lock_send);
  18513. lws_callback_on_writable(wsi_client);
  18514. lws_service(context, 0);
  18515. //sleep(1);
  18516. }