MessageHandler.c 957 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726
  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. //===============================
  43. // OCPP auth variable
  44. //===============================
  45. static int authorizeRetryTimes = 0; //number of Retry times
  46. //===============================
  47. // OCPP other variables
  48. //===============================
  49. static int HeartBeatWaitTime = 10;
  50. static int FirstHeartBeat = 0;
  51. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  52. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  53. static char CurrentChargingProfileScheduleStr[30] = {0};
  54. static float periousPeriodicPowerConsumption[CONNECTOR_QUANTITY] = {0};
  55. static float periousClockPowerConsumption[CONNECTOR_QUANTITY] = {0};
  56. //========================================
  57. // OCPP status/previous related variables
  58. //========================================
  59. static int GunStatusInterval = 10;
  60. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  61. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  62. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  63. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  64. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  65. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  66. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  67. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  68. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  69. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  70. static int TransactionMessageAttemptsValue = 0;
  71. static int TransactionMessageRetryIntervalValue = 0;
  72. static int TempMeterValueInterval = 0;
  73. static struct OCPPAuthLocalElemet
  74. {
  75. int listVersionInt;
  76. char idTagstr[21];
  77. char parentIdTag[21];
  78. char expiryDate[36];
  79. char idTagstatus[16];
  80. }idTagQuery;
  81. //============================================
  82. // OCPP MeterValue request flag
  83. //============================================
  84. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  85. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  86. //============================================
  87. // OCPP HeartBeat Response Not Receive Counts
  88. //============================================
  89. static int HeartBeatWithNOResponse = 0;
  90. //============================================
  91. // OCPP California Pricing Requirements
  92. //============================================
  93. static char dmsVersion[21] = {0};
  94. extern sqlite3 *db;
  95. int TransactionMessageAttemptsGet(void);
  96. int TransactionMessageRetryIntervalGet(void);
  97. int GetOcppConnStatus(void);
  98. void SetOcppConnStatus(uint8_t status);
  99. int setKeyValue(char *key, char *value);
  100. void OCPP_get_TableAuthlocalAllData(void);
  101. void processUnkownKey(void);
  102. struct InterLock
  103. {
  104. unsigned char isSentUnplug[CONNECTOR_QUANTITY];
  105. unsigned char isGetDiagnosticGoing:1;
  106. unsigned char isUpdateFirmwareGoing:1;
  107. }interLock;
  108. struct ClientTime
  109. {
  110. struct timespec Heartbeat;
  111. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  112. struct timespec StartTransaction;
  113. struct timespec StopTransaction;
  114. struct timespec MeterValues[CONNECTOR_QUANTITY];
  115. struct timespec RemoteStartWait;
  116. struct timespec TcciQueryDeduct;
  117. }clientTime;
  118. typedef union
  119. {
  120. //Operations Initiated by Central System
  121. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  122. struct
  123. {
  124. //CsMsgValue[0]
  125. unsigned char StatusNotificationReq:1; //bit 0,
  126. unsigned char StatusNotificationConf:1; //bit 1,
  127. unsigned char TriggerMeterValue:1; //bit 2,
  128. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  129. unsigned char isOnCharging:1; //bit 4.
  130. unsigned char :3; //bit 5~7
  131. }bits[CONNECTOR_QUANTITY];
  132. }CpinitiateMsg;
  133. CpinitiateMsg cpinitateMsg;
  134. //GetConfiguration Array
  135. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  136. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  137. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  138. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  139. static char *ChargePointErrorCodeStr[] = {
  140. MACROSTR(ConnectorLockFailure),
  141. MACROSTR(EVCommunicationError),
  142. MACROSTR(GroundFailure),
  143. MACROSTR(HighTemperature),
  144. MACROSTR(InternalError),
  145. MACROSTR(LocalListConflict),
  146. MACROSTR(NoError),
  147. MACROSTR(OtherError),
  148. MACROSTR(OverCurrentFailure),
  149. MACROSTR(OverVoltage),
  150. MACROSTR(PowerMeterFailure),
  151. MACROSTR(PowerSwitchFailure),
  152. MACROSTR(ReaderFailure),
  153. MACROSTR(ResetFailure),
  154. MACROSTR(UnderVoltage),
  155. MACROSTR(WeakSignal)
  156. };
  157. static char * ChargePointStatusStr[] = {
  158. MACROSTR(Available),
  159. MACROSTR(Preparing),
  160. MACROSTR(Charging),
  161. MACROSTR(SuspendedEVSE),
  162. MACROSTR(SuspendedEV),
  163. MACROSTR(Finishing),
  164. MACROSTR(Reserved),
  165. MACROSTR(Unavailable),
  166. MACROSTR(Faulted)
  167. };
  168. static char *RegistrationStatusStr[] = {
  169. MACROSTR(Accepted),
  170. MACROSTR(Pending),
  171. MACROSTR(Rejected)
  172. };
  173. static char *AvailabilityTypeStr[] = {
  174. MACROSTR(Inoperative),
  175. MACROSTR(Operative)
  176. };
  177. static char *AvailabilityStatusStr[] = {
  178. MACROSTR(Accepted),
  179. MACROSTR(Rejected),
  180. MACROSTR(Scheduled)
  181. };
  182. static char *ConfigurationStatusStr[] = {
  183. MACROSTR(Accepted),
  184. MACROSTR(Rejected),
  185. MACROSTR(RebootRequired),
  186. MACROSTR(NotSupported)
  187. };
  188. static char *ClearCacheStatusStr[] = {
  189. MACROSTR(Accepted),
  190. MACROSTR(Rejected)
  191. };
  192. static char *ChargingProfilePurposeTypeStr[] = {
  193. MACROSTR(ChargePointMaxProfile),
  194. MACROSTR(TxDefaultProfile),
  195. MACROSTR(TxProfile)
  196. };
  197. static char *ChargingProfileStatusStr[] = {
  198. MACROSTR(Accepted),
  199. MACROSTR(Rejected),
  200. MACROSTR(NotSupported)
  201. };
  202. static char *ClearChargingProfileStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Unknown)
  205. };
  206. static char *GetCompositeScheduleStatusStr[] = {
  207. MACROSTR(Accepted),
  208. MACROSTR(Rejected)
  209. };
  210. static char *UpdateTypeStr[] = {
  211. MACROSTR(Differential),
  212. MACROSTR(Full)
  213. };
  214. static char *UpdateStatusStr[] = {
  215. MACROSTR(Accepted),
  216. MACROSTR(Failed),
  217. MACROSTR(NotSupported),
  218. MACROSTR(VersionMismatch)
  219. };
  220. static char *RemoteStartStopStatusStr[] = {
  221. MACROSTR(Accepted),
  222. MACROSTR(Rejected)
  223. };
  224. static char *ReservationStatusStr[] = {
  225. MACROSTR(Accepted),
  226. MACROSTR(Faulted),
  227. MACROSTR(Occupied),
  228. MACROSTR(Rejected),
  229. MACROSTR(Unavailable)
  230. };
  231. static char *ResetTypeStr[] = {
  232. MACROSTR(Hard),
  233. MACROSTR(Soft)
  234. };
  235. static char *ResetStatusStr[] = {
  236. MACROSTR(Accepted),
  237. MACROSTR(Rejected)
  238. };
  239. static char * DiagnosticsStatusStr[] = {
  240. MACROSTR(Idle),
  241. MACROSTR(Uploaded),
  242. MACROSTR(UploadFailed),
  243. MACROSTR(Uploading)
  244. };
  245. static char * FirmwareStatusStr[] = {
  246. MACROSTR(Downloaded),
  247. MACROSTR(DownloadFailed),
  248. MACROSTR(Downloading),
  249. MACROSTR(Idle),
  250. MACROSTR(InstallationFailed),
  251. MACROSTR(Installing),
  252. MACROSTR(Installed)
  253. };
  254. static char * MessageTriggerStr[] = {
  255. MACROSTR(BootNotification),
  256. MACROSTR(DiagnosticsStatusNotification),
  257. MACROSTR(FirmwareStatusNotification),
  258. MACROSTR(Heartbeat),
  259. MACROSTR(MeterValues),
  260. MACROSTR(StatusNotification)
  261. };
  262. static char * TriggerMessageStatusStr[] = {
  263. MACROSTR(Accepted),
  264. MACROSTR(Rejected),
  265. MACROSTR(NotImplemented)
  266. };
  267. static char * UnlockStatusStr[] = {
  268. MACROSTR(Unlocked),
  269. MACROSTR(UnlockFailed),
  270. MACROSTR(NotSupported)
  271. };
  272. #if 0
  273. static char * StopTransactionReasonStr[] = {
  274. MACROSTR(EmergencyStop),
  275. MACROSTR(EVDisconnected),
  276. MACROSTR(HardReset),
  277. MACROSTR(Local),
  278. MACROSTR(Other),
  279. MACROSTR(PowerLoss),
  280. MACROSTR(Reboot),
  281. MACROSTR(Remote),
  282. MACROSTR(SoftReset),
  283. MACROSTR(UnlockCommand),
  284. MACROSTR(DeAuthorized)
  285. };
  286. #endif
  287. static char * CancelReservationStatusStr[] = {
  288. MACROSTR(Accepted),
  289. MACROSTR(Rejected)
  290. };
  291. static char * ReadingContextStr[] = {
  292. MACROSTR(Interruption.Begin),
  293. MACROSTR(Interruption.End),
  294. MACROSTR(Other),
  295. MACROSTR(Sample.Clock),
  296. MACROSTR(Sample.Periodic),
  297. MACROSTR(Transaction.Begin),
  298. MACROSTR(Transaction.End),
  299. MACROSTR(Trigger)
  300. };
  301. static char * ValueFormatStr[] = {
  302. MACROSTR(Raw),
  303. MACROSTR(SignedData)
  304. };
  305. static char * MeasurandStr[] = {
  306. MACROSTR(Current.Export),
  307. MACROSTR(Current.Import),
  308. MACROSTR(Current.Offered),
  309. MACROSTR(Energy.Active.Export.Register),
  310. MACROSTR(Energy.Active.Import.Register),
  311. MACROSTR(Energy.Reactive.Export.Register),
  312. MACROSTR(Energy.Reactive.Import.Register),
  313. MACROSTR(Energy.Active.Export.Interval),
  314. MACROSTR(Energy.Active.Import.Interval),
  315. MACROSTR(Energy.Reactive.Export.Interval),
  316. MACROSTR(Energy.Reactive.Import.Interval),
  317. MACROSTR(Frequency),
  318. MACROSTR(Power.Active.Export),
  319. MACROSTR(Power.Active.Import),
  320. MACROSTR(Power.Factor),
  321. MACROSTR(Power.Offered),
  322. MACROSTR(Power.Reactive.ExportMACROSTR),
  323. MACROSTR(Power.Reactive.Import),
  324. MACROSTR(RPM),
  325. MACROSTR(SoC),
  326. MACROSTR(Temperature),
  327. MACROSTR(Voltage)
  328. };
  329. static char * LocationStr[] = {
  330. MACROSTR(Body),
  331. MACROSTR(Cable),
  332. MACROSTR(EV),
  333. MACROSTR(Inlet),
  334. MACROSTR(Outlet)
  335. };
  336. static char * PhaseStr[] = {
  337. MACROSTR(L1),
  338. MACROSTR(L2),
  339. MACROSTR(L3),
  340. MACROSTR(N),
  341. MACROSTR(L1-N),
  342. MACROSTR(L2-N),
  343. MACROSTR(L3-N),
  344. MACROSTR(L1-L2),
  345. MACROSTR(L2-L3),
  346. MACROSTR(L3-L1)
  347. };
  348. static char * UnitOfMeasureStr[] = {
  349. MACROSTR(Wh),
  350. MACROSTR(kWh),
  351. MACROSTR(varh),
  352. MACROSTR(kvarh),
  353. MACROSTR(W),
  354. MACROSTR(kW),
  355. MACROSTR(VA),
  356. MACROSTR(kVA),
  357. MACROSTR(var),
  358. MACROSTR(kvar),
  359. MACROSTR(A),
  360. MACROSTR(V),
  361. MACROSTR(Celsius),
  362. MACROSTR(Fahrenheit),
  363. MACROSTR(K),
  364. MACROSTR(Percent)
  365. };
  366. //=========================================
  367. // Save configuration
  368. //=========================================
  369. int runShellCmd(const char*cmd)
  370. {
  371. int result = FAIL;
  372. char buf[256];
  373. FILE *fp;
  374. fp = popen(cmd, "r");
  375. if(fp != NULL)
  376. {
  377. while(fgets(buf, sizeof(buf), fp) != NULL)
  378. {
  379. DEBUG_INFO("%s\n", buf);
  380. }
  381. result = PASS;
  382. }
  383. pclose(fp);
  384. return result;
  385. }
  386. int StoreUsrConfigData(struct SysConfigData *UsrData)
  387. {
  388. int result = PASS;
  389. int fd,wrd;
  390. unsigned int i,Chk;
  391. unsigned char *ptr, *BufTmp;
  392. int MtdBlockSize = 0x300000;
  393. Chk=0;
  394. ptr=(unsigned char *)UsrData;
  395. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  396. {
  397. memset(BufTmp,0,MtdBlockSize);
  398. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  399. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  400. Chk+=*(BufTmp+i);
  401. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  402. // Output configuration to file.
  403. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  404. if (fd < 0)
  405. {
  406. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  407. free(BufTmp);
  408. return 0;
  409. }
  410. wrd=write(fd, BufTmp, MtdBlockSize);
  411. close(fd);
  412. if(wrd<MtdBlockSize)
  413. {
  414. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  415. free(BufTmp);
  416. return 0;
  417. }
  418. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  419. DEBUG_INFO("Erase /dev/mtd10.\n");
  420. runShellCmd("flash_erase /dev/mtd10 0 0");
  421. DEBUG_INFO("Write /dev/mtd10.\n");
  422. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  423. DEBUG_INFO("Erase /dev/mtd11.\n");
  424. runShellCmd("flash_erase /dev/mtd11 0 0");
  425. DEBUG_INFO("Write /dev/mtd11.\n");
  426. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  427. system("rm -f /mnt/EvseConfig.bin");
  428. DEBUG_INFO("EvseConfig write to flash OK\n");
  429. }
  430. else
  431. {
  432. DEBUG_ERROR("alloc BlockSize NG\r\n");
  433. result = FAIL;
  434. }
  435. if(BufTmp!=NULL)
  436. free(BufTmp);
  437. return result;
  438. }
  439. //=========================================
  440. // Sqlite3 related function
  441. //=========================================
  442. static int selectSqlCount = 0;
  443. static int callback(void *data, int argc, char **argv, char **azColName){
  444. int i;
  445. //printf("%s: ", (const char*)data);
  446. selectSqlCount = argc;
  447. for(i = 0; i<argc; i++){
  448. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  449. }
  450. //printf("\n");
  451. return 0;
  452. }
  453. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  454. //int i;
  455. //printf("%s:\n", (const char*)data);
  456. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  457. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  458. return 0;
  459. }
  460. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  461. //printf("%s:\n", (const char*)data);
  462. //idTag
  463. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  464. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  465. //parentIdTag
  466. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  467. //expir_date
  468. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  469. //status
  470. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  471. //version
  472. if(columenCount > 5)
  473. idTagQuery.listVersionInt = atoi(columnValue[5]);
  474. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  475. return 0;
  476. }
  477. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  478. {
  479. // localversion = argv[5] ? atoi(argv[5]) : 0;
  480. // printf("localversion=%d\n", localversion);
  481. return 0;
  482. }
  483. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  484. {
  485. for (int i = 0; i < n_columns; i++)
  486. {
  487. DEBUG_INFO("%s\t", col_values[i]);
  488. }
  489. DEBUG_INFO("\n");
  490. return 0;
  491. }
  492. int OCPP_cleanLocalCache()
  493. {
  494. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  495. char *errMsg = 0;
  496. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  497. if (SQLITE_OK != rc)
  498. {
  499. DEBUG_INFO("SQL error: %s\n",errMsg);
  500. return FALSE;
  501. }
  502. return TRUE;
  503. }
  504. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  505. {
  506. int isSuccess = TRUE;
  507. int ret = 0;
  508. //const char* data = "Callback function called";
  509. char sql[300];
  510. char zErrMsg[200];
  511. memset(sql, 0, 300);
  512. memset(zErrMsg, 0, 200);
  513. 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);
  514. //* Execute SQL statement */
  515. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  516. if( ret != SQLITE_OK )
  517. {
  518. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  519. isSuccess = FALSE;
  520. }
  521. return isSuccess;
  522. }
  523. void OCPP_getIdTagFromLocalCache(char idTag[])
  524. {
  525. int rc = 0;
  526. char sql[100];
  527. char zErrMsg[100];
  528. memset(sql, 0, 100);
  529. memset(zErrMsg, 0, 100);
  530. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  531. memset(&idTagQuery, 0, sizeof(idTagQuery));
  532. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  533. /* Execute SQL statement */
  534. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  535. if( rc != SQLITE_OK )
  536. {
  537. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  538. }
  539. }
  540. void OCPP_getListVerion()
  541. {
  542. int rc = 0;
  543. // const char* data = "Callback function called";
  544. char sql[100];
  545. char zErrMsg[100];
  546. memset(sql, 0, 100);
  547. memset(zErrMsg, 0, 100);
  548. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  549. /* Execute SQL statement */
  550. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  551. if( rc != SQLITE_OK )
  552. {
  553. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  554. }
  555. }
  556. void OCPP_get_TableAuthlocalAllData(void)
  557. {
  558. int rc = 0;
  559. char sql[100];
  560. char zErrMsg[100];
  561. memset(sql, 0, 100);
  562. memset(zErrMsg, 0, 100);
  563. sprintf(sql,"select * from ocpp_auth_local ");
  564. /* Execute SQL statement */
  565. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  566. if( rc != SQLITE_OK )
  567. {
  568. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  569. }
  570. //return ver;
  571. }
  572. int OCPP_cleanLocalList()
  573. {
  574. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  575. char *errMsg = 0;
  576. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  577. if (SQLITE_OK != rc)
  578. {
  579. DEBUG_INFO("%s\n",errMsg);
  580. return FALSE;
  581. }
  582. return TRUE;
  583. }
  584. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  585. {
  586. int isSuccess = FALSE;
  587. int ret = 0;
  588. //const char* data = "Callback function called";
  589. char sql[300];
  590. char zErrMsg[200];
  591. memset(sql, 0, 300);
  592. memset(zErrMsg, 0, 200);
  593. 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);
  594. //* Execute SQL statement */
  595. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  596. if( ret != SQLITE_OK )
  597. {
  598. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  599. return isSuccess;
  600. }
  601. memset(sql, 0, 300);
  602. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  603. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  604. if( ret != SQLITE_OK )
  605. {
  606. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  607. return isSuccess;
  608. }
  609. isSuccess = TRUE;
  610. return isSuccess;
  611. }
  612. void OCPP_getIdTagFromLocalList(char idTag[])
  613. {
  614. int rc = 0;
  615. // const char* data = "Callback function called";
  616. char sql[100];
  617. char zErrMsg[100];
  618. memset(sql, 0, 100);
  619. memset(zErrMsg, 0, 100);
  620. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  621. memset(&idTagQuery, 0, sizeof(idTagQuery));
  622. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  623. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  624. /* Execute SQL statement */
  625. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  626. if( rc != SQLITE_OK )
  627. {
  628. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  629. }
  630. //return ver;
  631. }
  632. void OCPP_deleteIdTagFromLocalList(char idTag[])
  633. {
  634. //int ver = 0;
  635. //int isSuccess = FALSE;
  636. int rc = 0;
  637. char sql[100];
  638. char zErrMsg[100];
  639. memset(sql, 0, 100);
  640. memset(zErrMsg, 0, 100);
  641. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  642. //* Execute SQL statement */
  643. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  644. if( rc != SQLITE_OK )
  645. {
  646. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  647. }
  648. }
  649. int getCurrentYear()
  650. {
  651. int result = 0;
  652. time_t CurrentTime;
  653. struct tm *tm;
  654. CurrentTime = time(NULL);
  655. tm=localtime(&CurrentTime);
  656. result = (tm->tm_year + 1900);
  657. return result;
  658. }
  659. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  660. {
  661. int result = PASS;
  662. char* errMsg = NULL;
  663. char sqlStr[8192];
  664. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  665. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  666. {
  667. result = FAIL;
  668. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  669. }
  670. 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));
  671. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  672. {
  673. result = FAIL;
  674. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  675. }
  676. return result;
  677. }
  678. 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)
  679. {
  680. int result = PASS;
  681. char* errMsg = NULL;
  682. char sqlStr[8192];
  683. 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');",
  684. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  685. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  686. {
  687. result = FAIL;
  688. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  689. }
  690. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  691. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  692. {
  693. result = FAIL;
  694. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  695. }
  696. return result;
  697. }
  698. int OCPP_update_deduct_info(int txId, char *creditNo)
  699. {
  700. int result = PASS;
  701. char* errMsg = NULL;
  702. char sqlStr[8192];
  703. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  704. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  705. {
  706. result = FAIL;
  707. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  708. }
  709. return result;
  710. }
  711. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  712. {
  713. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  714. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  715. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, "{\\\"txId\\\":%d,\\\"creditNo\\\":\\\"%s\\\",\\\"deductResult\\\":%s,\\\"isDonateInvoice\\\":%s,\\\"amount\\\":%s,\\\"approvalNo\\\":\\\"%s\\\"}",
  716. atoi(columnValue[1]),
  717. columnValue[2],
  718. atoi(columnValue[3])==1?"true":"false",
  719. atoi(columnValue[4])==1?"true":"false",
  720. columnValue[5],
  721. columnValue[9]);
  722. ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
  723. return 0;
  724. }
  725. void OCPP_query_deduct_info()
  726. {
  727. int rc = 0;
  728. char sql[100];
  729. char zErrMsg[100];
  730. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  731. /* Execute SQL statement */
  732. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  733. if( rc != SQLITE_OK )
  734. {
  735. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  736. }
  737. }
  738. void reportReaderStatus(int gun_index)
  739. {
  740. struct timeval tmnow;
  741. struct tm *tm;
  742. char buf[28];//, usec_buf[6];
  743. gettimeofday(&tmnow, NULL);
  744. time_t t;
  745. t = time(NULL);
  746. /*UTC time and date*/
  747. tm = gmtime(&t);
  748. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  749. #if 0 // remove temporally
  750. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  751. strcat(buf,".");
  752. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  753. strcat(buf,usec_buf);
  754. #endif
  755. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  756. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId,"%s","ID_ReaderStatus");
  757. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, "{\\\"connectorId\\\":%d,\\\"readerStatus\\\":%d,\\\"timestamp\\\":\\\"%s\\\",\\\"SerialNo\\\":\\\"%s\\\",\\\"creditNo\\\":\\\"%s\\\",\\\"VEMData\\\":\\\"%s\\\"}",
  758. (gun_index+1),
  759. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].readerStatus,
  760. buf,
  761. ShmOCPP16DataPH->TcciCustomData.SerialNo[gun_index],
  762. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].creditNo,
  763. ShmOCPP16Data->TcciCustomData.VEMData[gun_index]);
  764. ShmOCPP16DataPH->CsMsg.bits[0].DataTransferReq = 1;
  765. }
  766. //==========================================
  767. // Check time passed since today
  768. //==========================================
  769. long long DiffTimebWithNow(struct timeb ST)
  770. {
  771. //return milli-second
  772. struct timeb ET;
  773. long long StartTime,StopTime;
  774. ftime(&ET);
  775. StartTime=(long long)ST.time;
  776. StopTime=(long long)ET.time;
  777. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  778. }
  779. int getTimePassSinceToday(uint8_t gun_index)
  780. {
  781. int result = -1;
  782. static time_t lastTime[4];
  783. time_t t;
  784. struct tm *tmStartToday;
  785. struct timeb tbStartToday;
  786. t=time(NULL);
  787. if(difftime(t, lastTime[gun_index])>0)
  788. {
  789. tmStartToday=localtime(&t);
  790. tmStartToday->tm_hour = 0;
  791. tmStartToday->tm_min = 0;
  792. tmStartToday->tm_sec = 0;
  793. tbStartToday.time = mktime(tmStartToday);
  794. tbStartToday.millitm = 0;
  795. result = DiffTimebWithNow(tbStartToday)/1000;
  796. lastTime[gun_index] = t;
  797. }
  798. return result;
  799. }
  800. void getNowDatetime(uint8_t *data)
  801. {
  802. time_t t = time(NULL);
  803. struct tm tm = *localtime(&t);
  804. 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);
  805. }
  806. int syncDateTimeRTC(uint8_t *data)
  807. {
  808. struct ParsingResult
  809. {
  810. int result;
  811. int scanedElement;
  812. int year;
  813. int month;
  814. int mday;
  815. int hour;
  816. int min;
  817. int sec;
  818. int tz_hour;
  819. int tz_min;
  820. float minSec;
  821. }result;
  822. struct tm tmOrg;
  823. struct tm *tmTarget;
  824. struct timeb tbTarget;
  825. char buf[128];
  826. memset(&result, 0x00, sizeof(struct ParsingResult));
  827. result.result = PASS;
  828. if(strstr((char*)data, ".") != NULL)
  829. {
  830. // Original data with mini second
  831. if(strstr((char*)data, "Z") != NULL)
  832. {
  833. // Original data with Z
  834. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  835. &result.year,
  836. &result.month,
  837. &result.mday,
  838. &result.hour,
  839. &result.min,
  840. &result.sec,
  841. &result.minSec);
  842. }
  843. else
  844. {
  845. // Original data without Z
  846. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  847. &result.year,
  848. &result.month,
  849. &result.mday,
  850. &result.hour,
  851. &result.min,
  852. &result.sec,
  853. &result.minSec,
  854. &result.tz_hour,
  855. &result.tz_min);
  856. }
  857. }
  858. else
  859. {
  860. // Original data without mini second
  861. if(strstr((char*)data, "Z") != NULL)
  862. {
  863. // Original data with Z
  864. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  865. &result.year,
  866. &result.month,
  867. &result.mday,
  868. &result.hour,
  869. &result.min,
  870. &result.sec);
  871. }
  872. else
  873. {
  874. // Original data without Z
  875. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  876. &result.year,
  877. &result.month,
  878. &result.mday,
  879. &result.hour,
  880. &result.min,
  881. &result.sec,
  882. &result.tz_hour,
  883. &result.tz_min);
  884. }
  885. }
  886. tmOrg.tm_year = result.year - 1900;
  887. tmOrg.tm_mon = result.month - 1;
  888. tmOrg.tm_mday = result.mday;
  889. tmOrg.tm_hour = result.hour;
  890. tmOrg.tm_min = result.min;
  891. tmOrg.tm_sec = result.sec;
  892. tmOrg.tm_gmtoff = 0;
  893. tbTarget.time = mktime(&tmOrg);
  894. tbTarget.timezone = 0;
  895. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  896. tmTarget = gmtime(&tbTarget.time);
  897. 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);
  898. //DEBUG_INFO(" org date time: %s\n", data);
  899. //DEBUG_INFO("parse date time: %s\n", buf);
  900. system(buf);
  901. system("/sbin/hwclock -w --systohc");
  902. if(result.scanedElement < 6)
  903. result.result = FAIL;
  904. return result.result;
  905. }
  906. //==========================================
  907. // GetCompositeSchedule logic related function
  908. //==========================================
  909. int DiffTimebSec(struct timeb ST, struct timeb ET)
  910. {
  911. //return milli-second
  912. unsigned int StartTime,StopTime;
  913. StartTime=(unsigned int)ST.time;
  914. StopTime=(unsigned int)ET.time;
  915. return (StopTime-StartTime);
  916. }
  917. int DiffTimebWithNowSec(struct timeb ST)
  918. {
  919. //return milli-second
  920. struct timeb ET;
  921. unsigned int StartTime,StopTime;
  922. ftime(&ET);
  923. StartTime=(unsigned int)ST.time;
  924. StopTime=(unsigned int)ET.time;
  925. return (StopTime-StartTime);
  926. }
  927. int getStartStop(uint8_t *start, uint8_t *stop)
  928. {
  929. struct ParsingResult
  930. {
  931. int result;
  932. int scanedElement;
  933. int year;
  934. int month;
  935. int mday;
  936. int hour;
  937. int min;
  938. int sec;
  939. int tz_hour;
  940. int tz_min;
  941. float minSec;
  942. };
  943. struct ParsingResult parseStart;
  944. struct ParsingResult parseStop;
  945. int result = -1;
  946. struct tm tmStart;
  947. struct timeb tbStart;
  948. struct tm tmStop;
  949. struct timeb tbStop;
  950. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  951. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  952. // Scan start & stop date time
  953. if(strstr((char*)start, ".") != NULL)
  954. {
  955. // Original data with mini second
  956. if(strstr((char*)start, "Z") != NULL)
  957. {
  958. // Original data with Z
  959. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  960. &parseStart.year,
  961. &parseStart.month,
  962. &parseStart.mday,
  963. &parseStart.hour,
  964. &parseStart.min,
  965. &parseStart.sec,
  966. &parseStart.minSec);
  967. }
  968. else
  969. {
  970. // Original data without Z
  971. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  972. &parseStart.year,
  973. &parseStart.month,
  974. &parseStart.mday,
  975. &parseStart.hour,
  976. &parseStart.min,
  977. &parseStart.sec,
  978. &parseStart.minSec,
  979. &parseStart.tz_hour,
  980. &parseStart.tz_min);
  981. }
  982. }
  983. else
  984. {
  985. // Original data without mini second
  986. if(strstr((char*)start, "Z") != NULL)
  987. {
  988. // Original data with Z
  989. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  990. &parseStart.year,
  991. &parseStart.month,
  992. &parseStart.mday,
  993. &parseStart.hour,
  994. &parseStart.min,
  995. &parseStart.sec);
  996. }
  997. else
  998. {
  999. // Original data without Z
  1000. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1001. &parseStart.year,
  1002. &parseStart.month,
  1003. &parseStart.mday,
  1004. &parseStart.hour,
  1005. &parseStart.min,
  1006. &parseStart.sec,
  1007. &parseStart.tz_hour,
  1008. &parseStart.tz_min);
  1009. }
  1010. }
  1011. if(strstr((char*)stop, ".") != NULL)
  1012. {
  1013. // Original data with mini second
  1014. if(strstr((char*)stop, "Z") != NULL)
  1015. {
  1016. // Original data with Z
  1017. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1018. &parseStop.year,
  1019. &parseStop.month,
  1020. &parseStop.mday,
  1021. &parseStop.hour,
  1022. &parseStop.min,
  1023. &parseStop.sec,
  1024. &parseStop.minSec);
  1025. }
  1026. else
  1027. {
  1028. // Original data without Z
  1029. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1030. &parseStop.year,
  1031. &parseStop.month,
  1032. &parseStop.mday,
  1033. &parseStop.hour,
  1034. &parseStop.min,
  1035. &parseStop.sec,
  1036. &parseStop.minSec,
  1037. &parseStop.tz_hour,
  1038. &parseStop.tz_min);
  1039. }
  1040. }
  1041. else
  1042. {
  1043. // Original data without mini second
  1044. if(strstr((char*)stop, "Z") != NULL)
  1045. {
  1046. // Original data with Z
  1047. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1048. &parseStop.year,
  1049. &parseStop.month,
  1050. &parseStop.mday,
  1051. &parseStop.hour,
  1052. &parseStop.min,
  1053. &parseStop.sec);
  1054. }
  1055. else
  1056. {
  1057. // Original data without Z
  1058. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1059. &parseStop.year,
  1060. &parseStop.month,
  1061. &parseStop.mday,
  1062. &parseStop.hour,
  1063. &parseStop.min,
  1064. &parseStop.sec,
  1065. &parseStop.tz_hour,
  1066. &parseStop.tz_min);
  1067. }
  1068. }
  1069. // Calculate date time difference
  1070. if((parseStart.scanedElement >=6) &&
  1071. (parseStop.scanedElement >=6))
  1072. {
  1073. //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);
  1074. //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);
  1075. tmStart.tm_year = parseStart.year - 1900;
  1076. tmStart.tm_mon = parseStart.month - 1;
  1077. tmStart.tm_mday = parseStart.mday;
  1078. tmStart.tm_hour = parseStart.hour;
  1079. tmStart.tm_min = parseStart.min;
  1080. tmStart.tm_sec = parseStart.sec;
  1081. tmStart.tm_gmtoff = 0;
  1082. tbStart.time = mktime(&tmStart);
  1083. tbStart.timezone = 0;
  1084. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1085. tmStop.tm_year = parseStop.year - 1900;
  1086. tmStop.tm_mon = parseStop.month - 1;
  1087. tmStop.tm_mday = parseStop.mday;
  1088. tmStop.tm_hour = parseStop.hour;
  1089. tmStop.tm_min = parseStop.min;
  1090. tmStop.tm_sec = parseStop.sec;
  1091. tmStop.tm_gmtoff = 0;
  1092. tbStop.time = mktime(&tmStop);
  1093. tbStop.timezone = 0;
  1094. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1095. result = DiffTimebSec(tbStart, tbStop);
  1096. //DEBUG_INFO("getStartStop(): %d\n", result);
  1097. }
  1098. else
  1099. {
  1100. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1101. }
  1102. return result;
  1103. }
  1104. int isOvertNow(uint8_t *start)
  1105. {
  1106. int result = NO;
  1107. struct ParsingResult
  1108. {
  1109. int result;
  1110. int scanedElement;
  1111. int year;
  1112. int month;
  1113. int mday;
  1114. int hour;
  1115. int min;
  1116. int sec;
  1117. int tz_hour;
  1118. int tz_min;
  1119. float minSec;
  1120. }parsingResult;
  1121. struct tm tmStart;
  1122. struct timeb tbStart;
  1123. if(strstr((char*)start, ".") != NULL)
  1124. {
  1125. // Original data with mini second
  1126. if(strstr((char*)start, "Z") != NULL)
  1127. {
  1128. // Original data with Z
  1129. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1130. &parsingResult.year,
  1131. &parsingResult.month,
  1132. &parsingResult.mday,
  1133. &parsingResult.hour,
  1134. &parsingResult.min,
  1135. &parsingResult.sec,
  1136. &parsingResult.minSec);
  1137. }
  1138. else
  1139. {
  1140. // Original data without Z
  1141. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1142. &parsingResult.year,
  1143. &parsingResult.month,
  1144. &parsingResult.mday,
  1145. &parsingResult.hour,
  1146. &parsingResult.min,
  1147. &parsingResult.sec,
  1148. &parsingResult.minSec,
  1149. &parsingResult.tz_hour,
  1150. &parsingResult.tz_min);
  1151. }
  1152. }
  1153. else
  1154. {
  1155. // Original data without mini second
  1156. if(strstr((char*)start, "Z") != NULL)
  1157. {
  1158. // Original data with Z
  1159. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1160. &parsingResult.year,
  1161. &parsingResult.month,
  1162. &parsingResult.mday,
  1163. &parsingResult.hour,
  1164. &parsingResult.min,
  1165. &parsingResult.sec);
  1166. }
  1167. else
  1168. {
  1169. // Original data without Z
  1170. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1171. &parsingResult.year,
  1172. &parsingResult.month,
  1173. &parsingResult.mday,
  1174. &parsingResult.hour,
  1175. &parsingResult.min,
  1176. &parsingResult.sec,
  1177. &parsingResult.tz_hour,
  1178. &parsingResult.tz_min);
  1179. }
  1180. }
  1181. if(parsingResult.scanedElement >= 6)
  1182. {
  1183. tmStart.tm_year = parsingResult.year - 1900;
  1184. tmStart.tm_mon = parsingResult.month - 1;
  1185. tmStart.tm_mday = parsingResult.mday;
  1186. tmStart.tm_hour = parsingResult.hour;
  1187. tmStart.tm_min = parsingResult.min;
  1188. tmStart.tm_sec = parsingResult.sec;
  1189. tmStart.tm_gmtoff = 0;
  1190. tbStart.time = mktime(&tmStart);
  1191. tbStart.timezone = 0;
  1192. tbStart.millitm = 0;
  1193. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1194. if(DiffTimebWithNowSec(tbStart) <= 0)
  1195. result = NO;
  1196. else
  1197. result = YES;
  1198. }
  1199. else
  1200. {
  1201. DEBUG_WARN("Start date parsing error.\n");
  1202. }
  1203. return result;
  1204. }
  1205. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1206. {
  1207. struct ParsingResult
  1208. {
  1209. int result;
  1210. int scanedElement;
  1211. int year;
  1212. int month;
  1213. int mday;
  1214. int hour;
  1215. int min;
  1216. int sec;
  1217. int tz_hour;
  1218. int tz_min;
  1219. float minSec;
  1220. };
  1221. struct ParsingResult parseStart;
  1222. struct ParsingResult parseStop;
  1223. int result = -1;
  1224. struct tm tmStart;
  1225. struct timeb tbStart;
  1226. struct tm tmStop;
  1227. struct timeb tbStop;
  1228. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1229. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1230. // Scan start & stop date time
  1231. if(strstr((char*)start, ".") != NULL)
  1232. {
  1233. // Original data with mini second
  1234. if(strstr((char*)start, "Z") != NULL)
  1235. {
  1236. // Original data with Z
  1237. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1238. &parseStart.year,
  1239. &parseStart.month,
  1240. &parseStart.mday,
  1241. &parseStart.hour,
  1242. &parseStart.min,
  1243. &parseStart.sec,
  1244. &parseStart.minSec);
  1245. }
  1246. else
  1247. {
  1248. // Original data without Z
  1249. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1250. &parseStart.year,
  1251. &parseStart.month,
  1252. &parseStart.mday,
  1253. &parseStart.hour,
  1254. &parseStart.min,
  1255. &parseStart.sec,
  1256. &parseStart.minSec,
  1257. &parseStart.tz_hour,
  1258. &parseStart.tz_min);
  1259. }
  1260. }
  1261. else
  1262. {
  1263. // Original data without mini second
  1264. if(strstr((char*)start, "Z") != NULL)
  1265. {
  1266. // Original data with Z
  1267. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1268. &parseStart.year,
  1269. &parseStart.month,
  1270. &parseStart.mday,
  1271. &parseStart.hour,
  1272. &parseStart.min,
  1273. &parseStart.sec);
  1274. }
  1275. else
  1276. {
  1277. // Original data without Z
  1278. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1279. &parseStart.year,
  1280. &parseStart.month,
  1281. &parseStart.mday,
  1282. &parseStart.hour,
  1283. &parseStart.min,
  1284. &parseStart.sec,
  1285. &parseStart.tz_hour,
  1286. &parseStart.tz_min);
  1287. }
  1288. }
  1289. if(strstr((char*)stop, ".") != NULL)
  1290. {
  1291. // Original data with mini second
  1292. if(strstr((char*)stop, "Z") != NULL)
  1293. {
  1294. // Original data with Z
  1295. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1296. &parseStop.year,
  1297. &parseStop.month,
  1298. &parseStop.mday,
  1299. &parseStop.hour,
  1300. &parseStop.min,
  1301. &parseStop.sec,
  1302. &parseStop.minSec);
  1303. }
  1304. else
  1305. {
  1306. // Original data without Z
  1307. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1308. &parseStop.year,
  1309. &parseStop.month,
  1310. &parseStop.mday,
  1311. &parseStop.hour,
  1312. &parseStop.min,
  1313. &parseStop.sec,
  1314. &parseStop.minSec,
  1315. &parseStop.tz_hour,
  1316. &parseStop.tz_min);
  1317. }
  1318. }
  1319. else
  1320. {
  1321. // Original data without mini second
  1322. if(strstr((char*)stop, "Z") != NULL)
  1323. {
  1324. // Original data with Z
  1325. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1326. &parseStop.year,
  1327. &parseStop.month,
  1328. &parseStop.mday,
  1329. &parseStop.hour,
  1330. &parseStop.min,
  1331. &parseStop.sec);
  1332. }
  1333. else
  1334. {
  1335. // Original data without Z
  1336. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1337. &parseStop.year,
  1338. &parseStop.month,
  1339. &parseStop.mday,
  1340. &parseStop.hour,
  1341. &parseStop.min,
  1342. &parseStop.sec,
  1343. &parseStop.tz_hour,
  1344. &parseStop.tz_min);
  1345. }
  1346. }
  1347. // Calculate date time difference
  1348. if((parseStart.scanedElement >=6) &&
  1349. (parseStop.scanedElement >=6))
  1350. {
  1351. //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);
  1352. //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);
  1353. tmStart.tm_year = parseStart.year - 1900;
  1354. tmStart.tm_mon = parseStart.month - 1;
  1355. tmStart.tm_mday = parseStart.mday;
  1356. tmStart.tm_hour = parseStart.hour;
  1357. tmStart.tm_min = parseStart.min;
  1358. tmStart.tm_sec = parseStart.sec;
  1359. tmStart.tm_gmtoff = 0;
  1360. tbStart.time = mktime(&tmStart);
  1361. tbStart.timezone = 0;
  1362. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1363. tmStop.tm_year = parseStop.year - 1900;
  1364. tmStop.tm_mon = parseStop.month - 1;
  1365. tmStop.tm_mday = parseStop.mday;
  1366. tmStop.tm_hour = parseStop.hour;
  1367. tmStop.tm_min = parseStop.min;
  1368. tmStop.tm_sec = parseStop.sec;
  1369. tmStop.tm_gmtoff = 0;
  1370. tbStop.time = mktime(&tmStop);
  1371. tbStop.timezone = 0;
  1372. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1373. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1374. //DEBUG_INFO("getStartStop(): %d\n", result);
  1375. }
  1376. else
  1377. {
  1378. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1379. }
  1380. return result;
  1381. }
  1382. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1383. {
  1384. FILE *fp;
  1385. char profileFileName[128];
  1386. char *line = NULL;
  1387. size_t len = 0;
  1388. time_t CurrentTime;
  1389. struct tm *tmComposite;
  1390. struct StructChargingProfile maxProfile;
  1391. struct StructChargingProfile compositeProfile;
  1392. uint8_t limitMax=0;
  1393. int compositePeriodIdx = 0;
  1394. //uint8_t isDurationNull = FALSE;
  1395. CurrentTime = time(NULL);
  1396. tmComposite=localtime(&CurrentTime);
  1397. 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);
  1398. if(isUnitA)
  1399. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1400. else
  1401. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1402. compositeProfile.ChargingSchedule.Duration = durationReq;
  1403. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1404. {
  1405. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1406. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1407. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1408. }
  1409. compositeProfile.ChargingProfileId = 0;
  1410. compositeProfile.StackLevel = 99 ;
  1411. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1412. maxProfile.ChargingProfileId = -1;
  1413. maxProfile.ChargingSchedule.Duration = -1;
  1414. system("rm -f /tmp/*.json");
  1415. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1416. // Search max profile
  1417. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1418. if((access(profileFileName, F_OK))!=-1)
  1419. {
  1420. fp = fopen(profileFileName, "r");
  1421. while(getline(&line, &len, fp) != -1)
  1422. {
  1423. json_object *obj = NULL;
  1424. obj = json_tokener_parse(line);
  1425. if(is_error(obj))
  1426. {
  1427. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1428. }
  1429. else
  1430. {
  1431. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1432. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1433. )
  1434. {
  1435. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1436. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1437. )
  1438. {
  1439. struct tm tmFrom, tmTo;
  1440. struct timeb tbFrom, tbTo;
  1441. 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) &&
  1442. (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))
  1443. {
  1444. tmFrom.tm_year -= 1900;
  1445. tmFrom.tm_mon -= 1;
  1446. tbFrom.time = mktime(&tmFrom);
  1447. tmTo.tm_year -= 1900;
  1448. tmTo.tm_mon -= 1;
  1449. tbTo.time = mktime(&tmTo);
  1450. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1451. {
  1452. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1453. {
  1454. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1455. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1456. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1457. }
  1458. if(maxProfile.ChargingProfileId == -1)
  1459. DEBUG_INFO("MaxProfile found.\n");
  1460. else
  1461. DEBUG_INFO("MaxProfile updated.\n");
  1462. // Required item
  1463. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1464. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1465. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1466. if(isUnitA)
  1467. {
  1468. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1469. 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++)
  1470. {
  1471. 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"));
  1472. 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?
  1473. 3:
  1474. 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")));
  1475. 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")));
  1476. }
  1477. }
  1478. else
  1479. {
  1480. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1481. 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++)
  1482. {
  1483. 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"));
  1484. 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?
  1485. 3:
  1486. 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")));
  1487. 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));
  1488. }
  1489. }
  1490. // Optional item
  1491. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1492. {
  1493. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1494. }
  1495. else
  1496. {
  1497. sprintf((char*)maxProfile.ValidFrom, " ");
  1498. }
  1499. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1500. {
  1501. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1502. }
  1503. else
  1504. {
  1505. sprintf((char*)maxProfile.ValidTo, " ");
  1506. }
  1507. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1508. {
  1509. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1510. }
  1511. else
  1512. {
  1513. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1514. }
  1515. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1516. {
  1517. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1518. }
  1519. else
  1520. {
  1521. maxProfile.TransactionId = -1;
  1522. }
  1523. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1524. {
  1525. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1526. }
  1527. else
  1528. {
  1529. maxProfile.ChargingSchedule.Duration = 86400;
  1530. //isDurationNull = TRUE;
  1531. }
  1532. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1533. {
  1534. 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")));
  1535. }
  1536. else
  1537. {
  1538. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1539. }
  1540. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1541. {
  1542. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1543. }
  1544. else
  1545. {
  1546. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1547. }
  1548. }
  1549. }
  1550. }
  1551. else
  1552. {
  1553. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1554. {
  1555. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1556. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1557. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1558. }
  1559. if(maxProfile.ChargingProfileId == -1)
  1560. DEBUG_INFO("MaxProfile found.\n");
  1561. else
  1562. DEBUG_INFO("MaxProfile updated.\n");
  1563. // Required item
  1564. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1565. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1566. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1567. if(isUnitA)
  1568. {
  1569. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1570. 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++)
  1571. {
  1572. 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"));
  1573. 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?
  1574. 3:
  1575. 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")));
  1576. 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")));
  1577. }
  1578. }
  1579. else
  1580. {
  1581. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1582. 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++)
  1583. {
  1584. 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"));
  1585. 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?
  1586. 3:
  1587. 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")));
  1588. 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));
  1589. }
  1590. }
  1591. // Optional item
  1592. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1593. {
  1594. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1595. }
  1596. else
  1597. {
  1598. sprintf((char*)maxProfile.ValidFrom, " ");
  1599. }
  1600. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1601. {
  1602. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1603. }
  1604. else
  1605. {
  1606. sprintf((char*)maxProfile.ValidTo, " ");
  1607. }
  1608. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1609. {
  1610. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1611. }
  1612. else
  1613. {
  1614. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1615. }
  1616. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1617. {
  1618. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1619. }
  1620. else
  1621. {
  1622. maxProfile.TransactionId = -1;
  1623. }
  1624. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1625. {
  1626. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1627. }
  1628. else
  1629. {
  1630. maxProfile.ChargingSchedule.Duration = 86400;
  1631. //isDurationNull = TRUE;
  1632. }
  1633. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1634. {
  1635. 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")));
  1636. }
  1637. else
  1638. {
  1639. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  1640. }
  1641. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1642. {
  1643. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1644. }
  1645. else
  1646. {
  1647. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1648. }
  1649. }
  1650. }
  1651. }
  1652. json_object_put(obj);
  1653. }
  1654. fclose(fp);
  1655. /*
  1656. if(maxProfile.ChargingProfileId !=-1)
  1657. {
  1658. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1659. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1660. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1661. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1662. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1663. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1664. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1665. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1666. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1667. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1668. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1669. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1670. {
  1671. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1672. {
  1673. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1674. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1675. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1676. }
  1677. }
  1678. }
  1679. else
  1680. DEBUG_INFO("MaxProfile not found.\n");
  1681. DEBUG_INFO("------------------------------------\n");*/
  1682. }
  1683. if(maxProfile.ChargingProfileId != -1)
  1684. {
  1685. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1686. {
  1687. if(maxProfile.ChargingSchedule.Duration != -1)
  1688. {
  1689. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1690. 0:
  1691. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1692. }
  1693. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1694. {
  1695. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1696. {
  1697. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  1698. 0:
  1699. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  1700. if(idxPeriod > 0)
  1701. {
  1702. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1703. {
  1704. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1705. }
  1706. }
  1707. }
  1708. }
  1709. }
  1710. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1711. {
  1712. if(maxProfile.ChargingSchedule.Duration != -1)
  1713. {
  1714. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1715. }
  1716. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1717. {
  1718. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1719. {
  1720. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1721. if(idxPeriod > 0)
  1722. {
  1723. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1724. {
  1725. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1726. }
  1727. }
  1728. }
  1729. }
  1730. }
  1731. else
  1732. {
  1733. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1734. {
  1735. if(maxProfile.ChargingSchedule.Duration != -1)
  1736. {
  1737. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1738. 0:
  1739. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1740. }
  1741. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1742. {
  1743. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1744. {
  1745. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  1746. 0:
  1747. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  1748. if(idxPeriod > 0)
  1749. {
  1750. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1751. {
  1752. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1753. }
  1754. }
  1755. }
  1756. }
  1757. }
  1758. else
  1759. {
  1760. if((maxProfile.ChargingSchedule.Duration != -1)/* && (isDurationNull)*/)
  1761. {
  1762. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1763. 0:
  1764. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1765. }
  1766. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1767. {
  1768. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1769. {
  1770. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  1771. 0:
  1772. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  1773. if(idxPeriod > 0)
  1774. {
  1775. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1776. {
  1777. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1778. }
  1779. }
  1780. }
  1781. }
  1782. }
  1783. }
  1784. /*
  1785. DEBUG_INFO("MaxProfile after align.\n");
  1786. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1787. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1788. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1789. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1790. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1791. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1792. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1793. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1794. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1795. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1796. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1797. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1798. {
  1799. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1800. {
  1801. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1802. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1803. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1804. }
  1805. }
  1806. DEBUG_INFO("------------------------------------\n");*/
  1807. }
  1808. // Find each profile period quantity
  1809. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1810. {
  1811. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1812. limitMax = idx+1;
  1813. }
  1814. if(maxProfile.ChargingProfileId != -1)
  1815. {
  1816. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1817. {
  1818. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1819. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1820. (maxProfile.ChargingSchedule.Duration > 0))
  1821. {
  1822. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1823. {
  1824. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1825. compositePeriodIdx++;
  1826. }
  1827. else
  1828. {
  1829. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1830. }
  1831. }
  1832. }
  1833. }
  1834. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1835. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  1836. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  1837. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  1838. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1839. {
  1840. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1841. {
  1842. compositeProfile.ChargingProfileId = 1;
  1843. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1844. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1845. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1846. }
  1847. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1848. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1849. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1850. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1851. }
  1852. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  1853. if(line)
  1854. free(line);
  1855. }
  1856. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1857. {
  1858. FILE *fp;
  1859. char profileFileName[128];
  1860. char *line = NULL;
  1861. size_t len = 0;
  1862. time_t CurrentTime;
  1863. struct tm *tmComposite;
  1864. struct StructChargingProfile maxProfile;
  1865. struct StructChargingProfile defaultTxProfile;
  1866. struct StructChargingProfile txProfile;
  1867. struct StructChargingProfile compositeProfile;
  1868. struct StructChargingSchedulePeriod tmpPeriod;
  1869. uint8_t limitMax=0;
  1870. uint8_t limitDef=0;
  1871. uint8_t limitTx=0;
  1872. int compositePeriodIdx = 0;
  1873. CurrentTime = time(NULL);
  1874. tmComposite=localtime(&CurrentTime);
  1875. 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);
  1876. if(isUnitA)
  1877. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1878. else
  1879. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1880. compositeProfile.ChargingSchedule.Duration = durationReq;
  1881. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1882. {
  1883. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1884. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1885. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1886. }
  1887. compositeProfile.ChargingProfileId = 0;
  1888. compositeProfile.StackLevel = 99 ;
  1889. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1890. maxProfile.ChargingProfileId = -1;
  1891. defaultTxProfile.ChargingProfileId = -1;
  1892. txProfile.ChargingProfileId = -1;
  1893. maxProfile.ChargingSchedule.Duration = -1;
  1894. defaultTxProfile.ChargingSchedule.Duration = -1;
  1895. txProfile.ChargingSchedule.Duration = -1;
  1896. system("rm -f /tmp/*.json");
  1897. system("cp /Storage/OCPP_PH/*.json /tmp 2>/dev/null");
  1898. /*
  1899. * Search valid charging profile
  1900. */
  1901. //DEBUG_INFO("====================================\n");
  1902. // Search tx profile
  1903. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1904. if((access(profileFileName, F_OK))!=-1)
  1905. {
  1906. fp = fopen(profileFileName, "r");
  1907. while(getline(&line, &len, fp) != -1)
  1908. {
  1909. json_object *obj = NULL;
  1910. obj = json_tokener_parse(line);
  1911. if(is_error(obj))
  1912. {
  1913. DEBUG_ERROR("Parse txProfile from file error.\n");
  1914. }
  1915. else
  1916. {
  1917. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1918. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1919. )
  1920. {
  1921. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1922. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1923. )
  1924. {
  1925. struct tm tmFrom, tmTo;
  1926. struct timeb tbFrom, tbTo;
  1927. 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) &&
  1928. (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))
  1929. {
  1930. tmFrom.tm_year -= 1900;
  1931. tmFrom.tm_mon -= 1;
  1932. tbFrom.time = mktime(&tmFrom);
  1933. tmTo.tm_year -= 1900;
  1934. tmTo.tm_mon -= 1;
  1935. tbTo.time = mktime(&tmTo);
  1936. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1937. {
  1938. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1939. {
  1940. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1941. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1942. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1943. }
  1944. if(txProfile.ChargingProfileId == -1)
  1945. DEBUG_INFO("TxProfile found.\n");
  1946. else
  1947. DEBUG_INFO("TxProfile updated.\n");
  1948. // Required item
  1949. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1950. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1951. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1952. if(isUnitA)
  1953. {
  1954. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1955. 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++)
  1956. {
  1957. 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"));
  1958. 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?
  1959. 3:
  1960. 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")));
  1961. 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")));
  1962. }
  1963. }
  1964. else
  1965. {
  1966. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1967. 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++)
  1968. {
  1969. 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"));
  1970. 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?
  1971. 3:
  1972. 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")));
  1973. 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));
  1974. }
  1975. }
  1976. // Optional item
  1977. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1978. {
  1979. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1980. }
  1981. else
  1982. {
  1983. sprintf((char*)txProfile.ValidFrom, " ");
  1984. }
  1985. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1986. {
  1987. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1988. }
  1989. else
  1990. {
  1991. sprintf((char*)txProfile.ValidTo, " ");
  1992. }
  1993. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1994. {
  1995. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1996. }
  1997. else
  1998. {
  1999. sprintf((char*)txProfile.RecurrencyKind, " ");
  2000. }
  2001. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2002. {
  2003. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2004. }
  2005. else
  2006. {
  2007. txProfile.TransactionId = -1;
  2008. }
  2009. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2010. {
  2011. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2012. }
  2013. else
  2014. {
  2015. txProfile.ChargingSchedule.Duration = 86400;
  2016. }
  2017. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2018. {
  2019. 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")));
  2020. }
  2021. else
  2022. {
  2023. 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));
  2024. }
  2025. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2026. {
  2027. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2028. }
  2029. else
  2030. {
  2031. txProfile.ChargingSchedule.MinChargingRate = -1;
  2032. }
  2033. }
  2034. }
  2035. }
  2036. else
  2037. {
  2038. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2039. {
  2040. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2041. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2042. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2043. }
  2044. if(txProfile.ChargingProfileId == -1)
  2045. DEBUG_INFO("TxProfile found.\n");
  2046. else
  2047. DEBUG_INFO("TxProfile updated.\n");
  2048. // Required item
  2049. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2050. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2051. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2052. if(isUnitA)
  2053. {
  2054. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2055. 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++)
  2056. {
  2057. 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"));
  2058. 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?
  2059. 3:
  2060. 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")));
  2061. 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")));
  2062. }
  2063. }
  2064. else
  2065. {
  2066. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2067. 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++)
  2068. {
  2069. 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"));
  2070. 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?
  2071. 3:
  2072. 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")));
  2073. 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));
  2074. }
  2075. }
  2076. // Optional item
  2077. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2078. {
  2079. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2080. }
  2081. else
  2082. {
  2083. sprintf((char*)txProfile.ValidFrom, " ");
  2084. }
  2085. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2086. {
  2087. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2088. }
  2089. else
  2090. {
  2091. sprintf((char*)txProfile.ValidTo, " ");
  2092. }
  2093. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2094. {
  2095. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2096. }
  2097. else
  2098. {
  2099. sprintf((char*)txProfile.RecurrencyKind, " ");
  2100. }
  2101. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2102. {
  2103. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2104. }
  2105. else
  2106. {
  2107. txProfile.TransactionId = -1;
  2108. }
  2109. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2110. {
  2111. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2112. }
  2113. else
  2114. {
  2115. txProfile.ChargingSchedule.Duration = 86400;
  2116. }
  2117. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2118. {
  2119. 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")));
  2120. }
  2121. else
  2122. {
  2123. 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));
  2124. }
  2125. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2126. {
  2127. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2128. }
  2129. else
  2130. {
  2131. txProfile.ChargingSchedule.MinChargingRate = -1;
  2132. }
  2133. }
  2134. }
  2135. }
  2136. json_object_put(obj);
  2137. }
  2138. fclose(fp);
  2139. /*
  2140. if(txProfile.ChargingProfileId != -1)
  2141. {
  2142. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2143. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2144. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2145. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2146. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2147. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2148. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2149. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2150. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2151. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2152. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2153. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2154. {
  2155. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2156. {
  2157. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2158. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2159. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2160. }
  2161. }
  2162. }
  2163. else
  2164. DEBUG_INFO("TxProfile not found.\n");*/
  2165. }
  2166. // Search default tx profile
  2167. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2168. if((access(profileFileName, F_OK))==-1)
  2169. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2170. if((access(profileFileName, F_OK))!=-1)
  2171. {
  2172. fp = fopen(profileFileName, "r");
  2173. while(getline(&line, &len, fp) != -1)
  2174. {
  2175. json_object *obj = NULL;
  2176. obj = json_tokener_parse(line);
  2177. if(is_error(obj))
  2178. {
  2179. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2180. }
  2181. else
  2182. {
  2183. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2184. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2185. )
  2186. {
  2187. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2188. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2189. )
  2190. {
  2191. struct tm tmFrom, tmTo;
  2192. struct timeb tbFrom, tbTo;
  2193. 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) &&
  2194. (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))
  2195. {
  2196. tmFrom.tm_year -= 1900;
  2197. tmFrom.tm_mon -= 1;
  2198. tbFrom.time = mktime(&tmFrom);
  2199. tmTo.tm_year -= 1900;
  2200. tmTo.tm_mon -= 1;
  2201. tbTo.time = mktime(&tmTo);
  2202. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2203. {
  2204. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2205. {
  2206. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2207. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2208. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2209. }
  2210. if(defaultTxProfile.ChargingProfileId == -1)
  2211. DEBUG_INFO("TxDefaultProfile found.\n");
  2212. else
  2213. DEBUG_INFO("TxDefaultProfile updated.\n");
  2214. // Required item
  2215. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2216. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2217. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2218. if(isUnitA)
  2219. {
  2220. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2221. 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++)
  2222. {
  2223. 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"));
  2224. 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?
  2225. 3:
  2226. 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")));
  2227. 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")));
  2228. }
  2229. }
  2230. else
  2231. {
  2232. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2233. 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++)
  2234. {
  2235. 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"));
  2236. 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?
  2237. 3:
  2238. 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")));
  2239. 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));
  2240. }
  2241. }
  2242. // Optional item
  2243. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2244. {
  2245. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2246. }
  2247. else
  2248. {
  2249. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2250. }
  2251. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2252. {
  2253. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2254. }
  2255. else
  2256. {
  2257. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2258. }
  2259. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2260. {
  2261. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2262. }
  2263. else
  2264. {
  2265. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2266. }
  2267. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2268. {
  2269. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2270. }
  2271. else
  2272. {
  2273. defaultTxProfile.TransactionId = -1;
  2274. }
  2275. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2276. {
  2277. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2278. }
  2279. else
  2280. {
  2281. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2282. }
  2283. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2284. {
  2285. 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")));
  2286. }
  2287. else
  2288. {
  2289. 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));
  2290. }
  2291. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2292. {
  2293. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2294. }
  2295. else
  2296. {
  2297. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2298. }
  2299. }
  2300. }
  2301. }
  2302. else
  2303. {
  2304. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2305. {
  2306. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2307. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2308. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2309. }
  2310. if(defaultTxProfile.ChargingProfileId == -1)
  2311. DEBUG_INFO("TxDefaultProfile found.\n");
  2312. else
  2313. DEBUG_INFO("TxDefaultProfile updated.\n");
  2314. // Required item
  2315. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2316. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2317. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2318. if(isUnitA)
  2319. {
  2320. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2321. 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++)
  2322. {
  2323. 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"));
  2324. 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?
  2325. 3:
  2326. 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")));
  2327. 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")));
  2328. }
  2329. }
  2330. else
  2331. {
  2332. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2333. 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++)
  2334. {
  2335. 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"));
  2336. 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?
  2337. 3:
  2338. 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")));
  2339. 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));
  2340. }
  2341. }
  2342. // Optional item
  2343. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2344. {
  2345. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2346. }
  2347. else
  2348. {
  2349. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2350. }
  2351. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2352. {
  2353. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2354. }
  2355. else
  2356. {
  2357. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2358. }
  2359. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2360. {
  2361. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2362. }
  2363. else
  2364. {
  2365. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2366. }
  2367. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2368. {
  2369. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2370. }
  2371. else
  2372. {
  2373. defaultTxProfile.TransactionId = -1;
  2374. }
  2375. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2376. {
  2377. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2378. }
  2379. else
  2380. {
  2381. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2382. }
  2383. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2384. {
  2385. 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")));
  2386. }
  2387. else
  2388. {
  2389. 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));
  2390. }
  2391. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2392. {
  2393. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2394. }
  2395. else
  2396. {
  2397. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2398. }
  2399. }
  2400. }
  2401. }
  2402. json_object_put(obj);
  2403. }
  2404. fclose(fp);
  2405. /*
  2406. if(defaultTxProfile.ChargingProfileId != -1)
  2407. {
  2408. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2409. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2410. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2411. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2412. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2413. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2414. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2415. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2416. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2417. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2418. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2419. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2420. {
  2421. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2422. {
  2423. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2424. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2425. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2426. }
  2427. }
  2428. }
  2429. else
  2430. DEBUG_INFO("TxDefaultProfile not found.\n");
  2431. DEBUG_INFO("------------------------------------\n");*/
  2432. }
  2433. // Search max profile
  2434. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2435. if((access(profileFileName, F_OK))!=-1)
  2436. {
  2437. fp = fopen(profileFileName, "r");
  2438. while(getline(&line, &len, fp) != -1)
  2439. {
  2440. json_object *obj = NULL;
  2441. obj = json_tokener_parse(line);
  2442. if(is_error(obj))
  2443. {
  2444. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2445. }
  2446. else
  2447. {
  2448. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2449. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2450. )
  2451. {
  2452. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2453. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2454. )
  2455. {
  2456. struct tm tmFrom, tmTo;
  2457. struct timeb tbFrom, tbTo;
  2458. 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) &&
  2459. (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))
  2460. {
  2461. tmFrom.tm_year -= 1900;
  2462. tmFrom.tm_mon -= 1;
  2463. tbFrom.time = mktime(&tmFrom);
  2464. tmTo.tm_year -= 1900;
  2465. tmTo.tm_mon -= 1;
  2466. tbTo.time = mktime(&tmTo);
  2467. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2468. {
  2469. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2470. {
  2471. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2472. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2473. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2474. }
  2475. if(maxProfile.ChargingProfileId == -1)
  2476. DEBUG_INFO("MaxProfile found.\n");
  2477. else
  2478. DEBUG_INFO("MaxProfile updated.\n");
  2479. // Required item
  2480. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2481. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2482. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2483. if(isUnitA)
  2484. {
  2485. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2486. 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++)
  2487. {
  2488. 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"));
  2489. 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?
  2490. 3:
  2491. 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")));
  2492. 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")));
  2493. }
  2494. }
  2495. else
  2496. {
  2497. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2498. 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++)
  2499. {
  2500. 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"));
  2501. 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?
  2502. 3:
  2503. 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")));
  2504. 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));
  2505. }
  2506. }
  2507. // Optional item
  2508. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2509. {
  2510. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2511. }
  2512. else
  2513. {
  2514. sprintf((char*)maxProfile.ValidFrom, " ");
  2515. }
  2516. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2517. {
  2518. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2519. }
  2520. else
  2521. {
  2522. sprintf((char*)maxProfile.ValidTo, " ");
  2523. }
  2524. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2525. {
  2526. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2527. }
  2528. else
  2529. {
  2530. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2531. }
  2532. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2533. {
  2534. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2535. }
  2536. else
  2537. {
  2538. maxProfile.TransactionId = -1;
  2539. }
  2540. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2541. {
  2542. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2543. }
  2544. else
  2545. {
  2546. maxProfile.ChargingSchedule.Duration = 86400;
  2547. }
  2548. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2549. {
  2550. 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")));
  2551. }
  2552. else
  2553. {
  2554. 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));
  2555. }
  2556. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2557. {
  2558. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2559. }
  2560. else
  2561. {
  2562. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2563. }
  2564. }
  2565. }
  2566. }
  2567. else
  2568. {
  2569. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2570. {
  2571. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2572. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2573. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2574. }
  2575. if(maxProfile.ChargingProfileId == -1)
  2576. DEBUG_INFO("MaxProfile found.\n");
  2577. else
  2578. DEBUG_INFO("MaxProfile updated.\n");
  2579. // Required item
  2580. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2581. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2582. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2583. if(isUnitA)
  2584. {
  2585. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2586. 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++)
  2587. {
  2588. 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"));
  2589. 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?
  2590. 3:
  2591. 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")));
  2592. 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")));
  2593. }
  2594. }
  2595. else
  2596. {
  2597. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2598. 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++)
  2599. {
  2600. 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"));
  2601. 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?
  2602. 3:
  2603. 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")));
  2604. 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));
  2605. }
  2606. }
  2607. // Optional item
  2608. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2609. {
  2610. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2611. }
  2612. else
  2613. {
  2614. sprintf((char*)maxProfile.ValidFrom, " ");
  2615. }
  2616. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2617. {
  2618. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2619. }
  2620. else
  2621. {
  2622. sprintf((char*)maxProfile.ValidTo, " ");
  2623. }
  2624. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2625. {
  2626. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2627. }
  2628. else
  2629. {
  2630. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2631. }
  2632. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2633. {
  2634. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2635. }
  2636. else
  2637. {
  2638. maxProfile.TransactionId = -1;
  2639. }
  2640. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2641. {
  2642. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2643. }
  2644. else
  2645. {
  2646. maxProfile.ChargingSchedule.Duration = 86400;
  2647. }
  2648. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2649. {
  2650. 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")));
  2651. }
  2652. else
  2653. {
  2654. 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));
  2655. }
  2656. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2657. {
  2658. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2659. }
  2660. else
  2661. {
  2662. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2663. }
  2664. }
  2665. }
  2666. }
  2667. json_object_put(obj);
  2668. }
  2669. fclose(fp);
  2670. /*
  2671. if(maxProfile.ChargingProfileId !=-1)
  2672. {
  2673. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2674. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2675. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2676. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2677. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2678. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2679. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2680. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2681. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2682. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2683. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2684. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2685. {
  2686. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2687. {
  2688. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2689. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2690. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2691. }
  2692. }
  2693. }
  2694. else
  2695. DEBUG_INFO("MaxProfile not found.\n");
  2696. DEBUG_INFO("------------------------------------\n");*/
  2697. }
  2698. /*
  2699. * Align found profile start schedule & periods
  2700. */
  2701. //DEBUG_INFO("====================================\n");
  2702. /*
  2703. // For local test usage, force modify found profile start schedule info
  2704. 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);
  2705. 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);
  2706. 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);
  2707. */
  2708. if(txProfile.ChargingProfileId != -1)
  2709. {
  2710. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2711. {
  2712. if(txProfile.ChargingSchedule.Duration != -1)
  2713. {
  2714. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2715. 0:
  2716. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2717. }
  2718. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2719. {
  2720. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2721. {
  2722. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2723. 0:
  2724. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2725. if(idxPeriod > 0)
  2726. {
  2727. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2728. {
  2729. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2730. }
  2731. }
  2732. }
  2733. }
  2734. }
  2735. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2736. {
  2737. if(txProfile.ChargingSchedule.Duration != -1)
  2738. {
  2739. 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?
  2740. 0:
  2741. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2742. }
  2743. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2744. {
  2745. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2746. {
  2747. 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?
  2748. 0:
  2749. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2750. if(idxPeriod > 0)
  2751. {
  2752. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2753. {
  2754. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2755. }
  2756. }
  2757. }
  2758. }
  2759. }
  2760. else
  2761. {
  2762. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2763. {
  2764. if(txProfile.ChargingSchedule.Duration != -1)
  2765. {
  2766. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2767. 0:
  2768. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2769. }
  2770. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2771. {
  2772. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2773. {
  2774. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2775. 0:
  2776. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2777. if(idxPeriod > 0)
  2778. {
  2779. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2780. {
  2781. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2782. }
  2783. }
  2784. }
  2785. }
  2786. }
  2787. else
  2788. {
  2789. if(txProfile.ChargingSchedule.Duration != -1)
  2790. {
  2791. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2792. 0:
  2793. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2794. }
  2795. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2796. {
  2797. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2798. {
  2799. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2800. 0:
  2801. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2802. if(idxPeriod > 0)
  2803. {
  2804. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2805. {
  2806. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2807. }
  2808. }
  2809. }
  2810. }
  2811. }
  2812. }
  2813. /*
  2814. DEBUG_INFO("txProfile after align.\n");
  2815. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2816. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2817. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2818. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2819. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2820. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2821. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2822. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2823. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2824. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2825. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2826. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2827. {
  2828. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2829. {
  2830. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2831. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2832. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2833. }
  2834. }*/
  2835. }
  2836. if(defaultTxProfile.ChargingProfileId != -1)
  2837. {
  2838. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2839. {
  2840. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2841. {
  2842. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2843. 0:
  2844. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2845. }
  2846. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2847. {
  2848. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2849. {
  2850. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2851. 0:
  2852. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2853. if(idxPeriod > 0)
  2854. {
  2855. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2856. {
  2857. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2858. }
  2859. }
  2860. }
  2861. }
  2862. }
  2863. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2864. {
  2865. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2866. {
  2867. 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?
  2868. 0:
  2869. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2870. }
  2871. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2872. {
  2873. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2874. {
  2875. 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?
  2876. 0:
  2877. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2878. if(idxPeriod > 0)
  2879. {
  2880. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2881. {
  2882. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2883. }
  2884. }
  2885. }
  2886. }
  2887. }
  2888. else
  2889. {
  2890. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2891. {
  2892. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2893. {
  2894. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2895. 0:
  2896. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2897. }
  2898. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2899. {
  2900. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2901. {
  2902. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2903. 0:
  2904. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2905. if(idxPeriod > 0)
  2906. {
  2907. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2908. {
  2909. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2910. }
  2911. }
  2912. }
  2913. }
  2914. }
  2915. else
  2916. {
  2917. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2918. {
  2919. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2920. 0:
  2921. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2922. }
  2923. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2924. {
  2925. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2926. {
  2927. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2928. 0:
  2929. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2930. if(idxPeriod > 0)
  2931. {
  2932. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2933. {
  2934. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2935. }
  2936. }
  2937. }
  2938. }
  2939. }
  2940. }
  2941. /*
  2942. DEBUG_INFO("defaultTxProfile after align.\n");
  2943. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2944. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2945. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2946. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2947. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2948. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2949. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2950. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2951. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2952. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2953. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2954. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2955. {
  2956. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2957. {
  2958. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2959. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2960. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2961. }
  2962. }
  2963. DEBUG_INFO("------------------------------------\n");*/
  2964. }
  2965. if(maxProfile.ChargingProfileId != -1)
  2966. {
  2967. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2968. {
  2969. if(maxProfile.ChargingSchedule.Duration != -1)
  2970. {
  2971. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2972. 0:
  2973. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2974. }
  2975. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2976. {
  2977. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2978. {
  2979. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2980. 0:
  2981. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2982. if(idxPeriod > 0)
  2983. {
  2984. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2985. {
  2986. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2987. }
  2988. }
  2989. }
  2990. }
  2991. }
  2992. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2993. {
  2994. if(maxProfile.ChargingSchedule.Duration != -1)
  2995. {
  2996. 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?
  2997. 0:
  2998. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  2999. }
  3000. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3001. {
  3002. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3003. {
  3004. 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?
  3005. 0:
  3006. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3007. if(idxPeriod > 0)
  3008. {
  3009. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3010. {
  3011. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3012. }
  3013. }
  3014. }
  3015. }
  3016. }
  3017. else
  3018. {
  3019. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3020. {
  3021. if(maxProfile.ChargingSchedule.Duration != -1)
  3022. {
  3023. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3024. 0:
  3025. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3026. }
  3027. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3028. {
  3029. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3030. {
  3031. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3032. 0:
  3033. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3034. if(idxPeriod > 0)
  3035. {
  3036. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3037. {
  3038. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3039. }
  3040. }
  3041. }
  3042. }
  3043. }
  3044. else
  3045. {
  3046. if(maxProfile.ChargingSchedule.Duration != -1)
  3047. {
  3048. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3049. 0:
  3050. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3051. }
  3052. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3053. {
  3054. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3055. {
  3056. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3057. 0:
  3058. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3059. if(idxPeriod > 0)
  3060. {
  3061. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3062. {
  3063. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3064. }
  3065. }
  3066. }
  3067. }
  3068. }
  3069. }
  3070. /*
  3071. DEBUG_INFO("MaxProfile after align.\n");
  3072. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3073. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3074. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3075. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3076. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3077. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3078. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3079. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3080. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3081. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3082. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3083. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3084. {
  3085. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3086. {
  3087. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3088. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3089. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3090. }
  3091. }
  3092. DEBUG_INFO("------------------------------------\n");*/
  3093. }
  3094. /*
  3095. * Merge to conposite schedule
  3096. */
  3097. //DEBUG_INFO("====================================\n");
  3098. // Find each profile period quantity
  3099. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3100. {
  3101. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3102. limitMax = idx+1;
  3103. }
  3104. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3105. {
  3106. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3107. limitDef = idx+1;
  3108. }
  3109. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3110. {
  3111. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3112. limitTx = idx+1;
  3113. }
  3114. // TxProfile found, composite schedule based on it
  3115. if(txProfile.ChargingProfileId != -1)
  3116. {
  3117. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3118. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3119. {
  3120. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3121. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3122. (txProfile.ChargingSchedule.Duration > 0))
  3123. {
  3124. if(maxProfile.ChargingProfileId != -1)
  3125. {
  3126. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3127. {
  3128. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3129. {
  3130. if((maxProfile.ChargingSchedule.Duration > 0))
  3131. {
  3132. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3133. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3134. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3135. }
  3136. else
  3137. {
  3138. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3139. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3140. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3141. }
  3142. }
  3143. if(idxMaxPeriod == (limitMax-1))
  3144. {
  3145. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3146. {
  3147. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3148. {
  3149. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3150. compositePeriodIdx++;
  3151. }
  3152. else
  3153. {
  3154. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3155. }
  3156. }
  3157. }
  3158. }
  3159. }
  3160. else
  3161. {
  3162. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3163. {
  3164. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3165. compositePeriodIdx++;
  3166. }
  3167. else
  3168. {
  3169. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3170. }
  3171. }
  3172. }
  3173. if(idxTxPeriod == (limitTx-1))
  3174. {
  3175. if(defaultTxProfile.ChargingProfileId != -1)
  3176. {
  3177. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3178. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3179. {
  3180. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3181. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3182. (defaultTxProfile.ChargingSchedule.Duration>0))
  3183. {
  3184. if(maxProfile.ChargingProfileId != -1)
  3185. {
  3186. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3187. {
  3188. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3189. {
  3190. if((maxProfile.ChargingSchedule.Duration > 0))
  3191. {
  3192. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3193. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3194. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3195. }
  3196. else
  3197. {
  3198. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3199. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3200. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3201. }
  3202. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3203. {
  3204. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3205. {
  3206. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3207. compositePeriodIdx++;
  3208. }
  3209. else
  3210. {
  3211. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3212. }
  3213. }
  3214. // Delete duplicate period
  3215. if(compositePeriodIdx > 1)
  3216. {
  3217. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3218. {
  3219. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3220. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3221. compositePeriodIdx -= 1;
  3222. }
  3223. }
  3224. }
  3225. else
  3226. {
  3227. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3228. {
  3229. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3230. compositePeriodIdx++;
  3231. }
  3232. else
  3233. {
  3234. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3235. }
  3236. break;
  3237. }
  3238. }
  3239. }
  3240. else
  3241. {
  3242. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3243. {
  3244. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3245. compositePeriodIdx++;
  3246. }
  3247. else
  3248. {
  3249. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3250. }
  3251. }
  3252. }
  3253. }
  3254. }
  3255. }
  3256. }
  3257. }
  3258. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3259. else if(defaultTxProfile.ChargingProfileId != -1)
  3260. {
  3261. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3262. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3263. {
  3264. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3265. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3266. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3267. {
  3268. if(maxProfile.ChargingProfileId != -1)
  3269. {
  3270. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3271. {
  3272. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3273. {
  3274. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3275. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3276. if((maxProfile.ChargingSchedule.Duration > 0))
  3277. {
  3278. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3279. }
  3280. else
  3281. {
  3282. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3283. }
  3284. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3285. {
  3286. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3287. {
  3288. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3289. compositePeriodIdx++;
  3290. }
  3291. else
  3292. {
  3293. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3294. }
  3295. }
  3296. // Delete duplicate period
  3297. if(compositePeriodIdx > 1)
  3298. {
  3299. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3300. {
  3301. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3302. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3303. compositePeriodIdx -= 1;
  3304. }
  3305. }
  3306. }
  3307. else
  3308. {
  3309. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3310. {
  3311. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3312. compositePeriodIdx++;
  3313. }
  3314. else
  3315. {
  3316. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3317. }
  3318. break;
  3319. }
  3320. }
  3321. }
  3322. else
  3323. {
  3324. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3325. {
  3326. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3327. compositePeriodIdx++;
  3328. }
  3329. else
  3330. {
  3331. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3332. }
  3333. }
  3334. }
  3335. }
  3336. }
  3337. // Fill other period by MaxProfile
  3338. if(maxProfile.ChargingProfileId != -1)
  3339. {
  3340. if(compositePeriodIdx==0)
  3341. {
  3342. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3343. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3344. {
  3345. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3346. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3347. (maxProfile.ChargingSchedule.Duration > 0))
  3348. {
  3349. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3350. {
  3351. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3352. compositePeriodIdx++;
  3353. }
  3354. else
  3355. {
  3356. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3357. }
  3358. }
  3359. }
  3360. }
  3361. else
  3362. {
  3363. int lastCompositePeriodIdx = compositePeriodIdx;
  3364. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3365. {
  3366. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3367. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3368. (maxProfile.ChargingSchedule.Duration > 0))
  3369. {
  3370. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3371. {
  3372. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3373. {
  3374. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3375. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3376. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3377. }
  3378. else
  3379. {
  3380. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3381. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3382. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3383. }
  3384. }
  3385. if(tmpPeriod.Limit != -1)
  3386. {
  3387. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3388. {
  3389. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3390. {
  3391. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3392. compositePeriodIdx++;
  3393. }
  3394. else
  3395. {
  3396. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3397. }
  3398. }
  3399. // Delete duplicate period
  3400. if(compositePeriodIdx > 1)
  3401. {
  3402. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3403. {
  3404. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3405. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3406. compositePeriodIdx -= 1;
  3407. }
  3408. }
  3409. }
  3410. }
  3411. }
  3412. }
  3413. }
  3414. compositeProfile.ChargingSchedule.Duration = durationReq;
  3415. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3416. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3417. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  3418. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  3419. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3420. {
  3421. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3422. {
  3423. compositeProfile.ChargingProfileId = 1;
  3424. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3425. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3426. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3427. }
  3428. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3429. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3430. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3431. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3432. }
  3433. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  3434. if(line)
  3435. free(line);
  3436. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  3437. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3438. }
  3439. //==========================================
  3440. // Init all share memory
  3441. //==========================================
  3442. int InitShareMemory()
  3443. {
  3444. int result = PASS;
  3445. int MeterSMId;
  3446. //creat ShmSysConfigAndInfo
  3447. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3448. {
  3449. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3450. result = FAIL;
  3451. }
  3452. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3453. {
  3454. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3455. result = FAIL;
  3456. }
  3457. else
  3458. {}
  3459. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3460. {
  3461. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3462. result = FAIL;
  3463. }
  3464. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3465. {
  3466. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3467. result = FAIL;
  3468. }
  3469. else
  3470. {}
  3471. //creat ShmPsuData
  3472. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3473. {
  3474. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3475. result = FAIL;
  3476. }
  3477. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3478. {
  3479. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3480. result = FAIL;
  3481. }
  3482. else
  3483. {}
  3484. //link ShmOCPP16Data
  3485. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3486. {
  3487. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3488. result = FAIL;
  3489. }
  3490. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3491. {
  3492. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3493. result = FAIL;
  3494. }
  3495. else
  3496. {}
  3497. //creat ShmOCPP16DataPH
  3498. if ((MeterSMId = shmget(ShmOcppPHModuleKey, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  3499. {
  3500. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  3501. result = FAIL;
  3502. }
  3503. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3504. {
  3505. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  3506. result = FAIL;
  3507. }
  3508. else
  3509. {}
  3510. /****************************** For Initial Settings************************************************/
  3511. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  3512. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  3513. // allocate Configuration memory address
  3514. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  3515. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3516. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3517. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3518. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  3519. //offline MeterValue Interval
  3520. TempMeterValueInterval = 0;
  3521. return result;
  3522. }
  3523. int ProcessShareMemory()
  3524. {
  3525. int result = PASS;
  3526. if(InitShareMemory() == FAIL)
  3527. {
  3528. DEBUG_ERROR("InitShareMemory NG\n");
  3529. if(ShmStatusCodeData!=NULL)
  3530. {
  3531. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3532. }
  3533. result = FAIL;
  3534. }
  3535. // Model name parsing
  3536. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3537. {
  3538. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3539. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3540. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3541. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3542. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3543. ) // 'D' means DC
  3544. {
  3545. // DO series
  3546. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3547. {
  3548. gunTotalNumber += 1;
  3549. gunType[gun_index] = GUN_TYPE_DO;
  3550. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3551. {
  3552. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  3553. {
  3554. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3555. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  3556. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  3557. }
  3558. }
  3559. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3560. {
  3561. case Gun_Type_Chademo:
  3562. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3563. break;
  3564. case Gun_Type_CCS_2:
  3565. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3566. break;
  3567. case Gun_Type_GB:
  3568. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3569. break;
  3570. case Gun_Type_AC:
  3571. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3572. break;
  3573. default:
  3574. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3575. break;
  3576. }
  3577. }
  3578. }
  3579. else
  3580. {
  3581. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3582. {
  3583. gunTotalNumber += 1;
  3584. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3585. {
  3586. case Gun_Type_Chademo:
  3587. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3588. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3589. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  3590. {
  3591. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  3592. {
  3593. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  3594. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  3595. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  3596. }
  3597. }
  3598. break;
  3599. case Gun_Type_CCS_2:
  3600. gunType[gun_index] = GUN_TYPE_CCS;
  3601. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3602. for (int index = 0; index < CCS_QUANTITY; index++)
  3603. {
  3604. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  3605. {
  3606. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  3607. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  3608. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  3609. }
  3610. }
  3611. break;
  3612. case Gun_Type_GB:
  3613. gunType[gun_index] = GUN_TYPE_GBT;
  3614. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3615. for (int index = 0; index < GB_QUANTITY; index++)
  3616. {
  3617. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  3618. {
  3619. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  3620. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  3621. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  3622. }
  3623. }
  3624. break;
  3625. case Gun_Type_AC:
  3626. gunType[gun_index] = GUN_TYPE_AC;
  3627. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3628. for (int index = 0; index < AC_QUANTITY; index++)
  3629. {
  3630. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  3631. {
  3632. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  3633. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  3634. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  3635. }
  3636. }
  3637. break;
  3638. default:
  3639. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3640. break;
  3641. }
  3642. }
  3643. }
  3644. }
  3645. else
  3646. {
  3647. DEBUG_ERROR("Model name parsing fail.\n");
  3648. result = FAIL;
  3649. }
  3650. if(result != PASS)sleep(5);
  3651. return result;
  3652. }
  3653. void checkRemoteStart(uint8_t connectorIdInt)
  3654. {
  3655. uint8_t tempIndex;
  3656. int result = PASS;
  3657. char cmdBuf[512];
  3658. //check Transaction active
  3659. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3660. {
  3661. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3662. {
  3663. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3664. }
  3665. else
  3666. {
  3667. tempIndex = connectorIdInt -1;
  3668. }
  3669. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3670. {
  3671. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3672. {
  3673. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3674. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3675. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3676. {
  3677. //Reserved
  3678. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3679. }
  3680. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3681. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3682. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3683. {
  3684. //Reserved
  3685. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3686. result = FAIL;
  3687. goto end;
  3688. }
  3689. else
  3690. {
  3691. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3692. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3693. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3694. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3695. {
  3696. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  3697. result = FAIL;
  3698. goto end;
  3699. }
  3700. }//END FOR ELSE
  3701. }
  3702. }// END FOR CHAdeMO_QUANTITY
  3703. }
  3704. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3705. {
  3706. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3707. {
  3708. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3709. }
  3710. else
  3711. {
  3712. tempIndex = connectorIdInt -1;
  3713. }
  3714. for (int index = 0; index < CCS_QUANTITY; index++)
  3715. {
  3716. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3717. {
  3718. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3719. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3720. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3721. {
  3722. //Reserved
  3723. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3724. }
  3725. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3726. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3727. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3728. {
  3729. //Reserved
  3730. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3731. result = FAIL;
  3732. goto end;
  3733. }
  3734. else
  3735. {
  3736. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3737. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3738. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3739. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3740. {
  3741. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3742. result = FAIL;
  3743. goto end;
  3744. }
  3745. }// END FOR ELSE
  3746. }
  3747. }// END FOR CCS_QUANTITY
  3748. }
  3749. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3750. {
  3751. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3752. {
  3753. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3754. }
  3755. else
  3756. {
  3757. tempIndex = connectorIdInt -1;
  3758. }
  3759. for (int index = 0; index < GB_QUANTITY; index++)
  3760. {
  3761. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3762. {
  3763. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3764. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3765. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3766. {
  3767. //Reserved
  3768. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3769. }
  3770. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3771. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3772. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3773. {
  3774. //Reserved
  3775. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3776. result = FAIL;
  3777. goto end;
  3778. }
  3779. else
  3780. {
  3781. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3782. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3783. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3784. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3785. {
  3786. DEBUG_WARN("GBT connector not allow start cause busy.\n.");
  3787. result = FAIL;
  3788. goto end;
  3789. }
  3790. }// END FOR ELSE
  3791. }
  3792. } // END FOR GB_QUANTITY
  3793. }
  3794. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3795. {
  3796. tempIndex = connectorIdInt -1;
  3797. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3798. {
  3799. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3800. {
  3801. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3802. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3803. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3804. {
  3805. //Reserved
  3806. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3807. }
  3808. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3809. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3810. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3811. {
  3812. //Reserved
  3813. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3814. result = FAIL;
  3815. goto end;
  3816. }
  3817. else
  3818. {
  3819. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3820. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3821. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3822. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3823. {
  3824. DEBUG_WARN("Dispenser connector not allow start cause busy.\n.");
  3825. result = FAIL;
  3826. goto end;
  3827. }
  3828. }// END FOR ELSE
  3829. }
  3830. } // END FOR GB_QUANTITY
  3831. }
  3832. else
  3833. {
  3834. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3835. {
  3836. tempIndex = 2;
  3837. }
  3838. else
  3839. {
  3840. tempIndex = connectorIdInt -1;
  3841. }
  3842. for (int index = 0; index < AC_QUANTITY; index++)
  3843. {
  3844. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3845. {
  3846. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3847. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3848. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3849. {
  3850. //Reserved
  3851. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3852. }
  3853. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3854. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3855. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3856. {
  3857. //Reserved
  3858. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3859. result = FAIL;
  3860. goto end;
  3861. }
  3862. else
  3863. {
  3864. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3865. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3866. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3867. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3868. {
  3869. DEBUG_WARN("AC connector not allow start cause busy.\n.");
  3870. result = FAIL;
  3871. goto end;
  3872. }
  3873. }//END FOR ELSE
  3874. }
  3875. }// END FOR AC_QUANTITY
  3876. }
  3877. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3878. {
  3879. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3880. {
  3881. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3882. if((access("/Storage/OCPP_PH/TxProfile_Tmp.json", F_OK))!=-1)
  3883. {
  3884. sprintf(cmdBuf, "mv /Storage/OCPP_PH/TxProfile_Tmp.json /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  3885. system(cmdBuf);
  3886. }
  3887. }
  3888. else
  3889. {
  3890. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3891. result = FAIL;
  3892. }
  3893. }
  3894. end:
  3895. if(result == PASS)
  3896. {
  3897. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3898. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3899. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3900. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3901. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3902. }
  3903. }
  3904. void CheckSystemValue(void)
  3905. {
  3906. char filenmae[100]={0};
  3907. char str[100]={0};
  3908. int tempIndex = 0;
  3909. //===============================
  3910. // send Heartbeat
  3911. //===============================
  3912. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3913. {
  3914. //parameter for test
  3915. sendHeartbeatRequest(0);
  3916. //==============================================
  3917. // Reset Waiting Time
  3918. //==============================================
  3919. HeartBeatWithNOResponse += 2;
  3920. }
  3921. //===============================
  3922. // Credit deduct report
  3923. //===============================
  3924. if(ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq)
  3925. {
  3926. OCPP_insert_deduct_info(ShmOCPP16DataPH->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.creditNo,
  3927. ShmOCPP16DataPH->TcciCustomData.DeductInfo.deductResult, ShmOCPP16DataPH->TcciCustomData.DeductInfo.isDonateInvoice,
  3928. ShmOCPP16DataPH->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.vemData,
  3929. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.RRN,
  3930. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.storeId);
  3931. ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq = FALSE;
  3932. }
  3933. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  3934. {
  3935. OCPP_query_deduct_info();
  3936. refreshStartTimer(&clientTime.TcciQueryDeduct);
  3937. }
  3938. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3939. {
  3940. // ClockAlign MeterValue
  3941. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3942. {
  3943. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3944. {
  3945. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3946. {
  3947. tempIndex = ((gun_index==2) ? 1: 0);
  3948. }
  3949. else
  3950. {
  3951. tempIndex = gun_index;
  3952. }
  3953. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3954. {
  3955. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3956. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3957. {
  3958. reqClockAlignMeter[gun_index] = 1;
  3959. }
  3960. }// End for CHAdeMO
  3961. }
  3962. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3963. {
  3964. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3965. {
  3966. tempIndex = ((gun_index==2) ? 1: 0);
  3967. }
  3968. else
  3969. {
  3970. tempIndex = gun_index;
  3971. }
  3972. for (int index = 0; index < CCS_QUANTITY; index++)
  3973. {
  3974. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3975. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3976. {
  3977. reqClockAlignMeter[gun_index] = 1;
  3978. }
  3979. } // End for CCS
  3980. }
  3981. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3982. {
  3983. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3984. {
  3985. tempIndex = ((gun_index==2) ? 1: 0);
  3986. }
  3987. else
  3988. {
  3989. tempIndex = gun_index;
  3990. }
  3991. for (int index = 0; index < GB_QUANTITY; index++)
  3992. {
  3993. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3994. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3995. {
  3996. reqClockAlignMeter[gun_index] = 1;
  3997. }
  3998. }// End for GB
  3999. }
  4000. else if(gunType[gun_index] == GUN_TYPE_DO)
  4001. {
  4002. tempIndex = gun_index;
  4003. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4004. {
  4005. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4006. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4007. {
  4008. reqClockAlignMeter[gun_index] = 1;
  4009. }
  4010. }
  4011. }
  4012. else
  4013. {
  4014. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4015. {
  4016. tempIndex = 2;
  4017. }
  4018. else
  4019. {
  4020. tempIndex = gun_index;
  4021. }
  4022. for (int index = 0; index < AC_QUANTITY; index++)
  4023. {
  4024. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4025. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4026. {
  4027. reqClockAlignMeter[gun_index] = 1;
  4028. }
  4029. }//End for AC
  4030. }
  4031. }
  4032. }
  4033. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4034. {
  4035. //==========================================
  4036. // Check remote start without connector id
  4037. //==========================================
  4038. if(ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  4039. {
  4040. int connectorIdInt = -1;
  4041. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4042. {
  4043. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4044. {
  4045. connectorIdInt = (gun_index+1);
  4046. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4047. checkRemoteStart(connectorIdInt);
  4048. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  4049. break;
  4050. }
  4051. }
  4052. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4053. {
  4054. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4055. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  4056. }
  4057. }
  4058. //==========================================
  4059. // csu trigger DataTransferReq
  4060. //==========================================
  4061. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  4062. {
  4063. sendDataTransferRequest(gun_index);
  4064. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  4065. }
  4066. //===============================
  4067. // CSU Trigger Authorize Request
  4068. //===============================
  4069. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4070. {
  4071. sendAuthorizeRequest(0);
  4072. authorizeRetryTimes = authorizeRetryTimes + 1;
  4073. if(authorizeRetryTimes < 3)
  4074. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4075. }
  4076. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4077. {
  4078. authorizeRetryTimes = 0;
  4079. SetOcppConnStatus(FALSE);
  4080. server_sign = FALSE;
  4081. }
  4082. 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))
  4083. {
  4084. sendAuthorizeRequest(0);
  4085. }
  4086. //==============================================
  4087. // Charger start transaction
  4088. //==============================================
  4089. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4090. {
  4091. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4092. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  4093. sendStartTransactionRequest(gun_index);
  4094. refreshStartTimer(&clientTime.StartTransaction);
  4095. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4096. //storeTempStopTransaction(gun_index);
  4097. }
  4098. //==============================================
  4099. // Charger stop transaction
  4100. //==============================================
  4101. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4102. {
  4103. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4104. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  4105. sendStopTransactionRequest(gun_index);
  4106. refreshStartTimer(&clientTime.StopTransaction);
  4107. memset(&ShmOCPP16DataPH->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4108. }
  4109. //==============================================
  4110. // Charger status report
  4111. //==============================================
  4112. //--- Check Mode Change ---//
  4113. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4114. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4115. {
  4116. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4117. {
  4118. tempIndex = ((gun_index==2) ? 1: 0);
  4119. }
  4120. else
  4121. {
  4122. tempIndex = gun_index;
  4123. }
  4124. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4125. {
  4126. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4127. {
  4128. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4129. {
  4130. // Sent unplug message for California pricing logic
  4131. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4132. {
  4133. uint8_t ts[36];
  4134. getNowDatetime(ts);
  4135. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4136. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4137. if(strcmp((char*)dmsVersion, "2.0")==0)
  4138. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4139. else
  4140. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4141. sendUnplugByDataTransferRequest(gun_index);
  4142. interLock.isSentUnplug[gun_index] = 1;
  4143. }
  4144. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4145. {
  4146. interLock.isSentUnplug[gun_index] = 0;
  4147. }
  4148. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4149. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4150. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4151. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4152. {
  4153. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4154. if((access(filenmae,F_OK))!=-1)
  4155. {
  4156. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4157. sprintf(str,"rm -f %s",filenmae);
  4158. system(str);
  4159. }
  4160. }
  4161. }
  4162. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4163. #if 1 // for TempStopTransaction
  4164. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4165. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4166. {
  4167. checkTempStopTransaction(gun_index);
  4168. }
  4169. #endif
  4170. }
  4171. }
  4172. }
  4173. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4174. {
  4175. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4176. {
  4177. tempIndex = ((gun_index==2) ? 1: 0);
  4178. }
  4179. else
  4180. {
  4181. tempIndex = gun_index;
  4182. }
  4183. for (int index = 0; index < CCS_QUANTITY; index++)
  4184. {
  4185. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4186. {
  4187. if((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]*/ )
  4188. {
  4189. // Sent unplug message for California pricing logic
  4190. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4191. {
  4192. uint8_t ts[36];
  4193. getNowDatetime(ts);
  4194. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4195. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4196. if(strcmp((char*)dmsVersion, "2.0")==0)
  4197. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4198. else
  4199. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4200. sendUnplugByDataTransferRequest(gun_index);
  4201. interLock.isSentUnplug[gun_index] = 1;
  4202. }
  4203. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4204. {
  4205. interLock.isSentUnplug[gun_index] = 0;
  4206. }
  4207. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4208. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4209. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4210. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4211. {
  4212. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4213. if((access(filenmae,F_OK))!=-1)
  4214. {
  4215. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4216. sprintf(str,"rm -f %s",filenmae);
  4217. system(str);
  4218. }
  4219. }
  4220. }
  4221. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4222. #if 1 // for TempStopTransaction
  4223. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4224. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4225. {
  4226. checkTempStopTransaction(gun_index);
  4227. }
  4228. #endif
  4229. }
  4230. }
  4231. }
  4232. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4233. {
  4234. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4235. {
  4236. tempIndex = ((gun_index==2) ? 1: 0);
  4237. }
  4238. else
  4239. {
  4240. tempIndex = gun_index;
  4241. }
  4242. for (int index = 0; index < GB_QUANTITY; index++)
  4243. {
  4244. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4245. {
  4246. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4247. {
  4248. // Sent unplug message for California pricing logic
  4249. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4250. {
  4251. uint8_t ts[36];
  4252. getNowDatetime(ts);
  4253. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4254. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4255. if(strcmp((char*)dmsVersion, "2.0")==0)
  4256. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4257. else
  4258. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4259. sendUnplugByDataTransferRequest(gun_index);
  4260. interLock.isSentUnplug[gun_index] = 1;
  4261. }
  4262. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4263. {
  4264. interLock.isSentUnplug[gun_index] = 0;
  4265. }
  4266. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4267. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4268. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4269. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4270. {
  4271. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4272. if((access(filenmae,F_OK))!=-1)
  4273. {
  4274. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4275. sprintf(str,"rm -f %s",filenmae);
  4276. system(str);
  4277. }
  4278. }
  4279. }
  4280. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4281. #if 1 // for TempStopTransaction
  4282. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4283. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4284. {
  4285. checkTempStopTransaction(gun_index);
  4286. }
  4287. #endif
  4288. }
  4289. }
  4290. }
  4291. else if(gunType[gun_index] == GUN_TYPE_DO)
  4292. {
  4293. tempIndex = gun_index;
  4294. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4295. {
  4296. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4297. {
  4298. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4299. {
  4300. // Sent unplug message for California pricing logic
  4301. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  4302. {
  4303. uint8_t ts[36];
  4304. getNowDatetime(ts);
  4305. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4306. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4307. if(strcmp((char*)dmsVersion, "2.0")==0)
  4308. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4309. else
  4310. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4311. sendUnplugByDataTransferRequest(gun_index);
  4312. interLock.isSentUnplug[gun_index] = 1;
  4313. }
  4314. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  4315. {
  4316. interLock.isSentUnplug[gun_index] = 0;
  4317. }
  4318. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4319. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4320. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4321. 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
  4322. {
  4323. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4324. if((access(filenmae,F_OK))!=-1)
  4325. {
  4326. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4327. sprintf(str,"rm -f %s",filenmae);
  4328. system(str);
  4329. }
  4330. }
  4331. }
  4332. 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);
  4333. #if 1 // for TempStopTransaction
  4334. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4335. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4336. {
  4337. checkTempStopTransaction(gun_index);
  4338. }
  4339. #endif
  4340. }
  4341. }
  4342. }
  4343. else
  4344. {
  4345. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4346. {
  4347. tempIndex = 2;
  4348. }
  4349. else
  4350. {
  4351. tempIndex = gun_index;
  4352. }
  4353. for (int index = 0; index < AC_QUANTITY; index++)
  4354. {
  4355. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4356. {
  4357. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4358. {
  4359. // Sent unplug message for California pricing logic
  4360. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A) && !interLock.isSentUnplug[gun_index])
  4361. {
  4362. uint8_t ts[36];
  4363. getNowDatetime(ts);
  4364. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4365. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4366. if(strcmp((char*)dmsVersion, "2.0")==0)
  4367. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4368. else
  4369. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4370. sendUnplugByDataTransferRequest(gun_index);
  4371. interLock.isSentUnplug[gun_index] = 1;
  4372. }
  4373. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4374. {
  4375. interLock.isSentUnplug[gun_index] = 0;
  4376. }
  4377. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4378. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4379. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4380. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4381. {
  4382. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4383. if((access(filenmae,F_OK))!=-1)
  4384. {
  4385. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4386. sprintf(str,"rm -f %s",filenmae);
  4387. system(str);
  4388. }
  4389. }
  4390. }
  4391. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4392. #if 1 // for TempStopTransaction
  4393. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4394. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4395. {
  4396. checkTempStopTransaction(gun_index);
  4397. }
  4398. #endif
  4399. }
  4400. }// END
  4401. }
  4402. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) &&
  4403. (
  4404. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4405. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4406. )
  4407. )
  4408. {
  4409. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  4410. sendStatusNotificationRequest(gun_index);
  4411. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4412. }
  4413. //==============================================
  4414. // TCCI reader status report
  4415. //==============================================
  4416. if(ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1)
  4417. {
  4418. reportReaderStatus(gun_index);
  4419. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4420. }
  4421. //==============================================
  4422. // CSU Trigger Smart Charging Profile
  4423. //==============================================
  4424. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4425. {
  4426. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  4427. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4428. }
  4429. //==============================================
  4430. // Meter report
  4431. //==============================================
  4432. // Trigger MeterValue
  4433. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4434. {
  4435. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4436. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4437. }
  4438. // Clock-aligned Meter value
  4439. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4440. {
  4441. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4442. reqClockAlignMeter[gun_index] = 0;
  4443. }
  4444. // Sample period MeterValue
  4445. 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))))
  4446. {
  4447. //check Transaction active
  4448. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4449. {
  4450. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4451. {
  4452. tempIndex = ((gun_index==2) ? 1: 0);
  4453. }
  4454. else
  4455. {
  4456. tempIndex = gun_index;
  4457. }
  4458. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4459. {
  4460. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4461. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4462. {
  4463. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4464. {
  4465. reqSampleMeter[gun_index] = 1;
  4466. }
  4467. }
  4468. }// End for CHAdeMO
  4469. }
  4470. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4471. {
  4472. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4473. {
  4474. tempIndex = ((gun_index==2) ? 1: 0);
  4475. }
  4476. else
  4477. {
  4478. tempIndex = gun_index;
  4479. }
  4480. for (int index = 0; index < CCS_QUANTITY; index++)
  4481. {
  4482. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4483. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4484. {
  4485. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4486. {
  4487. reqSampleMeter[gun_index] = 1;
  4488. }
  4489. }
  4490. } // End for CCS
  4491. }
  4492. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4493. {
  4494. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4495. {
  4496. tempIndex = ((gun_index==2) ? 1: 0);
  4497. }
  4498. else
  4499. {
  4500. tempIndex = gun_index;
  4501. }
  4502. for (int index = 0; index < GB_QUANTITY; index++)
  4503. {
  4504. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4505. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4506. {
  4507. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4508. {
  4509. reqSampleMeter[gun_index] = 1;
  4510. }
  4511. }
  4512. }// End for GB
  4513. }
  4514. else if(gunType[gun_index] == GUN_TYPE_DO)
  4515. {
  4516. tempIndex = gun_index;
  4517. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4518. {
  4519. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4520. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4521. {
  4522. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4523. {
  4524. reqSampleMeter[gun_index] = 1;
  4525. }
  4526. }
  4527. }
  4528. }
  4529. else
  4530. {
  4531. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4532. {
  4533. tempIndex = 2;
  4534. }
  4535. else
  4536. {
  4537. tempIndex = gun_index;
  4538. }
  4539. for (int index = 0; index < AC_QUANTITY; index++)
  4540. {
  4541. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4542. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4543. {
  4544. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4545. {
  4546. reqSampleMeter[gun_index] = 1;
  4547. }
  4548. }
  4549. }//End for AC
  4550. }
  4551. if(reqSampleMeter[gun_index] == 1)
  4552. {
  4553. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4554. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4555. //storeTempStopTransaction(gun_index);
  4556. reqSampleMeter[gun_index] = 0;
  4557. }
  4558. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4559. }
  4560. //==============================================
  4561. // Check Connector reserved
  4562. //==============================================
  4563. //===============================
  4564. // Check if Reserve is expired
  4565. //===============================
  4566. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  4567. {
  4568. double diff_t;
  4569. struct tm tp;
  4570. // current time
  4571. time_t t = time(NULL);
  4572. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  4573. tp.tm_isdst = -1;
  4574. time_t utc = mktime(&tp);
  4575. diff_t = difftime(utc, t);
  4576. if(diff_t <= 0)
  4577. {
  4578. DEBUG_INFO("reserve expired.\n");
  4579. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  4580. }
  4581. }//END OF Check if Reserve is expired
  4582. //==========================================
  4583. // csu trigger FirmwareStatusNotificationReq
  4584. //==========================================
  4585. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4586. {
  4587. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  4588. }
  4589. //==========================================
  4590. // csu trigger DiagnosticsStatusNotificationReq
  4591. //==========================================
  4592. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4593. {
  4594. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  4595. }
  4596. //==========================================
  4597. // csu trigger CancelReservationConf
  4598. //==========================================
  4599. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4600. {
  4601. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  4602. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4603. }
  4604. //==========================================
  4605. // csu trigger ChangeAvailabilityConf
  4606. //==========================================
  4607. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4608. {
  4609. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  4610. }
  4611. //==========================================
  4612. // csu trigger UnlockConnectorConf
  4613. //==========================================
  4614. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4615. {
  4616. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  4617. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4618. }
  4619. //==========================================
  4620. // csu trigger ReserveNowConf
  4621. //==========================================
  4622. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4623. {
  4624. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  4625. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4626. }
  4627. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  4628. {
  4629. sendSignCertificateRequest();
  4630. }
  4631. }
  4632. }
  4633. //==========================================
  4634. // send request routine
  4635. //==========================================
  4636. int sendAuthorizeRequest(int gun_index)
  4637. {
  4638. mtrace();
  4639. int result = FAIL;
  4640. char message[100]={0};
  4641. char guid[37];
  4642. char tempdata[65]={0};
  4643. DEBUG_INFO("sendAuthorizeRequest...\n");
  4644. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4645. //Local Authorize
  4646. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  4647. {
  4648. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4649. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4650. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4651. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4652. result = PASS;
  4653. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4654. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4655. authorizeRetryTimes = 0;
  4656. return result;
  4657. }
  4658. 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))||
  4659. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4660. {
  4661. // Query from cache
  4662. DEBUG_INFO("Authorize from cache.\n");
  4663. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4664. // Query from list
  4665. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4666. {
  4667. DEBUG_INFO("Authorize from list.\n");
  4668. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4669. }
  4670. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4671. {
  4672. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4673. {
  4674. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4675. }
  4676. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4677. {
  4678. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4679. }
  4680. if(!GetOcppConnStatus())
  4681. {
  4682. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4683. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4684. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4685. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4686. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4687. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4688. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4689. authorizeRetryTimes = 0;
  4690. return result;
  4691. }
  4692. }
  4693. else
  4694. {
  4695. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4696. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4697. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4698. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4699. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  4700. else
  4701. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4702. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4703. result = PASS;
  4704. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4705. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4706. authorizeRetryTimes = 0;
  4707. return result;
  4708. }
  4709. }
  4710. //initialize struct Authorize
  4711. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  4712. //get data from shared memory
  4713. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4714. random_uuid(guid);
  4715. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  4716. LWS_Send(message);
  4717. sprintf(tempdata, "Authorize,%d", gun_index);
  4718. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4719. {
  4720. result = PASS;
  4721. DEBUG_INFO("Authorize mapItem pass\n");
  4722. }
  4723. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4724. return result;
  4725. }
  4726. int sendBootNotificationRequest(void)
  4727. {
  4728. mtrace();
  4729. int result = FAIL;
  4730. char message[500]={0}, payload[700]={0};
  4731. char guid[37]={0};
  4732. char tempdata[65]={0};
  4733. // Fill BootNotification fields
  4734. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  4735. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4736. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4737. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4738. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4739. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4740. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4741. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4742. ShmOCPP16DataPH->ChargeBoxId
  4743. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4744. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4745. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4746. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  4747. ,ShmOCPP16DataPH->BootNotification.CpIccid
  4748. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  4749. random_uuid(guid);
  4750. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4751. LWS_Send(message);
  4752. sprintf(tempdata, "BootNotification,0");
  4753. 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*/)
  4754. {
  4755. result = PASS;
  4756. }
  4757. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4758. strcpy(queuedata,message);
  4759. return result;
  4760. }
  4761. int sendDataTransferRequest(int gun_index)
  4762. {
  4763. mtrace();
  4764. char message[1000]={0};
  4765. char guid[37]={0};
  4766. char tempdata[65]={0};
  4767. int result = FAIL;
  4768. random_uuid(guid);
  4769. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4770. MESSAGE_TYPE_CALL,
  4771. guid,
  4772. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4773. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4774. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4775. LWS_Send(message);
  4776. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4777. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4778. {
  4779. result = PASS;
  4780. DEBUG_INFO("DataTransfer mapItem pass\n");
  4781. }
  4782. return result;
  4783. }
  4784. int sendUnplugByDataTransferRequest(int gun_index)
  4785. {
  4786. mtrace();
  4787. char message[1000]={0};
  4788. char guid[37]={0};
  4789. char tempdata[65]={0};
  4790. int result = FAIL;
  4791. random_uuid(guid);
  4792. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4793. (gun_index+1),
  4794. MESSAGE_TYPE_CALL,
  4795. guid,
  4796. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4797. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4798. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4799. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4800. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4801. {
  4802. result = PASS;
  4803. DEBUG_INFO("DataTransfer mapItem pass\n");
  4804. }
  4805. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  4806. return result;
  4807. }
  4808. int sendDiagnosticsStatusNotificationRequest(char *status)
  4809. {
  4810. mtrace();
  4811. int result = FAIL;
  4812. char message[110]={0};
  4813. char guid[37]={0};
  4814. char tempdata[65]={0};
  4815. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4816. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4817. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4818. random_uuid(guid);
  4819. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4820. LWS_SendNow(message);
  4821. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4822. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4823. {
  4824. result = PASS;
  4825. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4826. }
  4827. //#ifdef SystemLogMessage
  4828. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4829. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4830. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4831. //#endif
  4832. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4833. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4834. //record status
  4835. if(strcmp(status,"Idle")==0)
  4836. {
  4837. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4838. }
  4839. else if(strcmp(status,"Uploaded")==0)
  4840. {
  4841. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4842. }
  4843. else if(strcmp(status,"UploadFailed")==0)
  4844. {
  4845. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4846. }
  4847. else if(strcmp(status,"Uploading")==0)
  4848. {
  4849. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4850. }
  4851. return result;
  4852. }
  4853. int sendFirmwareStatusNotificationRequest(char *status)
  4854. {
  4855. mtrace();
  4856. int result = FAIL;
  4857. char message[110]={0};
  4858. char guid[37]={0};
  4859. char tempdata[65]={0};
  4860. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4861. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4862. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4863. random_uuid(guid);
  4864. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4865. LWS_SendNow(message);
  4866. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4867. 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*/)
  4868. {
  4869. result = PASS;
  4870. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4871. }
  4872. //#ifdef SystemLogMessage
  4873. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4874. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4875. //#endif
  4876. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4877. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4878. //record status
  4879. if(strcmp(status,"Downloaded")==0)
  4880. {
  4881. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4882. }
  4883. else if(strcmp(status,"DownloadFailed")==0)
  4884. {
  4885. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4886. }
  4887. else if(strcmp(status,"Downloading")==0)
  4888. {
  4889. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4890. }
  4891. else if(strcmp(status,"Idle")==0)
  4892. {
  4893. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4894. }
  4895. else if(strcmp(status,"InstallationFailed")==0)
  4896. {
  4897. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4898. }
  4899. else if(strcmp(status,"Installing")==0)
  4900. {
  4901. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4902. }
  4903. else if(strcmp(status,"Installed")==0)
  4904. {
  4905. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4906. }
  4907. return result;
  4908. }
  4909. int sendHeartbeatRequest(int gun_index)
  4910. {
  4911. mtrace();
  4912. int result = FAIL;
  4913. char message[80]={0};
  4914. char guid[37]={0};
  4915. char tempdata[65]={0};
  4916. random_uuid(guid);
  4917. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4918. , MESSAGE_TYPE_CALL
  4919. , guid );
  4920. LWS_Send(message);
  4921. sprintf(tempdata, "Heartbeat,%d", 0);
  4922. 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*/)
  4923. {
  4924. result = PASS;
  4925. }
  4926. return result;
  4927. }
  4928. int sendStartTransactionRequest(int gun_index)
  4929. {
  4930. mtrace();
  4931. int result = FAIL;
  4932. char message[250]={0};
  4933. char guid[37]={0};
  4934. struct timeval tmnow;
  4935. struct tm *tm;
  4936. char buf[28];//, usec_buf[6];
  4937. char tempdata[65]={0};
  4938. int tempIndex = 0;
  4939. DEBUG_INFO("sendStartTransactionRequest...\n");
  4940. gettimeofday(&tmnow, NULL);
  4941. time_t t;
  4942. t = time(NULL);
  4943. /*UTC time and date*/
  4944. tm = gmtime(&t);
  4945. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4946. #if 0 // remove temporally
  4947. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4948. strcat(buf,".");
  4949. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4950. strcat(buf,usec_buf);
  4951. #endif
  4952. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4953. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4954. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4955. // clear StartTransaction Response
  4956. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4957. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4958. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4959. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4960. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4961. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4962. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4963. {
  4964. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4965. {
  4966. tempIndex = ((gun_index==2) ? 1: 0);
  4967. }
  4968. else
  4969. {
  4970. tempIndex = gun_index;
  4971. }
  4972. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4973. {
  4974. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4975. {
  4976. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4977. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4978. }
  4979. }
  4980. }
  4981. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4982. {
  4983. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4984. {
  4985. tempIndex = ((gun_index==2) ? 1: 0);
  4986. }
  4987. else
  4988. {
  4989. tempIndex = gun_index;
  4990. }
  4991. for (int index = 0; index < CCS_QUANTITY; index++)
  4992. {
  4993. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4994. {
  4995. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4996. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4997. }
  4998. }
  4999. }
  5000. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5001. {
  5002. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5003. {
  5004. tempIndex = ((gun_index==2) ? 1: 0);
  5005. }
  5006. else
  5007. {
  5008. tempIndex = gun_index;
  5009. }
  5010. for (int index = 0; index < GB_QUANTITY; index++)
  5011. {
  5012. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5013. {
  5014. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5015. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  5016. }
  5017. }
  5018. }
  5019. else if(gunType[gun_index] == GUN_TYPE_DO)
  5020. {
  5021. tempIndex = gun_index;
  5022. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5023. {
  5024. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5025. {
  5026. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5027. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5028. }
  5029. }
  5030. }
  5031. else
  5032. {
  5033. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5034. {
  5035. tempIndex = 2;
  5036. }
  5037. else
  5038. {
  5039. tempIndex = gun_index;
  5040. }
  5041. for (int index = 0; index < AC_QUANTITY; index++)
  5042. {
  5043. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5044. {
  5045. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5046. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5047. }
  5048. }
  5049. }
  5050. random_uuid(guid);
  5051. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5052. {
  5053. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5054. , gun_index +1
  5055. , MESSAGE_TYPE_CALL
  5056. , guid
  5057. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  5058. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  5059. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  5060. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  5061. }
  5062. else
  5063. {
  5064. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5065. , gun_index +1
  5066. , MESSAGE_TYPE_CALL
  5067. , guid
  5068. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  5069. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  5070. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  5071. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  5072. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  5073. }
  5074. #if 1
  5075. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5076. 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*/)
  5077. {
  5078. result = PASS;
  5079. }
  5080. #endif
  5081. strcpy(queuedata, message);
  5082. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5083. OCPP_insert_transaction_msg(YES, queuedata);
  5084. return result;
  5085. }
  5086. int sendStatusNotificationRequest(int gun_index)
  5087. {
  5088. mtrace();
  5089. int result = FAIL;
  5090. char message[600]={0};
  5091. char guid[37];
  5092. int currentStatus = 0;
  5093. struct timeval tmnow;
  5094. struct tm *tm;
  5095. char buf[28];//, usec_buf[6];
  5096. char tempdata[65]={0};
  5097. int tempIndex = 0;
  5098. uint8_t isStateChanged = TRUE;
  5099. uint8_t isContentIllegal = TRUE;
  5100. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5101. gettimeofday(&tmnow, NULL);
  5102. time_t t;
  5103. t = time(NULL);
  5104. /*UTC time and date*/
  5105. tm = gmtime(&t);
  5106. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5107. #if 0 // remove temporally
  5108. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5109. strcat(buf,".");
  5110. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5111. strcat(buf,usec_buf);
  5112. #endif
  5113. //printf("%s",buf);
  5114. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5115. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5116. // it's option
  5117. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  5118. /*
  5119. enum _SYSTEM_STATUS
  5120. {
  5121. S_BOOTING = 0,
  5122. S_IDLE, = 1
  5123. S_AUTHORIZING, =2
  5124. S_REASSIGN_CHECK, =3
  5125. S_REASSIGN, =4
  5126. S_PRECHARGE, =5
  5127. S_PREPARING_FOR_EV, =6
  5128. S_PREPARING_FOR_EVSE, =7
  5129. S_CHARGING, =8
  5130. S_TERMINATING, =9
  5131. S_COMPLETE, =10
  5132. S_ALARM, =11
  5133. S_FAULT =12
  5134. }
  5135. */
  5136. //check Transaction active
  5137. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5138. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5139. {
  5140. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5141. {
  5142. tempIndex = ((gun_index==2) ? 1: 0);
  5143. }
  5144. else
  5145. {
  5146. tempIndex = gun_index;
  5147. }
  5148. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5149. {
  5150. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5151. {
  5152. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5153. {
  5154. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5155. {
  5156. currentStatus = Preparing; //OCPP Status: Preparing
  5157. }
  5158. else
  5159. {
  5160. currentStatus = Available; //OCPP Status: Available
  5161. }
  5162. }
  5163. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5164. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5165. ) //S_PRECHARGE
  5166. {
  5167. currentStatus = Preparing; //OCPP Status: Preparing
  5168. }
  5169. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5170. {
  5171. currentStatus = Charging; //OCPP Status: Charging
  5172. }
  5173. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5174. {
  5175. currentStatus = Finishing; //OCPP Status: Finishing
  5176. }
  5177. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5178. {
  5179. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5180. }
  5181. 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
  5182. {
  5183. currentStatus = Unavailable; //OCPP Status: Unavailable
  5184. }
  5185. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5186. {
  5187. currentStatus = Faulted; //OCPP Status: Faulted
  5188. }
  5189. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5190. {
  5191. currentStatus = Reserved; //OCPP Status: Reserved
  5192. }
  5193. } //end of the same index
  5194. }//end of for CHAdeMO_QUANTITY
  5195. }
  5196. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5197. {
  5198. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5199. {
  5200. tempIndex = ((gun_index==2) ? 1: 0);
  5201. }
  5202. else
  5203. {
  5204. tempIndex = gun_index;
  5205. }
  5206. for (int index = 0; index < CCS_QUANTITY; index++)
  5207. {
  5208. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5209. {
  5210. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5211. {
  5212. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5213. {
  5214. currentStatus = Preparing; //OCPP Status: Preparing
  5215. }
  5216. else
  5217. {
  5218. currentStatus = Available; //OCPP Status: Available
  5219. }
  5220. }
  5221. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5222. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5223. ) //S_PRECHARGE
  5224. {
  5225. currentStatus = Preparing; //OCPP Status: Preparing
  5226. }
  5227. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5228. {
  5229. currentStatus = Charging; //OCPP Status: Charging
  5230. }
  5231. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5232. {
  5233. currentStatus = Finishing; //OCPP Status: Finishing
  5234. }
  5235. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5236. {
  5237. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5238. }
  5239. 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
  5240. {
  5241. currentStatus = Unavailable; //OCPP Status : Unavailable
  5242. }
  5243. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5244. {
  5245. currentStatus = Faulted; //OCPP Status: Faulted
  5246. }
  5247. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5248. {
  5249. currentStatus = Reserved; //OCPP Status: Reserved
  5250. }
  5251. } //end of the same index
  5252. } // end of for CCS_QUANTITY
  5253. }
  5254. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5255. {
  5256. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5257. {
  5258. tempIndex = ((gun_index==2) ? 1: 0);
  5259. }
  5260. else
  5261. {
  5262. tempIndex = gun_index;
  5263. }
  5264. for (int index = 0; index < GB_QUANTITY; index++)
  5265. {
  5266. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5267. {
  5268. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5269. {
  5270. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5271. {
  5272. currentStatus = Preparing; //OCPP Status: Preparing
  5273. }
  5274. else
  5275. {
  5276. currentStatus = Available; //OCPP Status: Available
  5277. }
  5278. }
  5279. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5280. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5281. ) //S_PRECHARGE
  5282. {
  5283. currentStatus = Preparing; //OCPP Status: Preparing
  5284. }
  5285. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5286. {
  5287. currentStatus = Charging; //OCPP Status: Charging
  5288. }
  5289. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5290. {
  5291. currentStatus = Finishing; //OCPP Status: Finishing
  5292. }
  5293. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5294. {
  5295. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5296. }
  5297. 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
  5298. {
  5299. currentStatus = Unavailable; //OCPP Status: Unavailable
  5300. }
  5301. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5302. {
  5303. currentStatus = Faulted; //OCPP Status: Faulted
  5304. }
  5305. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5306. {
  5307. currentStatus = Reserved; //OCPP Status: Reserved
  5308. }
  5309. } //end of the same index
  5310. } // end of for GB_QUANTITY
  5311. }
  5312. else if(gunType[gun_index] == GUN_TYPE_DO)
  5313. {
  5314. tempIndex = gun_index;
  5315. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5316. {
  5317. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5318. {
  5319. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5320. {
  5321. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5322. {
  5323. currentStatus = Preparing; //OCPP Status: Preparing
  5324. }
  5325. else
  5326. {
  5327. currentStatus = Available; //OCPP Status: Available
  5328. }
  5329. }
  5330. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5331. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5332. ) //S_PRECHARGE
  5333. {
  5334. currentStatus = Preparing; //OCPP Status: Preparing
  5335. }
  5336. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5337. {
  5338. currentStatus = Charging; //OCPP Status: Charging
  5339. }
  5340. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5341. {
  5342. currentStatus = Finishing; //OCPP Status: Finishing
  5343. }
  5344. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5345. {
  5346. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5347. }
  5348. 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
  5349. {
  5350. currentStatus = Unavailable; //OCPP Status: Unavailable
  5351. }
  5352. 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
  5353. {
  5354. currentStatus = Faulted; //OCPP Status: Faulted
  5355. }
  5356. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5357. {
  5358. currentStatus = Reserved; //OCPP Status: Reserved
  5359. }
  5360. } //end of the same index
  5361. }
  5362. }
  5363. else
  5364. {
  5365. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5366. {
  5367. tempIndex = 2;
  5368. }
  5369. else
  5370. {
  5371. tempIndex = gun_index;
  5372. }
  5373. for (int index = 0; index < AC_QUANTITY; index++)
  5374. {
  5375. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5376. {
  5377. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5378. {
  5379. 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))
  5380. {
  5381. currentStatus = Preparing; //OCPP Status: Preparing
  5382. }
  5383. else
  5384. {
  5385. currentStatus = Available; //OCPP Status: Available
  5386. }
  5387. }
  5388. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5389. {
  5390. currentStatus = Preparing; //OCPP Status: Preparing
  5391. }
  5392. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5393. {
  5394. currentStatus = Charging; //OCPP Status: Charging
  5395. }
  5396. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5397. {
  5398. currentStatus = Finishing; //OCPP Status: Finishing
  5399. }
  5400. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5401. {
  5402. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5403. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5404. else
  5405. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5406. }
  5407. 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
  5408. {
  5409. currentStatus = Unavailable; //OCPP Status: Unavailable
  5410. }
  5411. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5412. {
  5413. currentStatus = Faulted; //OCPP Status: Faulted
  5414. }
  5415. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5416. {
  5417. currentStatus = Reserved; //OCPP Status: Reserved
  5418. }
  5419. }//end of the same index
  5420. }//end of for AC_QUANTITY
  5421. }
  5422. //it's option
  5423. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5424. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5425. (strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5426. {
  5427. isStateChanged = FALSE;
  5428. }
  5429. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5430. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  5431. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5432. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5433. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  5434. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  5435. isContentIllegal = TRUE;
  5436. for(int index = 0; index < ARRAY_SIZE(ChargePointErrorCodeStr); index++)
  5437. {
  5438. if(strcmp((char *)ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[index])==0)
  5439. {
  5440. isContentIllegal = FALSE;
  5441. break;
  5442. }
  5443. }
  5444. if(isContentIllegal)
  5445. {
  5446. //DEBUG_WARN("Detect illegal ErrorCode: %s \n",(char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  5447. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[6]);
  5448. }
  5449. random_uuid(guid);
  5450. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5451. , MESSAGE_TYPE_CALL
  5452. , guid
  5453. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  5454. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  5455. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  5456. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  5457. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  5458. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  5459. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  5460. if((server_sign == TRUE) && isStateChanged)
  5461. {
  5462. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5463. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5464. LWS_Send(message);
  5465. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5466. 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*/)
  5467. {
  5468. //DEBUG_ERROR("statusNotification mapitem pass");
  5469. result = PASS;
  5470. }
  5471. }
  5472. else
  5473. {
  5474. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5475. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5476. result = PASS;
  5477. }
  5478. return result;
  5479. }
  5480. int sendStopTransactionRequest(int gun_index)
  5481. {
  5482. mtrace();
  5483. int result = FAIL;
  5484. //char message[1500]={0};
  5485. char guid[37]={0};
  5486. char tempdata[65]={0};
  5487. int tempIndex = 0;
  5488. char TempStopTransaction[256];
  5489. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  5490. //int idx_sample=0;
  5491. DEBUG_INFO("sendStopTransactionRequest \n");
  5492. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5493. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  5494. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5495. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5496. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5497. {
  5498. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5499. {
  5500. tempIndex = ((gun_index==2) ? 1: 0);
  5501. }
  5502. else
  5503. {
  5504. tempIndex = gun_index;
  5505. }
  5506. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5507. {
  5508. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5509. {
  5510. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5511. }
  5512. }// END OF CHAdeMO_QUANTITY
  5513. }
  5514. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5515. {
  5516. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5517. {
  5518. tempIndex = ((gun_index==2) ? 1: 0);
  5519. }
  5520. else
  5521. {
  5522. tempIndex = gun_index;
  5523. }
  5524. for (int index = 0; index < CCS_QUANTITY; index++)
  5525. {
  5526. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5527. {
  5528. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5529. }
  5530. }// END OF CCS_QUANTITY
  5531. }
  5532. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5533. {
  5534. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5535. {
  5536. tempIndex = ((gun_index==2) ? 1: 0);
  5537. }
  5538. else
  5539. {
  5540. tempIndex = gun_index;
  5541. }
  5542. for (int index = 0; index < GB_QUANTITY; index++)
  5543. {
  5544. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5545. {
  5546. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5547. }
  5548. }// END OF GB_QUANTITY
  5549. }
  5550. else if(gunType[gun_index] == GUN_TYPE_DO)
  5551. {
  5552. tempIndex = gun_index;
  5553. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5554. {
  5555. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5556. {
  5557. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5558. }
  5559. }// END OF GB_QUANTITY
  5560. }
  5561. else
  5562. {
  5563. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5564. {
  5565. tempIndex = 2;
  5566. }
  5567. else
  5568. {
  5569. tempIndex = gun_index;
  5570. }
  5571. for (int index = 0; index < AC_QUANTITY; index++)
  5572. {
  5573. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5574. {
  5575. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5576. }
  5577. }// END OF AC_QUANTITY
  5578. }
  5579. //====================================== Stop Transaction Time =====================================================
  5580. struct timeval tmnow;
  5581. struct tm *tm;
  5582. char buf[28];//, usec_buf[6];
  5583. gettimeofday(&tmnow, NULL);
  5584. time_t t;
  5585. t = time(NULL);
  5586. /*UTC time and date*/
  5587. tm = gmtime(&t);
  5588. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5589. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  5590. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  5591. random_uuid(guid);
  5592. /***********************************transactionData******************************************************/
  5593. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5594. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5595. //=================================
  5596. // Transaction_Begin
  5597. //=================================
  5598. //=================================
  5599. // Transaction_End
  5600. //=================================
  5601. // ================================= Current.Import L1 ===============================================
  5602. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5603. {
  5604. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5605. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5606. {
  5607. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5608. {
  5609. tempIndex = ((gun_index==2) ? 1: 0);
  5610. }
  5611. else
  5612. {
  5613. tempIndex = gun_index;
  5614. }
  5615. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5616. {
  5617. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5618. {
  5619. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5620. }
  5621. }// End of for CHAdeMO_QUANTITY
  5622. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5623. }
  5624. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5625. {
  5626. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5627. {
  5628. tempIndex = ((gun_index==2) ? 1: 0);
  5629. }
  5630. else
  5631. {
  5632. tempIndex = gun_index;
  5633. }
  5634. for (int index = 0; index < CCS_QUANTITY; index++)
  5635. {
  5636. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5637. {
  5638. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5639. }
  5640. }// End of for CCS_QUANTITY
  5641. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5642. }
  5643. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5644. {
  5645. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5646. {
  5647. tempIndex = ((gun_index==2) ? 1: 0);
  5648. }
  5649. else
  5650. {
  5651. tempIndex = gun_index;
  5652. }
  5653. for (int index = 0; index < GB_QUANTITY; index++)
  5654. {
  5655. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5656. {
  5657. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5658. }
  5659. }// End of for GB_QUANTITY
  5660. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5661. }
  5662. else if(gunType[gun_index] == GUN_TYPE_DO)
  5663. {
  5664. tempIndex = gun_index;
  5665. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5666. {
  5667. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5668. {
  5669. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5670. }
  5671. }
  5672. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5673. }
  5674. else
  5675. {
  5676. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5677. {
  5678. tempIndex = 2;
  5679. }
  5680. else
  5681. {
  5682. tempIndex = gun_index;
  5683. }
  5684. for (int index = 0; index < AC_QUANTITY; index++)
  5685. {
  5686. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5687. {
  5688. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5689. }
  5690. }// End of for AC_QUANTITY
  5691. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5692. }
  5693. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5694. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5695. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5696. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5697. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5698. }
  5699. // ================================= Energy.Active.Import.Interval ==============================================
  5700. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5701. {
  5702. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5703. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5704. {
  5705. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5706. {
  5707. tempIndex = ((gun_index==2) ? 1: 0);
  5708. }
  5709. else
  5710. {
  5711. tempIndex = gun_index;
  5712. }
  5713. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5714. {
  5715. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5716. {
  5717. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5718. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  5719. }
  5720. }// END OF CHAdeMO_QUANTITY
  5721. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5722. }
  5723. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5724. {
  5725. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5726. {
  5727. tempIndex = ((gun_index==2) ? 1: 0);
  5728. }
  5729. else
  5730. {
  5731. tempIndex = gun_index;
  5732. }
  5733. for (int index = 0; index < CCS_QUANTITY; index++)
  5734. {
  5735. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5736. {
  5737. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5738. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5739. }
  5740. }// END OF CCS_QUANTITY
  5741. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5742. }
  5743. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5744. {
  5745. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5746. {
  5747. tempIndex = ((gun_index==2) ? 1: 0);
  5748. }
  5749. else
  5750. {
  5751. tempIndex = gun_index;
  5752. }
  5753. for (int index = 0; index < GB_QUANTITY; index++)
  5754. {
  5755. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5756. {
  5757. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5758. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5759. }
  5760. }// END OF GB_QUANTITY
  5761. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5762. }
  5763. else if(gunType[gun_index] == GUN_TYPE_DO)
  5764. {
  5765. tempIndex = gun_index;
  5766. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5767. {
  5768. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5769. {
  5770. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5771. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5772. }
  5773. }
  5774. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5775. }
  5776. else
  5777. {
  5778. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5779. {
  5780. tempIndex = 2;
  5781. }
  5782. else
  5783. {
  5784. tempIndex = gun_index;
  5785. }
  5786. for (int index = 0; index < AC_QUANTITY; index++)
  5787. {
  5788. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5789. {
  5790. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  5791. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5792. }
  5793. }// END OF AC_QUANTITY
  5794. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5795. }
  5796. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5797. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5798. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5799. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5800. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5801. }
  5802. //=================================== Power.Active.Import ==================================================
  5803. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5804. {
  5805. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5806. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5807. {
  5808. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5809. {
  5810. tempIndex = ((gun_index==2) ? 1: 0);
  5811. }
  5812. else
  5813. {
  5814. tempIndex = gun_index;
  5815. }
  5816. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5817. {
  5818. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5819. {
  5820. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5821. }
  5822. } // End for CHAdeMO_QUANTITY
  5823. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5824. }
  5825. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5826. {
  5827. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5828. {
  5829. tempIndex = ((gun_index==2) ? 1: 0);
  5830. }
  5831. else
  5832. {
  5833. tempIndex = gun_index;
  5834. }
  5835. for (int index = 0; index < CCS_QUANTITY; index++)
  5836. {
  5837. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5838. {
  5839. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5840. }
  5841. } // END for CCS_QUANTITY
  5842. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5843. }
  5844. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5845. {
  5846. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5847. {
  5848. tempIndex = ((gun_index==2) ? 1: 0);
  5849. }
  5850. else
  5851. {
  5852. tempIndex = gun_index;
  5853. }
  5854. for (int index = 0; index < GB_QUANTITY; index++)
  5855. {
  5856. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5857. {
  5858. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5859. }
  5860. }// END for GB_QUANTITY
  5861. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5862. }
  5863. else if(gunType[gun_index] == GUN_TYPE_DO)
  5864. {
  5865. tempIndex = gun_index;
  5866. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5867. {
  5868. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5869. {
  5870. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5871. }
  5872. }
  5873. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5874. }
  5875. else
  5876. {
  5877. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5878. {
  5879. tempIndex = 2;
  5880. }
  5881. else
  5882. {
  5883. tempIndex = gun_index;
  5884. }
  5885. for (int index = 0; index < AC_QUANTITY; index++)
  5886. {
  5887. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5888. {
  5889. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5890. }
  5891. } // END for AC_QUANTITY
  5892. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5893. }
  5894. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5895. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5896. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5897. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5898. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5899. }
  5900. //============================ Voltage L1 ====================================
  5901. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5902. {
  5903. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5904. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5905. {
  5906. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5907. {
  5908. tempIndex = ((gun_index==2) ? 1: 0);
  5909. }
  5910. else
  5911. {
  5912. tempIndex = gun_index;
  5913. }
  5914. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5915. {
  5916. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5917. {
  5918. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5919. }
  5920. } // END OF FOR CHAdeMO_QUANTITY
  5921. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5922. }
  5923. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5924. {
  5925. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5926. {
  5927. tempIndex = ((gun_index==2) ? 1: 0);
  5928. }
  5929. else
  5930. {
  5931. tempIndex = gun_index;
  5932. }
  5933. for (int index = 0; index < CCS_QUANTITY; index++)
  5934. {
  5935. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5936. {
  5937. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5938. }
  5939. } // END OF FOR CCS_QUANTITY
  5940. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5941. }
  5942. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5943. {
  5944. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5945. {
  5946. tempIndex = ((gun_index==2) ? 1: 0);
  5947. }
  5948. else
  5949. {
  5950. tempIndex = gun_index;
  5951. }
  5952. for (int index = 0; index < GB_QUANTITY; index++)
  5953. {
  5954. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5955. {
  5956. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5957. }
  5958. } // END OF FOR GB_QUANTITY
  5959. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5960. }
  5961. else if(gunType[gun_index] == GUN_TYPE_DO)
  5962. {
  5963. tempIndex = gun_index;
  5964. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5965. {
  5966. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5967. {
  5968. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5969. }
  5970. }
  5971. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5972. }
  5973. else
  5974. {
  5975. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5976. {
  5977. tempIndex = 2;
  5978. }
  5979. else
  5980. {
  5981. tempIndex = gun_index;
  5982. }
  5983. for (int index = 0; index < AC_QUANTITY; index++)
  5984. {
  5985. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5986. {
  5987. 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
  5988. }
  5989. } // END OF FOR AC_QUANTITY
  5990. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5991. }
  5992. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5993. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5994. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5995. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5996. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5997. }
  5998. //====================== End SoC ================================
  5999. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6000. {
  6001. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6002. 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))
  6003. {
  6004. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6005. {
  6006. tempIndex = ((gun_index==2) ? 1: 0);
  6007. }
  6008. else
  6009. {
  6010. tempIndex = gun_index;
  6011. }
  6012. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6013. {
  6014. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6015. {
  6016. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6017. {
  6018. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  6019. }
  6020. }
  6021. }
  6022. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6023. {
  6024. for (int index = 0; index < CCS_QUANTITY; index++)
  6025. {
  6026. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6027. {
  6028. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  6029. }
  6030. }
  6031. }
  6032. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6033. {
  6034. for (int index = 0; index < GB_QUANTITY; index++)
  6035. {
  6036. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6037. {
  6038. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6039. }
  6040. }
  6041. }
  6042. else if(gunType[gun_index] == GUN_TYPE_DO)
  6043. {
  6044. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6045. {
  6046. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6047. {
  6048. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6049. }
  6050. }
  6051. }
  6052. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6053. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6054. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6055. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6056. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6057. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6058. } // END FOR DC CASE
  6059. }
  6060. // ================================= Current.Import L2 ===============================================
  6061. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6062. {
  6063. // AC 3 phse L2 current
  6064. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6065. {
  6066. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6067. {
  6068. tempIndex = 2;
  6069. }
  6070. else
  6071. {
  6072. tempIndex = gun_index;
  6073. }
  6074. for (int index = 0; index < AC_QUANTITY; index++)
  6075. {
  6076. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6077. {
  6078. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6079. }
  6080. }// End of for AC_QUANTITY
  6081. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6082. }
  6083. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6084. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6085. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6086. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6087. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6088. }
  6089. // ================================= Current.Import L3 ===============================================
  6090. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6091. {
  6092. // AC 3 phse L3 current
  6093. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6094. {
  6095. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6096. {
  6097. tempIndex = 2;
  6098. }
  6099. else
  6100. {
  6101. tempIndex = gun_index;
  6102. }
  6103. for (int index = 0; index < AC_QUANTITY; index++)
  6104. {
  6105. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6106. {
  6107. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6108. }
  6109. }// End of for AC_QUANTITY
  6110. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6111. }
  6112. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6113. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6114. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6115. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6116. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6117. }
  6118. //============================ Voltage L2 ====================================
  6119. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6120. {
  6121. // AC 3 phse L2 voltage
  6122. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6123. {
  6124. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6125. {
  6126. tempIndex = 2;
  6127. }
  6128. else
  6129. {
  6130. tempIndex = gun_index;
  6131. }
  6132. for (int index = 0; index < AC_QUANTITY; index++)
  6133. {
  6134. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6135. {
  6136. 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
  6137. }
  6138. } // END OF FOR AC_QUANTITY
  6139. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6140. }
  6141. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6142. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6143. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6144. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6145. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6146. }
  6147. //============================ Voltage L3 ====================================
  6148. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6149. {
  6150. // AC 3 phse L3 voltage
  6151. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6152. {
  6153. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6154. {
  6155. tempIndex = 2;
  6156. }
  6157. else
  6158. {
  6159. tempIndex = gun_index;
  6160. }
  6161. for (int index = 0; index < AC_QUANTITY; index++)
  6162. {
  6163. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6164. {
  6165. 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
  6166. }
  6167. } // END OF FOR AC_QUANTITY
  6168. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6169. }
  6170. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6171. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6172. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6173. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6174. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6175. }
  6176. //====================== Start SoC ================================
  6177. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6178. {
  6179. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6180. 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))
  6181. {
  6182. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6183. {
  6184. tempIndex = ((gun_index==2) ? 1: 0);
  6185. }
  6186. else
  6187. {
  6188. tempIndex = gun_index;
  6189. }
  6190. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6191. {
  6192. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6193. {
  6194. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6195. {
  6196. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6197. }
  6198. }
  6199. }
  6200. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6201. {
  6202. for (int index = 0; index < CCS_QUANTITY; index++)
  6203. {
  6204. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6205. {
  6206. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6207. }
  6208. }
  6209. }
  6210. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6211. {
  6212. for (int index = 0; index < GB_QUANTITY; index++)
  6213. {
  6214. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6215. {
  6216. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6217. }
  6218. }
  6219. }
  6220. else if(gunType[gun_index] == GUN_TYPE_DO)
  6221. {
  6222. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6223. {
  6224. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6225. {
  6226. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6227. }
  6228. }
  6229. }
  6230. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6231. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6232. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6233. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6234. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6235. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6236. } // END FOR DC CASE
  6237. }
  6238. //================================================ Message create ====================================================
  6239. json_object *StopTransaction = json_object_new_object();
  6240. json_object *transactionDatas = json_object_new_array();
  6241. json_object *sampledValues = json_object_new_array();
  6242. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  6243. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  6244. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  6245. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  6246. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  6247. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  6248. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  6249. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  6250. {
  6251. json_object *transactionData = json_object_new_object();
  6252. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6253. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6254. {
  6255. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6256. {
  6257. json_object *sampledValue = json_object_new_object();
  6258. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6259. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6260. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6261. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6262. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6263. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6264. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6265. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6266. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6267. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6268. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6269. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6270. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6271. json_object_array_add(sampledValues, sampledValue);
  6272. }
  6273. }
  6274. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6275. json_object_array_add(transactionDatas, transactionData);
  6276. }
  6277. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6278. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6279. ,MESSAGE_TYPE_CALL
  6280. ,guid
  6281. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6282. json_object_put(StopTransaction);
  6283. #if 1 // for TempStopTransaction
  6284. //Delete TempStopTransaction
  6285. if((access(TempStopTransaction,F_OK))!=-1)
  6286. {
  6287. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6288. }
  6289. #endif
  6290. #if 1
  6291. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6292. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6293. {
  6294. result = PASS;
  6295. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6296. }
  6297. #endif
  6298. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6299. OCPP_insert_transaction_msg(NO, queuedata);
  6300. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6301. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  6302. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  6303. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6304. {
  6305. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  6306. }
  6307. //for test
  6308. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6309. return result;
  6310. }
  6311. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6312. {
  6313. mtrace();
  6314. int result = FAIL;
  6315. char guid[37]={0};
  6316. char tempdata[65]={0};
  6317. int tempIndex = 0;
  6318. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6319. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6320. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6321. //set value
  6322. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6323. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6324. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  6325. -1);
  6326. random_uuid(guid);
  6327. //UTC Date time
  6328. struct timeval tmnow;
  6329. struct tm *tm;
  6330. char buf[28];//, usec_buf[6];
  6331. gettimeofday(&tmnow, NULL);
  6332. time_t t;
  6333. t = time(NULL);
  6334. /*UTC time and date*/
  6335. tm = gmtime(&t);
  6336. if(dataType == ReadingContext_Sample_Clock)
  6337. {
  6338. struct tm *tmTarget;
  6339. struct timeb tbTarget;
  6340. tbTarget.time = mktime(tm);
  6341. tbTarget.time -= (atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6342. tmTarget = gmtime(&tbTarget.time);
  6343. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6344. }
  6345. else
  6346. {
  6347. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6348. }
  6349. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6350. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6351. //********************************(1)Current.Import L1************************************************/
  6352. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6353. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6354. (dataType == ReadingContext_Trigger))
  6355. {
  6356. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6357. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6358. {
  6359. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6360. {
  6361. tempIndex = ((gun_index==2) ? 1: 0);
  6362. }
  6363. else
  6364. {
  6365. tempIndex = gun_index;
  6366. }
  6367. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6368. {
  6369. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6370. {
  6371. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6372. }
  6373. }
  6374. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6375. }
  6376. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6377. {
  6378. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6379. {
  6380. tempIndex = ((gun_index==2) ? 1: 0);
  6381. }
  6382. else
  6383. {
  6384. tempIndex = gun_index;
  6385. }
  6386. for (int index = 0; index < CCS_QUANTITY; index++)
  6387. {
  6388. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6389. {
  6390. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6391. }
  6392. }
  6393. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6394. }
  6395. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6396. {
  6397. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6398. {
  6399. tempIndex = ((gun_index==2) ? 1: 0);
  6400. }
  6401. else
  6402. {
  6403. tempIndex = gun_index;
  6404. }
  6405. for (int index = 0; index < GB_QUANTITY; index++)
  6406. {
  6407. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6408. {
  6409. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6410. }
  6411. }
  6412. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6413. }
  6414. else if(gunType[gun_index] == GUN_TYPE_DO)
  6415. {
  6416. tempIndex = gun_index;
  6417. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6418. {
  6419. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6420. {
  6421. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6422. }
  6423. }
  6424. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6425. }
  6426. else
  6427. {
  6428. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6429. {
  6430. tempIndex = 2;
  6431. }
  6432. else
  6433. {
  6434. tempIndex = gun_index;
  6435. }
  6436. for (int index = 0; index < AC_QUANTITY; index++)
  6437. {
  6438. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6439. {
  6440. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6441. }
  6442. }
  6443. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6444. }
  6445. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6446. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6447. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6448. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6449. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6450. }
  6451. //********************************(2)Energy.Active.Import.Register ************************************************/
  6452. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6453. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6454. (dataType == ReadingContext_Trigger))
  6455. {
  6456. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6457. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6458. {
  6459. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6460. {
  6461. tempIndex = ((gun_index==2) ? 1: 0);
  6462. }
  6463. else
  6464. {
  6465. tempIndex = gun_index;
  6466. }
  6467. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6468. {
  6469. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6470. {
  6471. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6472. }
  6473. }
  6474. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6475. }
  6476. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6477. {
  6478. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6479. {
  6480. tempIndex = ((gun_index==2) ? 1: 0);
  6481. }
  6482. else
  6483. {
  6484. tempIndex = gun_index;
  6485. }
  6486. for (int index = 0; index < CCS_QUANTITY; index++)
  6487. {
  6488. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6489. {
  6490. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6491. }
  6492. }
  6493. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6494. }
  6495. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6496. {
  6497. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6498. {
  6499. tempIndex = ((gun_index==2) ? 1: 0);
  6500. }
  6501. else
  6502. {
  6503. tempIndex = gun_index;
  6504. }
  6505. for (int index = 0; index < GB_QUANTITY; index++)
  6506. {
  6507. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6508. {
  6509. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6510. }
  6511. }
  6512. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6513. }
  6514. else if(gunType[gun_index] == GUN_TYPE_DO)
  6515. {
  6516. tempIndex = gun_index;
  6517. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6518. {
  6519. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6520. {
  6521. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6522. }
  6523. }
  6524. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6525. }
  6526. else
  6527. {
  6528. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6529. {
  6530. tempIndex = 2;
  6531. }
  6532. else
  6533. {
  6534. tempIndex = gun_index;
  6535. }
  6536. for (int index = 0; index < AC_QUANTITY; index++)
  6537. {
  6538. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6539. {
  6540. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6541. }
  6542. }
  6543. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6544. }
  6545. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6546. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6547. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6548. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6549. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6550. }
  6551. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6552. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6553. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6554. (dataType == ReadingContext_Trigger))
  6555. {
  6556. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6557. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6558. {
  6559. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6560. {
  6561. tempIndex = ((gun_index==2) ? 1: 0);
  6562. }
  6563. else
  6564. {
  6565. tempIndex = gun_index;
  6566. }
  6567. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6568. {
  6569. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6570. {
  6571. if(dataType == ReadingContext_Sample_Clock)
  6572. {
  6573. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6574. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6575. }
  6576. else if(dataType == ReadingContext_Sample_Periodic)
  6577. {
  6578. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6579. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6580. }
  6581. else
  6582. {
  6583. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6584. }
  6585. }
  6586. } // END OF FOR CHAdeMO_QUANTITY
  6587. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6588. }
  6589. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6590. {
  6591. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6592. {
  6593. tempIndex = ((gun_index==2) ? 1: 0);
  6594. }
  6595. else
  6596. {
  6597. tempIndex = gun_index;
  6598. }
  6599. for (int index = 0; index < CCS_QUANTITY; index++)
  6600. {
  6601. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6602. {
  6603. if(dataType == ReadingContext_Sample_Clock)
  6604. {
  6605. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6606. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6607. }
  6608. else if(dataType == ReadingContext_Sample_Periodic)
  6609. {
  6610. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6611. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6612. }
  6613. else
  6614. {
  6615. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6616. }
  6617. }
  6618. } // END OF CCS_QUANTITY
  6619. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6620. }
  6621. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6622. {
  6623. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6624. {
  6625. tempIndex = ((gun_index==2) ? 1: 0);
  6626. }
  6627. else
  6628. {
  6629. tempIndex = gun_index;
  6630. }
  6631. for (int index = 0; index < GB_QUANTITY; index++)
  6632. {
  6633. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6634. {
  6635. if(dataType == ReadingContext_Sample_Clock)
  6636. {
  6637. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6638. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6639. }
  6640. else if(dataType == ReadingContext_Sample_Periodic)
  6641. {
  6642. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6643. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6644. }
  6645. else
  6646. {
  6647. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6648. }
  6649. }
  6650. } // END OF GB_QUANTITY
  6651. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6652. }
  6653. else if(gunType[gun_index] == GUN_TYPE_DO)
  6654. {
  6655. tempIndex = gun_index;
  6656. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6657. {
  6658. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6659. {
  6660. if(dataType == ReadingContext_Sample_Clock)
  6661. {
  6662. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]));
  6663. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6664. }
  6665. else if(dataType == ReadingContext_Sample_Periodic)
  6666. {
  6667. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6668. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6669. }
  6670. else
  6671. {
  6672. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6673. }
  6674. }
  6675. }
  6676. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6677. }
  6678. else
  6679. {
  6680. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6681. {
  6682. tempIndex = 2;
  6683. }
  6684. else
  6685. {
  6686. tempIndex = gun_index;
  6687. }
  6688. for (int index = 0; index < AC_QUANTITY; index++)
  6689. {
  6690. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6691. {
  6692. if(dataType == ReadingContext_Sample_Clock)
  6693. {
  6694. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6695. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6696. }
  6697. else if(dataType == ReadingContext_Sample_Periodic)
  6698. {
  6699. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6700. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6701. }
  6702. else
  6703. {
  6704. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6705. }
  6706. }
  6707. }
  6708. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6709. }
  6710. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6711. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6712. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6713. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6714. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6715. }
  6716. //********************************(4)Power.Active.Import************************************************/
  6717. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6718. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6719. (dataType == ReadingContext_Trigger))
  6720. {
  6721. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6722. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6723. {
  6724. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6725. {
  6726. tempIndex = ((gun_index==2) ? 1: 0);
  6727. }
  6728. else
  6729. {
  6730. tempIndex = gun_index;
  6731. }
  6732. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6733. {
  6734. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6735. {
  6736. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6737. }
  6738. } // END OF FOR
  6739. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6740. }
  6741. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6742. {
  6743. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6744. {
  6745. tempIndex = ((gun_index==2) ? 1: 0);
  6746. }
  6747. else
  6748. {
  6749. tempIndex = gun_index;
  6750. }
  6751. for (int index = 0; index < CCS_QUANTITY; index++)
  6752. {
  6753. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6754. {
  6755. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6756. }
  6757. }
  6758. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6759. }
  6760. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6761. {
  6762. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6763. {
  6764. tempIndex = ((gun_index==2) ? 1: 0);
  6765. }
  6766. else
  6767. {
  6768. tempIndex = gun_index;
  6769. }
  6770. for (int index = 0; index < GB_QUANTITY; index++)
  6771. {
  6772. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6773. {
  6774. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6775. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6776. }
  6777. }
  6778. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6779. }
  6780. else if(gunType[gun_index] == GUN_TYPE_DO)
  6781. {
  6782. tempIndex = gun_index;
  6783. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6784. {
  6785. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6786. {
  6787. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6788. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6789. }
  6790. }
  6791. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6792. }
  6793. else
  6794. {
  6795. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6796. {
  6797. tempIndex = 2;
  6798. }
  6799. else
  6800. {
  6801. tempIndex = gun_index;
  6802. }
  6803. for (int index = 0; index < AC_QUANTITY; index++)
  6804. {
  6805. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6806. {
  6807. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6808. }
  6809. }
  6810. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6811. }
  6812. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6813. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6814. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6815. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6816. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6817. }
  6818. //***********************************************(5)VOLTAGE L1******************************************************/
  6819. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6820. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6821. (dataType == ReadingContext_Trigger))
  6822. {
  6823. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6824. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6825. {
  6826. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6827. {
  6828. tempIndex = ((gun_index==2) ? 1: 0);
  6829. }
  6830. else
  6831. {
  6832. tempIndex = gun_index;
  6833. }
  6834. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6835. {
  6836. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6837. {
  6838. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6839. }
  6840. }
  6841. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6842. }
  6843. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6844. {
  6845. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6846. {
  6847. tempIndex = ((gun_index==2) ? 1: 0);
  6848. }
  6849. else
  6850. {
  6851. tempIndex = gun_index;
  6852. }
  6853. for (int index = 0; index < CCS_QUANTITY; index++)
  6854. {
  6855. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6856. {
  6857. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6858. }
  6859. }
  6860. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6861. }
  6862. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6863. {
  6864. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6865. {
  6866. tempIndex = ((gun_index==2) ? 1: 0);
  6867. }
  6868. else
  6869. {
  6870. tempIndex = gun_index;
  6871. }
  6872. for (int index = 0; index < GB_QUANTITY; index++)
  6873. {
  6874. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6875. {
  6876. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6877. }
  6878. }
  6879. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6880. }
  6881. else if(gunType[gun_index] == GUN_TYPE_DO)
  6882. {
  6883. tempIndex = gun_index;
  6884. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6885. {
  6886. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6887. {
  6888. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6889. }
  6890. }
  6891. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6892. }
  6893. else
  6894. {
  6895. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6896. {
  6897. tempIndex = 2;
  6898. }
  6899. else
  6900. {
  6901. tempIndex = gun_index;
  6902. }
  6903. for (int index = 0; index < AC_QUANTITY; index++)
  6904. {
  6905. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6906. {
  6907. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6908. }
  6909. }
  6910. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6911. }
  6912. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6913. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6914. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6915. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6916. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6917. }
  6918. //***********************************************(6)SOC******************************************************/
  6919. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6920. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6921. (dataType == ReadingContext_Trigger))
  6922. {
  6923. 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))
  6924. {
  6925. //idx_sample=5;
  6926. //sampledValue = NULL;
  6927. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6928. {
  6929. tempIndex = ((gun_index==2) ? 1: 0);
  6930. }
  6931. else
  6932. {
  6933. tempIndex = gun_index;
  6934. }
  6935. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6936. {
  6937. //tempIndex = ((gun_index==2) ? 1: 0);
  6938. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6939. {
  6940. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6941. {
  6942. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6943. }
  6944. }
  6945. }
  6946. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6947. {
  6948. //tempIndex = ((gun_index==2) ? 1: 0);
  6949. for (int index = 0; index < CCS_QUANTITY; index++)
  6950. {
  6951. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6952. {
  6953. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6954. }
  6955. }
  6956. }
  6957. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6958. {
  6959. //tempIndex = ((gun_index==2) ? 1: 0);
  6960. for (int index = 0; index < GB_QUANTITY; index++)
  6961. {
  6962. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6963. {
  6964. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6965. }
  6966. }
  6967. }
  6968. else if(gunType[gun_index] == GUN_TYPE_DO)
  6969. {
  6970. //tempIndex = ((gun_index==2) ? 1: 0);
  6971. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6972. {
  6973. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6974. {
  6975. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6976. }
  6977. }
  6978. }
  6979. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6980. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6981. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6982. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6983. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6984. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6985. }
  6986. }
  6987. //********************************(7)Current.Import L2************************************************/
  6988. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6989. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6990. (dataType == ReadingContext_Trigger))
  6991. {
  6992. // Only for AC 3 phase
  6993. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6994. {
  6995. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6996. {
  6997. tempIndex = 2;
  6998. }
  6999. else
  7000. {
  7001. tempIndex = gun_index;
  7002. }
  7003. for (int index = 0; index < AC_QUANTITY; index++)
  7004. {
  7005. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7006. {
  7007. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7008. }
  7009. }
  7010. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7011. }
  7012. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7013. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7014. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7015. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7016. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7017. }
  7018. //********************************(8)Current.Import L3************************************************/
  7019. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7020. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7021. (dataType == ReadingContext_Trigger))
  7022. {
  7023. // Only for AC 3 phase
  7024. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7025. {
  7026. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7027. {
  7028. tempIndex = 2;
  7029. }
  7030. else
  7031. {
  7032. tempIndex = gun_index;
  7033. }
  7034. for (int index = 0; index < AC_QUANTITY; index++)
  7035. {
  7036. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7037. {
  7038. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7039. }
  7040. }
  7041. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7042. }
  7043. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7044. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7045. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7046. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7047. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7048. }
  7049. //***********************************************(9)VOLTAGE L2******************************************************/
  7050. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7051. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7052. (dataType == ReadingContext_Trigger))
  7053. {
  7054. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7055. {
  7056. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7057. {
  7058. tempIndex = 2;
  7059. }
  7060. else
  7061. {
  7062. tempIndex = gun_index;
  7063. }
  7064. for (int index = 0; index < AC_QUANTITY; index++)
  7065. {
  7066. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7067. {
  7068. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7069. }
  7070. }
  7071. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7072. }
  7073. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7074. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7075. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7076. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7077. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7078. }
  7079. //***********************************************(10)VOLTAGE L3******************************************************/
  7080. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7081. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7082. (dataType == ReadingContext_Trigger))
  7083. {
  7084. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7085. {
  7086. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7087. {
  7088. tempIndex = 2;
  7089. }
  7090. else
  7091. {
  7092. tempIndex = gun_index;
  7093. }
  7094. for (int index = 0; index < AC_QUANTITY; index++)
  7095. {
  7096. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7097. {
  7098. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7099. }
  7100. }
  7101. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7102. }
  7103. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7104. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7105. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7106. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7107. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7108. }
  7109. //***********************************************(11)Current.Offered******************************************************/
  7110. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7111. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7112. (dataType == ReadingContext_Trigger))
  7113. {
  7114. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7115. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7116. {
  7117. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7118. {
  7119. tempIndex = ((gun_index==2) ? 1: 0);
  7120. }
  7121. else
  7122. {
  7123. tempIndex = gun_index;
  7124. }
  7125. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7126. {
  7127. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7128. {
  7129. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  7130. }
  7131. } // END OF FOR CHAdeMO_QUANTITY
  7132. }
  7133. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7134. {
  7135. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7136. {
  7137. tempIndex = ((gun_index==2) ? 1: 0);
  7138. }
  7139. else
  7140. {
  7141. tempIndex = gun_index;
  7142. }
  7143. for (int index = 0; index < CCS_QUANTITY; index++)
  7144. {
  7145. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7146. {
  7147. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  7148. }
  7149. } // END OF CCS_QUANTITY
  7150. }
  7151. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7152. {
  7153. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7154. {
  7155. tempIndex = ((gun_index==2) ? 1: 0);
  7156. }
  7157. else
  7158. {
  7159. tempIndex = gun_index;
  7160. }
  7161. for (int index = 0; index < GB_QUANTITY; index++)
  7162. {
  7163. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7164. {
  7165. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  7166. }
  7167. } // END OF GB_QUANTITY
  7168. }
  7169. else if(gunType[gun_index] == GUN_TYPE_DO)
  7170. {
  7171. tempIndex = gun_index;
  7172. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7173. {
  7174. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7175. {
  7176. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  7177. }
  7178. }
  7179. }
  7180. else
  7181. {
  7182. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7183. {
  7184. tempIndex = 2;
  7185. }
  7186. else
  7187. {
  7188. tempIndex = gun_index;
  7189. }
  7190. for (int index = 0; index < AC_QUANTITY; index++)
  7191. {
  7192. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7193. {
  7194. uint16_t currentOffer;
  7195. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7196. {
  7197. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7198. }
  7199. else
  7200. {
  7201. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7202. }
  7203. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7204. }
  7205. }
  7206. }
  7207. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7208. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7209. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7210. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7211. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7212. }
  7213. //***********************************************(12)Power.Offered******************************************************/
  7214. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7215. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7216. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7217. {
  7218. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7219. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7220. {
  7221. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7222. {
  7223. tempIndex = ((gun_index==2) ? 1: 0);
  7224. }
  7225. else
  7226. {
  7227. tempIndex = gun_index;
  7228. }
  7229. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7230. {
  7231. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7232. {
  7233. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  7234. }
  7235. } // END OF FOR CHAdeMO_QUANTITY
  7236. }
  7237. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7238. {
  7239. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7240. {
  7241. tempIndex = ((gun_index==2) ? 1: 0);
  7242. }
  7243. else
  7244. {
  7245. tempIndex = gun_index;
  7246. }
  7247. for (int index = 0; index < CCS_QUANTITY; index++)
  7248. {
  7249. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7250. {
  7251. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  7252. }
  7253. } // END OF CCS_QUANTITY
  7254. }
  7255. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7256. {
  7257. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7258. {
  7259. tempIndex = ((gun_index==2) ? 1: 0);
  7260. }
  7261. else
  7262. {
  7263. tempIndex = gun_index;
  7264. }
  7265. for (int index = 0; index < GB_QUANTITY; index++)
  7266. {
  7267. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7268. {
  7269. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  7270. }
  7271. } // END OF GB_QUANTITY
  7272. }
  7273. else if(gunType[gun_index] == GUN_TYPE_DO)
  7274. {
  7275. tempIndex = gun_index;
  7276. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7277. {
  7278. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7279. {
  7280. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  7281. }
  7282. }
  7283. }
  7284. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7285. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7286. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7287. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7288. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7289. }
  7290. // Message create ====================================================================================================
  7291. if(TRUE)
  7292. {
  7293. json_object *MeterValueReq = json_object_new_object();
  7294. json_object *MeterValues = json_object_new_array();
  7295. json_object *sampledValues = json_object_new_array();
  7296. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  7297. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  7298. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  7299. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  7300. {
  7301. json_object *MeterValue = json_object_new_object();
  7302. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7303. {
  7304. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7305. {
  7306. json_object *sampledValue = json_object_new_object();
  7307. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7308. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7309. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7310. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7311. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7312. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7313. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7314. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7315. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7316. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7317. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7318. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7319. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7320. json_object_array_add(sampledValues, sampledValue);
  7321. }
  7322. }
  7323. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7324. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7325. json_object_array_add(MeterValues, MeterValue);
  7326. }
  7327. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7328. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7329. ,gun_index + 1
  7330. ,MESSAGE_TYPE_CALL
  7331. ,guid
  7332. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7333. json_object_put(MeterValueReq);
  7334. }
  7335. // Put request guid to hash map
  7336. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7337. 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*/)
  7338. {
  7339. result = PASS;
  7340. //DEBUG_INFO("MeterValues mapitem pass\n");
  7341. }
  7342. if((dataType != ReadingContext_Trigger) &&
  7343. (dataType != ReadingContext_Sample_Clock) &&
  7344. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7345. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7346. else
  7347. {
  7348. if(FirstHeartBeat)
  7349. LWS_Send(queuedata +2);
  7350. }
  7351. return result;
  7352. }
  7353. int sendLogStatusNotificationRequest(char *status)
  7354. {
  7355. mtrace();
  7356. int result = PASS;
  7357. char message[4096]={0};
  7358. char guid[37]={0};
  7359. char tempdata[128]={0};
  7360. json_object *LogStatusNotification = json_object_new_object();
  7361. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7362. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  7363. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  7364. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  7365. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  7366. random_uuid(guid);
  7367. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7368. json_object_put(LogStatusNotification);
  7369. LWS_Send(message);
  7370. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7371. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7372. {
  7373. result = PASS;
  7374. }
  7375. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  7376. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  7377. return result;
  7378. }
  7379. int sendSecurityEventNotificationRequest()
  7380. {
  7381. mtrace();
  7382. int result = PASS;
  7383. char message[4096]={0};
  7384. char guid[37]={0};
  7385. char tempdata[128]={0};
  7386. json_object *SecurityEventNotification = json_object_new_object();
  7387. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7388. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  7389. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  7390. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  7391. random_uuid(guid);
  7392. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7393. json_object_put(SecurityEventNotification);
  7394. LWS_Send(message);
  7395. sprintf(tempdata, "SecurityEventNotification,0");
  7396. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7397. {
  7398. result = PASS;
  7399. }
  7400. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  7401. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  7402. return result;
  7403. }
  7404. int sendSignCertificateRequest()
  7405. {
  7406. mtrace();
  7407. int result = PASS;
  7408. char message[4096]={0};
  7409. char guid[37]={0};
  7410. char tempdata[128]={0};
  7411. json_object *SignCertificate = json_object_new_object();
  7412. DEBUG_INFO("sendSignCertificateRequest...\n");
  7413. // Read csr file content
  7414. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  7415. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  7416. char *line = NULL;
  7417. size_t len = 0;
  7418. while(getline(&line, &len, fp) != -1)
  7419. {
  7420. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7421. {
  7422. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  7423. }
  7424. }
  7425. fclose(fp);
  7426. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  7427. random_uuid(guid);
  7428. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7429. json_object_put(SignCertificate);
  7430. LWS_Send(message);
  7431. sprintf(tempdata, "SignCertificate,0");
  7432. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7433. {
  7434. result = PASS;
  7435. }
  7436. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  7437. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  7438. return result;
  7439. }
  7440. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7441. {
  7442. mtrace();
  7443. int result = PASS;
  7444. char message[110]={0};
  7445. char guid[37]={0};
  7446. char tempdata[65]={0};
  7447. json_object *FirmwareStatusNotification = json_object_new_object();
  7448. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7449. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7450. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  7451. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  7452. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  7453. random_uuid(guid);
  7454. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7455. json_object_put(FirmwareStatusNotification);
  7456. LWS_Send(message);
  7457. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7458. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7459. {
  7460. result = PASS;
  7461. }
  7462. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7463. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7464. return result;
  7465. }
  7466. //==========================================
  7467. // send confirm routine
  7468. //==========================================
  7469. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7470. {
  7471. mtrace();
  7472. int result = FAIL;
  7473. char message[100]={0};
  7474. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7475. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7476. LWS_Send(message);
  7477. result = TRUE;
  7478. return result;
  7479. }
  7480. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7481. {
  7482. mtrace();
  7483. int result = FAIL;
  7484. char message[100]={0};
  7485. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7486. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7487. LWS_Send(message);
  7488. result = TRUE;
  7489. return result;
  7490. }
  7491. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7492. {
  7493. mtrace();
  7494. int result = FAIL;
  7495. char message[100]={0};
  7496. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7497. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7498. LWS_Send(message);
  7499. result = TRUE;
  7500. return result;
  7501. }
  7502. int sendClearCacheConfirmation(char *uuid,char *payload)
  7503. {
  7504. mtrace();
  7505. int result = FAIL;
  7506. char message[500]={0};
  7507. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7508. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7509. LWS_Send(message);
  7510. return result;
  7511. }
  7512. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7513. {
  7514. mtrace();
  7515. int result = FAIL;
  7516. char message[500]={0};
  7517. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7518. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7519. LWS_Send(message);
  7520. return result;
  7521. }
  7522. int sendDataTransferConfirmation(char *uuid,char *payload)
  7523. {
  7524. mtrace();
  7525. char statusStr[20]={0};
  7526. char dataStr[10]={0};
  7527. char sstr[20]={0};
  7528. int c = 0;
  7529. char *loc;
  7530. int result = FAIL;
  7531. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7532. /**********************status**************************/
  7533. loc = strstr(payload, "status");
  7534. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7535. c = 0;
  7536. while (loc[3+strlen("status")+c] != '\"')
  7537. {
  7538. sstr[c] = loc[3+strlen("status")+c];
  7539. c++;
  7540. }
  7541. sstr[c] = '\0';
  7542. strcpy(statusStr, sstr);
  7543. /**********************data**************************/
  7544. loc = strstr(payload, "data");
  7545. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7546. c = 0;
  7547. while (loc[3+strlen("data")+c] != '\"')
  7548. {
  7549. sstr[c] = loc[3+strlen("data")+c];
  7550. c++;
  7551. }
  7552. sstr[c] = '\0';
  7553. strcpy(dataStr, sstr);
  7554. return result;
  7555. }
  7556. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7557. {
  7558. mtrace();
  7559. int result = FAIL;
  7560. char message[1000]={0};
  7561. int CompositeScheduleIndex = 0;
  7562. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7563. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7564. if(nPeriod == 0)
  7565. {
  7566. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7567. {
  7568. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7569. ,MESSAGE_TYPE_CALLRESULT
  7570. ,uuid
  7571. ,payload
  7572. ,connectorIdInt);
  7573. }
  7574. else
  7575. {
  7576. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  7577. ,MESSAGE_TYPE_CALLRESULT
  7578. ,uuid
  7579. ,payload
  7580. ,connectorIdInt
  7581. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7582. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7583. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7584. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7585. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7586. }
  7587. }
  7588. else
  7589. {
  7590. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7591. ,MESSAGE_TYPE_CALLRESULT
  7592. ,uuid
  7593. ,payload
  7594. ,connectorIdInt
  7595. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7596. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7597. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7598. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7599. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7600. {
  7601. if (idx_sample == 0)
  7602. {
  7603. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7604. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7605. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7606. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7607. }
  7608. else
  7609. {
  7610. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7611. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7612. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7613. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7614. }
  7615. }
  7616. sprintf(message + strlen(message), "]}}]");
  7617. }
  7618. LWS_Send(message);
  7619. result = TRUE;
  7620. return result;
  7621. }
  7622. int sendGetConfigurationConfirmation(char *uuid)
  7623. {
  7624. mtrace();
  7625. int result = FAIL;
  7626. int MaxKeySupported = 0;
  7627. int sentConfigurationNumber= 0;
  7628. int sentunConfigurationNumber= 0;
  7629. char message[1024*10]={0};
  7630. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7631. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7632. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  7633. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7634. ,MESSAGE_TYPE_CALLRESULT
  7635. ,uuid );
  7636. //configuration key
  7637. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7638. {
  7639. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7640. {
  7641. if (sentConfigurationNumber == 0)
  7642. {
  7643. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7644. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7645. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7646. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7647. }
  7648. else
  7649. {
  7650. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7651. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7652. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7653. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7654. }
  7655. sentConfigurationNumber = sentConfigurationNumber + 1;
  7656. }
  7657. }
  7658. sprintf(message + strlen(message), "]");
  7659. if(UnknownKeynum != 0)
  7660. {
  7661. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7662. //unkown key
  7663. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7664. {
  7665. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7666. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7667. if(sentunConfigurationNumber == 0)
  7668. {
  7669. sprintf(message + strlen(message), "\"%s\""
  7670. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7671. }
  7672. else
  7673. {
  7674. sprintf(message + strlen(message), ",\"%s\""
  7675. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7676. }
  7677. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7678. }
  7679. sprintf(message + strlen(message), "]");
  7680. }
  7681. sprintf(message + strlen(message), "}]");
  7682. LWS_Send(message);
  7683. return result;
  7684. }
  7685. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7686. {
  7687. mtrace();
  7688. int result = FAIL;
  7689. char message[400]={0};
  7690. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7691. if(strcmp(payload,"")==0)
  7692. {
  7693. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7694. }
  7695. else
  7696. {
  7697. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7698. }
  7699. LWS_Send(message);
  7700. result = TRUE;
  7701. return result;
  7702. }
  7703. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7704. {
  7705. mtrace();
  7706. int result = FAIL;
  7707. char message[80]={0};
  7708. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7709. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  7710. LWS_Send(message);
  7711. result = TRUE;
  7712. return result;
  7713. }
  7714. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7715. {
  7716. mtrace();
  7717. int result = FAIL;
  7718. char message[80]={0};
  7719. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7720. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7721. LWS_Send(message);
  7722. result = TRUE;
  7723. return result;
  7724. }
  7725. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7726. {
  7727. mtrace();
  7728. int result = FAIL;
  7729. char message[80]={0};
  7730. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7731. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7732. LWS_Send(message);
  7733. result = TRUE;
  7734. return result;
  7735. }
  7736. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7737. {
  7738. mtrace();
  7739. int result = FAIL;
  7740. char message[80]={0};
  7741. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7742. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7743. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7744. LWS_Send(message);
  7745. result = TRUE;
  7746. return result;
  7747. }
  7748. int sendResetConfirmation(char *uuid,char *payload)
  7749. {
  7750. mtrace();
  7751. int result = FAIL;
  7752. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7753. char message[80]={0};
  7754. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  7755. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7756. LWS_Send(message);
  7757. result = TRUE;
  7758. return result;
  7759. }
  7760. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7761. {
  7762. mtrace();
  7763. int result = FAIL;
  7764. char message[500]={0};
  7765. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7766. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7767. LWS_Send(message);
  7768. result = TRUE;
  7769. return result;
  7770. }
  7771. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7772. {
  7773. mtrace();
  7774. int result = FAIL;
  7775. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7776. char message[80]={0};
  7777. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7778. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7779. LWS_Send(message);
  7780. result = TRUE;
  7781. return result;
  7782. }
  7783. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7784. {
  7785. mtrace();
  7786. int result = FAIL;
  7787. char message[80]={0};
  7788. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7789. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7790. LWS_Send(message);
  7791. result = TRUE;
  7792. return result;
  7793. }
  7794. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7795. {
  7796. mtrace();
  7797. int result = FAIL;
  7798. char message[80]={0};
  7799. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7800. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7801. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7802. LWS_Send(message);
  7803. result = TRUE;
  7804. return result;
  7805. }
  7806. int sendUpdateFirmwareConfirmation(char *uuid)
  7807. {
  7808. mtrace();
  7809. int result = FAIL;
  7810. char message[60]={0};
  7811. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7812. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7813. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7814. LWS_Send(message);
  7815. result = TRUE;
  7816. return result;
  7817. }
  7818. int sendCertificateSignedConfirmation(char *uuid)
  7819. {
  7820. mtrace();
  7821. int result = PASS;
  7822. char message[4096]={0};
  7823. json_object *CertificateSigned = json_object_new_object();
  7824. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7825. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  7826. sprintf(message,"[%d,\"%s\",%s]"
  7827. ,MESSAGE_TYPE_CALLRESULT
  7828. ,uuid
  7829. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7830. json_object_put(CertificateSigned);
  7831. LWS_Send(message);
  7832. return result;
  7833. }
  7834. int sendDeleteCertificateConfirmation(char *uuid)
  7835. {
  7836. mtrace();
  7837. int result = PASS;
  7838. char message[4096]={0};
  7839. json_object *DeleteCertificate = json_object_new_object();
  7840. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7841. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  7842. sprintf(message,"[%d,\"%s\",%s]"
  7843. ,MESSAGE_TYPE_CALLRESULT
  7844. ,uuid
  7845. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7846. json_object_put(DeleteCertificate);
  7847. LWS_Send(message);
  7848. return result;
  7849. }
  7850. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7851. {
  7852. mtrace();
  7853. int result = PASS;
  7854. char message[4096]={0};
  7855. json_object *ExtendedTriggerMessage = json_object_new_object();
  7856. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7857. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7858. sprintf(message,"[%d,\"%s\",%s]"
  7859. ,MESSAGE_TYPE_CALLRESULT
  7860. ,uuid
  7861. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7862. json_object_put(ExtendedTriggerMessage);
  7863. LWS_Send(message);
  7864. return result;
  7865. }
  7866. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7867. {
  7868. mtrace();
  7869. int result = PASS;
  7870. char message[4096]={0};
  7871. json_object *GetInstalledCertificateIds = json_object_new_object();
  7872. json_object *certificateHashDataDatas = json_object_new_array();
  7873. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7874. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7875. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7876. {
  7877. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7878. {
  7879. json_object *certificateHashData = json_object_new_object();
  7880. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7881. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7882. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7883. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7884. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7885. }
  7886. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7887. }
  7888. else
  7889. {
  7890. json_object_put(certificateHashDataDatas);
  7891. }
  7892. sprintf(message,"[%d,\"%s\",%s]"
  7893. ,MESSAGE_TYPE_CALLRESULT
  7894. ,uuid
  7895. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7896. json_object_put(GetInstalledCertificateIds);
  7897. LWS_Send(message);
  7898. return result;
  7899. }
  7900. int sendGetLogConfirmation(char *uuid)
  7901. {
  7902. mtrace();
  7903. int result = PASS;
  7904. char message[4096]={0};
  7905. json_object *GetLog = json_object_new_object();
  7906. DEBUG_INFO("sendGetLogConfirmation...\n");
  7907. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7908. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7909. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7910. sprintf(message,"[%d,\"%s\",%s]"
  7911. ,MESSAGE_TYPE_CALLRESULT
  7912. ,uuid
  7913. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7914. json_object_put(GetLog);
  7915. LWS_Send(message);
  7916. return result;
  7917. }
  7918. int sendInstallCertificateConfirmation(char *uuid)
  7919. {
  7920. mtrace();
  7921. int result = PASS;
  7922. char message[4096]={0};
  7923. json_object *InstallCertificate = json_object_new_object();
  7924. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7925. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7926. sprintf(message,"[%d,\"%s\",%s]"
  7927. ,MESSAGE_TYPE_CALLRESULT
  7928. ,uuid
  7929. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7930. json_object_put(InstallCertificate);
  7931. LWS_Send(message);
  7932. return result;
  7933. }
  7934. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7935. {
  7936. mtrace();
  7937. int result = PASS;
  7938. char message[4096]={0};
  7939. json_object *SignedUpdateFirmware = json_object_new_object();
  7940. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7941. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7942. sprintf(message,"[%d,\"%s\",%s]"
  7943. ,MESSAGE_TYPE_CALLRESULT
  7944. ,uuid
  7945. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7946. json_object_put(SignedUpdateFirmware);
  7947. LWS_Send(message);
  7948. return result;
  7949. }
  7950. int sendUnknownConfirmation(char *uuid)
  7951. {
  7952. mtrace();
  7953. int result = PASS;
  7954. char message[256]={0};
  7955. DEBUG_INFO("sendUnknownConfirmation...\n");
  7956. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7957. LWS_Send(message);
  7958. return result;
  7959. }
  7960. //==========================================
  7961. // Handle server request routine Start
  7962. //==========================================
  7963. int handleCancelReservationRequest(char *uuid, char *payload)
  7964. {
  7965. mtrace();
  7966. int result = FAIL;
  7967. int gunNO = 0;
  7968. int reservationIdInt = -1;
  7969. char comfirmstr[20];
  7970. DEBUG_INFO("handleCancelReservationRequest...\n");
  7971. json_object *CancelReservation;
  7972. CancelReservation = json_tokener_parse(payload);
  7973. if(!is_error(CancelReservation))
  7974. {
  7975. // Required data
  7976. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7977. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7978. }
  7979. json_object_put(CancelReservation);
  7980. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7981. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7982. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7983. if(reservationIdInt != -1)
  7984. {
  7985. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7986. //check Transaction active
  7987. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7988. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7989. {
  7990. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7991. {
  7992. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7993. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7994. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7995. {
  7996. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7997. }
  7998. else
  7999. {
  8000. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8001. }
  8002. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8003. goto end;
  8004. }
  8005. }
  8006. for (int index = 0; index < CCS_QUANTITY; index++)
  8007. {
  8008. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8009. {
  8010. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8011. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8012. if(gunType[2] == GUN_TYPE_CCS)
  8013. {
  8014. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8015. }
  8016. else
  8017. {
  8018. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8019. }
  8020. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8021. goto end;
  8022. }
  8023. }
  8024. for (int index = 0; index < GB_QUANTITY; index++)
  8025. {
  8026. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8027. {
  8028. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8029. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8030. if(gunType[2] == GUN_TYPE_GBT)
  8031. {
  8032. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8033. }
  8034. else
  8035. {
  8036. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8037. }
  8038. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8039. goto end;
  8040. }
  8041. }
  8042. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8043. {
  8044. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8045. {
  8046. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8047. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index].ResponseStatus, "%s", comfirmstr );
  8048. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8049. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8050. goto end;
  8051. }
  8052. }
  8053. for (int index = 0; index < AC_QUANTITY; index++)
  8054. {
  8055. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8056. {
  8057. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8058. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8059. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8060. {
  8061. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8062. }
  8063. else
  8064. {
  8065. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8066. }
  8067. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8068. goto end;
  8069. }
  8070. }
  8071. }
  8072. //The reservationId does NOT match the reservationId
  8073. sendCancelReservationConfirmation(uuid, comfirmstr);
  8074. end:
  8075. // Fill in ocpp packet uuid
  8076. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  8077. return result;
  8078. }
  8079. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8080. {
  8081. mtrace();
  8082. int result = FAIL;
  8083. int gunIndex = -1;
  8084. char typeStr[16]={0};
  8085. char comfirmstr[20];
  8086. int specificId = FALSE;
  8087. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8088. json_object *ChangeAvailability;
  8089. ChangeAvailability = json_tokener_parse(payload);
  8090. if(!is_error(ChangeAvailability))
  8091. {
  8092. // Required data
  8093. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8094. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8095. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8096. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8097. }
  8098. json_object_put(ChangeAvailability);
  8099. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8100. {
  8101. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8102. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8103. }
  8104. else if(gunIndex == 0)
  8105. {
  8106. for(int i=0; i < gunTotalNumber; i++)
  8107. {
  8108. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  8109. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  8110. }
  8111. }
  8112. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8113. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8114. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8115. {
  8116. specificId = TRUE;
  8117. }
  8118. if(specificId == FALSE)
  8119. goto end;
  8120. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8121. {
  8122. //----------------------gunIndex is 0 ------------------------------------------------//
  8123. if(gunIndex == 0)
  8124. {
  8125. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8126. {
  8127. for(int i=0; i < gunTotalNumber; i++)
  8128. {
  8129. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8130. {
  8131. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8132. {
  8133. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8134. {
  8135. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8136. goto end;
  8137. }
  8138. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8139. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8140. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8141. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8142. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8143. {
  8144. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8145. goto end;
  8146. }
  8147. }
  8148. }//END FOR CHAdeMO_QUANTITY
  8149. for (int index = 0; index < CCS_QUANTITY; index++)
  8150. {
  8151. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8152. {
  8153. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8154. {
  8155. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8156. goto end;
  8157. }
  8158. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8159. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8160. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8161. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8162. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8163. {
  8164. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8165. goto end;
  8166. }
  8167. }
  8168. }//END FOR CCS_QUANTITY
  8169. for (int index = 0; index < GB_QUANTITY; index++)
  8170. {
  8171. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8172. {
  8173. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8174. {
  8175. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8176. goto end;
  8177. }
  8178. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8179. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8180. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8181. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8182. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8183. {
  8184. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8185. goto end;
  8186. }
  8187. }
  8188. }// END FOR GB_QUANTITY
  8189. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8190. {
  8191. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8192. {
  8193. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8194. {
  8195. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8196. goto end;
  8197. }
  8198. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8199. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8200. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8201. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8202. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8203. {
  8204. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8205. goto end;
  8206. }
  8207. }
  8208. }// END FOR GENERAL_GUN_QUANTITY
  8209. for (int index = 0; index < AC_QUANTITY; index++)
  8210. {
  8211. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8212. {
  8213. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8214. {
  8215. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8216. goto end;
  8217. }
  8218. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8219. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8220. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8221. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8222. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8223. {
  8224. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8225. goto end;
  8226. }
  8227. }
  8228. }//END FOR AC_QUANTITY
  8229. }// END FOR gunTotalNumber
  8230. }
  8231. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8232. {
  8233. for(int i=0; i < gunTotalNumber; i++)
  8234. {
  8235. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8236. {
  8237. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8238. goto end;
  8239. }
  8240. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8241. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8242. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8243. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8244. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8245. {
  8246. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8247. goto end;
  8248. }
  8249. }
  8250. }
  8251. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8252. goto end;
  8253. }
  8254. //----------------------gunIndex is not 0 ------------------------------------------------//
  8255. //check Transaction active
  8256. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8257. {
  8258. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8259. {
  8260. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8261. {
  8262. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8263. goto end;
  8264. }
  8265. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8266. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8267. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8268. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8269. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8270. {
  8271. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8272. goto end;
  8273. }
  8274. else
  8275. {
  8276. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8277. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8278. goto end;
  8279. }
  8280. }
  8281. }//END FOR CHAdeMO_QUANTITY
  8282. for (int index = 0; index < CCS_QUANTITY; index++)
  8283. {
  8284. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8285. {
  8286. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8287. {
  8288. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8289. goto end;
  8290. }
  8291. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8292. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8293. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8294. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8295. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8296. {
  8297. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8298. goto end;
  8299. }
  8300. else
  8301. {
  8302. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8303. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8304. goto end;
  8305. }
  8306. }
  8307. }//END FOR CCS_QUANTITY
  8308. for (int index = 0; index < GB_QUANTITY; index++)
  8309. {
  8310. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8311. {
  8312. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8313. {
  8314. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8315. goto end;
  8316. }
  8317. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8318. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8319. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8320. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8321. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8322. {
  8323. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8324. goto end;
  8325. }
  8326. else
  8327. {
  8328. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8329. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8330. goto end;
  8331. }
  8332. }
  8333. }// END FOR GB_QUANTITY
  8334. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8335. {
  8336. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8337. {
  8338. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8339. {
  8340. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8341. goto end;
  8342. }
  8343. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8344. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8345. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8346. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8347. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8348. {
  8349. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8350. goto end;
  8351. }
  8352. else
  8353. {
  8354. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8355. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8356. goto end;
  8357. }
  8358. }
  8359. }// END FOR GENERAL_GUN_QUANTITY
  8360. for (int index = 0; index < AC_QUANTITY; index++)
  8361. {
  8362. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8363. {
  8364. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8365. {
  8366. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8367. goto end;
  8368. }
  8369. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8370. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8371. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8372. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8373. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8374. {
  8375. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8376. goto end;
  8377. }
  8378. else
  8379. {
  8380. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8381. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8382. goto end;
  8383. }
  8384. }
  8385. }//END FOR AC_QUANTITY
  8386. }//END FOR AvailabilityTypeStr[Inoperative]
  8387. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8388. {
  8389. //----------------------gunIndex is 0 ------------------------------------------------//
  8390. if(gunIndex == 0)
  8391. {
  8392. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8393. {
  8394. for(int i=0; i < gunTotalNumber; i++)
  8395. {
  8396. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8397. {
  8398. 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
  8399. {
  8400. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8401. goto end;
  8402. }
  8403. }//END FOR CHAdeMO_QUANTITY
  8404. for (int index = 0; index < CCS_QUANTITY; index++)
  8405. {
  8406. 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
  8407. {
  8408. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8409. goto end;
  8410. }
  8411. }//END FOR CCS_QUANTITY
  8412. for (int index = 0; index < GB_QUANTITY; index++)
  8413. {
  8414. 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
  8415. {
  8416. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8417. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8418. goto end;
  8419. }
  8420. }// END FOR GB_QUANTITY
  8421. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8422. {
  8423. 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
  8424. {
  8425. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8426. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8427. goto end;
  8428. }
  8429. }// END FOR GENERAL_GUN_QUANTITY
  8430. for (int index = 0; index < AC_QUANTITY; index++)
  8431. {
  8432. 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
  8433. {
  8434. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8435. goto end;
  8436. }
  8437. }//END FOR CHAdeMO_QUANTITY
  8438. }// END FOR gunTotalNumber
  8439. }
  8440. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8441. {
  8442. for(int i=0; i < gunTotalNumber; i++)
  8443. {
  8444. for (int index = 0; index < AC_QUANTITY; index++)
  8445. {
  8446. 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
  8447. {
  8448. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8449. goto end;
  8450. }
  8451. }//END FOR CHAdeMO_QUANTITY
  8452. } // END FOR gunTotalNumber
  8453. }
  8454. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8455. goto end;
  8456. }
  8457. //----------------------gunIndex is not 0 ------------------------------------------------//
  8458. //check Transaction active
  8459. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8460. {
  8461. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8462. {
  8463. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8464. goto end;
  8465. }
  8466. }//END FOR CHAdeMO_QUANTITY
  8467. for (int index = 0; index < CCS_QUANTITY; index++)
  8468. {
  8469. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8470. {
  8471. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8472. goto end;
  8473. }
  8474. }//END FOR CCS_QUANTITY
  8475. for (int index = 0; index < GB_QUANTITY; index++)
  8476. {
  8477. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8478. {
  8479. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8480. goto end;
  8481. }
  8482. }// END FOR GB_QUANTITY
  8483. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8484. {
  8485. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8486. {
  8487. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8488. goto end;
  8489. }
  8490. }// END FOR GENERAL_GUN_QUANTITY
  8491. for (int index = 0; index < AC_QUANTITY; index++)
  8492. {
  8493. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8494. {
  8495. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8496. goto end;
  8497. }
  8498. }//END FOR AC_QUANTITY
  8499. }//END FOR AvailabilityTypeStr[Operative]
  8500. end:
  8501. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8502. {
  8503. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8504. }
  8505. else
  8506. {
  8507. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8508. }
  8509. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8510. {
  8511. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8512. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8513. }
  8514. else if(gunIndex == 0)
  8515. {
  8516. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8517. {
  8518. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8519. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8520. }
  8521. }
  8522. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8523. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8524. return result;
  8525. }
  8526. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8527. {
  8528. mtrace();
  8529. int valueInvalid = NO;
  8530. int result = FAIL;
  8531. char keystr[40]={0};
  8532. char valuestr[501]={0}; //value should be limited in 500 bytes
  8533. char comfirmstr[20]={0};
  8534. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8535. json_object *ChangeConfiguration;
  8536. ChangeConfiguration = json_tokener_parse(payload);
  8537. if(!is_error(ChangeConfiguration))
  8538. {
  8539. // Required data
  8540. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8541. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8542. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8543. {
  8544. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8545. }
  8546. else
  8547. {
  8548. valueInvalid = YES;
  8549. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8550. }
  8551. }
  8552. json_object_put(ChangeConfiguration);
  8553. if((uuid==NULL) || (payload ==NULL) || (valueInvalid == YES))
  8554. {
  8555. DEBUG_ERROR("Payload is null or not accepted.\n");
  8556. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8557. }
  8558. else
  8559. {
  8560. int status = setKeyValue(keystr, valuestr);
  8561. switch(status)
  8562. {
  8563. case ConfigurationStatus_Accepted:
  8564. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8565. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  8566. StoreConfigurationTable();
  8567. break;
  8568. case RebootRequired:
  8569. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8570. StoreConfigurationTable();
  8571. break;
  8572. case NotSupported:
  8573. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8574. break;
  8575. case ConfigurationStatus_Rejected:
  8576. default:
  8577. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8578. break;
  8579. }
  8580. }
  8581. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8582. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  8583. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8584. {
  8585. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8586. SetOcppConnStatus(FALSE);
  8587. }
  8588. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8589. {
  8590. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8591. }
  8592. return result;
  8593. }
  8594. int handleClearCacheRequest(char *uuid, char *payload)
  8595. {
  8596. mtrace();
  8597. int result = FAIL;
  8598. char comfirmstr[20];
  8599. char rmFileCmd[100]={0};
  8600. struct stat stats;
  8601. DEBUG_INFO("handleClearCacheRequest...\n");
  8602. stat("/Storage/OCPP_PH", &stats);
  8603. // Check for directory existence
  8604. if (S_ISDIR(stats.st_mode) == 1)
  8605. {}
  8606. else
  8607. {
  8608. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8609. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  8610. system(rmFileCmd);
  8611. }
  8612. if(OCPP_cleanLocalCache())
  8613. {
  8614. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8615. }
  8616. else
  8617. {
  8618. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8619. }
  8620. sendClearCacheConfirmation(uuid, comfirmstr);
  8621. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8622. return result;
  8623. }
  8624. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8625. {
  8626. mtrace();
  8627. int result = FAIL;
  8628. int resultRename;
  8629. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8630. char chargingProfilePurposeStr[26]={0};
  8631. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8632. char tempchargingProfilePurposeStr[26]={0};
  8633. char str[100]={0};
  8634. char fname[200]={0};
  8635. char comfirmstr[20]={0};
  8636. char word[1600]={0};
  8637. int clearflag = FALSE;
  8638. int chargingProfileIdIsNULL = FALSE;
  8639. int connectorIsNULL = FALSE;
  8640. int chargingProfilePurposeIsNULL = FALSE;
  8641. int stackLevelIsNULL = FALSE;
  8642. //int GotoEnd = FALSE;
  8643. FILE *fptr1, *fptr2;
  8644. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  8645. int n_chargingProfile=0;
  8646. int isEmptyFile = FALSE;
  8647. char sLineWord[1600]={0};
  8648. char chargingProfiles[10][100]={0};
  8649. int ChargeProfileCount = 0;
  8650. int ch;
  8651. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8652. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8653. json_object *ClearChargingProfile;
  8654. ClearChargingProfile = json_tokener_parse(payload);
  8655. if(!is_error(ClearChargingProfile))
  8656. {
  8657. // Optional data
  8658. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8659. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8660. else
  8661. chargingProfileIdIsNULL = TRUE;
  8662. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8663. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8664. else
  8665. connectorIsNULL = TRUE;
  8666. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8667. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8668. else
  8669. chargingProfilePurposeIsNULL = TRUE;
  8670. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8671. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8672. else
  8673. stackLevelIsNULL = TRUE;
  8674. }
  8675. json_object_put(ClearChargingProfile);
  8676. if(connectorIsNULL == FALSE)
  8677. {
  8678. switch(connectorIdInt)
  8679. {
  8680. case 0:
  8681. if(chargingProfilePurposeIsNULL == TRUE)
  8682. {
  8683. int l = 0;
  8684. strcpy(fname, ChargePointMaxProfile_JSON);
  8685. if((access(fname,F_OK))!=-1)
  8686. {
  8687. strcpy(chargingProfiles[l], fname);
  8688. l = l + 1;
  8689. }
  8690. strcpy(fname, TxDefaultProfile_0_JSON);
  8691. if((access(fname,F_OK))!=-1)
  8692. {
  8693. strcpy(chargingProfiles[l], fname);
  8694. l = l + 1;
  8695. }
  8696. ChargeProfileCount = l;
  8697. }
  8698. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8699. {
  8700. strcpy(fname, ChargePointMaxProfile_JSON);
  8701. if((access(fname,F_OK))!=-1)
  8702. {
  8703. strcpy(chargingProfiles[0], fname);
  8704. ChargeProfileCount = 1;
  8705. }
  8706. }
  8707. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8708. {
  8709. strcpy(fname, TxDefaultProfile_0_JSON);
  8710. if((access(fname,F_OK))!=-1)
  8711. {
  8712. strcpy(chargingProfiles[0], fname);
  8713. ChargeProfileCount = 1;
  8714. }
  8715. }
  8716. break;
  8717. default:
  8718. if(chargingProfilePurposeIsNULL == TRUE)
  8719. {
  8720. int m = 0;
  8721. memset(fname, 0, ARRAY_SIZE(fname));
  8722. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8723. if((access(fname,F_OK))!=-1)
  8724. {
  8725. strcpy(chargingProfiles[m], fname);
  8726. m = m + 1;
  8727. }
  8728. memset(fname, 0, ARRAY_SIZE(fname));
  8729. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8730. if((access(fname,F_OK))!=-1)
  8731. {
  8732. strcpy(chargingProfiles[m], fname);
  8733. m = m + 1;
  8734. }
  8735. ChargeProfileCount = m;
  8736. }
  8737. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8738. {
  8739. //strcpy(fname, TxDefaultProfile_1_JSON);
  8740. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8741. if((access(fname,F_OK))!=-1)
  8742. {
  8743. strcpy(chargingProfiles[0], fname);
  8744. ChargeProfileCount = 1;
  8745. }
  8746. }
  8747. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8748. {
  8749. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8750. if((access(fname,F_OK))!=-1)
  8751. {
  8752. strcpy(chargingProfiles[0], fname);
  8753. ChargeProfileCount = 1;
  8754. }
  8755. //strcpy(fname, TxProfile_1_JSON);
  8756. }
  8757. //strcpy(fname, ChargePointMaxProfile_JSON );
  8758. break;
  8759. }
  8760. }
  8761. else // Check all Charging Profiles
  8762. {
  8763. int i = 0;
  8764. char fnametemp[200]={0};
  8765. ChargeProfileCount = 0;
  8766. //Check ChargePointMaxProfile.json exit
  8767. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  8768. {
  8769. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  8770. i = i + 1;
  8771. }
  8772. //Check TxDefaultProfile_0.json exit
  8773. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  8774. {
  8775. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  8776. i = i + 1;
  8777. }
  8778. //Check TxDefaultProfile_%d.json
  8779. for(int j=1; j <= gunTotalNumber; j++)
  8780. {
  8781. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8782. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  8783. if((access(fnametemp,F_OK))!=-1)
  8784. {
  8785. strcpy(chargingProfiles[i], fnametemp);
  8786. i = i + 1;
  8787. }
  8788. }
  8789. //Check TxProfile_%d.json
  8790. for(int j=1; j <= gunTotalNumber; j++)
  8791. {
  8792. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8793. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  8794. if((access(fnametemp,F_OK))!=-1)
  8795. {
  8796. strcpy(chargingProfiles[i], fnametemp);
  8797. i = i + 1;
  8798. }
  8799. }
  8800. ChargeProfileCount = i;
  8801. }// End connectorIsNULL is TRUE
  8802. if(ChargeProfileCount == 0)
  8803. {
  8804. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8805. goto end;
  8806. }
  8807. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8808. {
  8809. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8810. goto end;
  8811. }
  8812. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8813. {
  8814. memset(str, 0, ARRAY_SIZE(str));
  8815. // clear temp file
  8816. sprintf(str,"rm -f %s",temp);
  8817. system(str);
  8818. for(int k=0; k < ChargeProfileCount; k++)
  8819. {
  8820. memset(str, 0, ARRAY_SIZE(str));
  8821. //clear file in C
  8822. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8823. system(str);
  8824. }
  8825. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8826. goto end;
  8827. }
  8828. else if(connectorIsNULL == TRUE)
  8829. {
  8830. for(int k=0; k < ChargeProfileCount; k++)
  8831. {
  8832. fptr1 = fopen(chargingProfiles[k], "r");
  8833. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  8834. //Check Charging Profile Count
  8835. while(fscanf(fptr1, "%s", word) != EOF)
  8836. {
  8837. //DEBUG_INFO("word=%s\n",word);
  8838. if(strstr(word, "chargingProfileId")!= NULL)
  8839. {
  8840. //DEBUG_INFO("test chargingProfileId \n");
  8841. n_chargingProfile = n_chargingProfile + 1;
  8842. //DEBUG_INFO("chargingProfileId Found\n");
  8843. }
  8844. }
  8845. rewind(fptr1);
  8846. //search Charging Profile Element
  8847. //int i= 0;
  8848. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8849. {
  8850. json_object *tmpProfilee;
  8851. tmpProfilee = json_tokener_parse(sLineWord);
  8852. if(!is_error(tmpProfilee))
  8853. {
  8854. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8855. {
  8856. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8857. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8858. }
  8859. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8860. {
  8861. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8862. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8863. }
  8864. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8865. {
  8866. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8867. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8868. }
  8869. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8870. {
  8871. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8872. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8873. }
  8874. }
  8875. json_object_put(tmpProfilee);
  8876. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8877. {
  8878. //------- not write to fptr2-------//
  8879. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8880. //clearflag = TRUE;
  8881. }
  8882. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8883. {
  8884. //------- not write to fptr2-------//
  8885. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8886. }
  8887. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8888. {
  8889. //------- not write to fptr2-------//
  8890. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8891. }
  8892. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8893. {
  8894. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8895. }
  8896. else
  8897. {
  8898. fprintf(fptr2, sLineWord);//writing data into file
  8899. }
  8900. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8901. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8902. if(clearflag == TRUE)
  8903. {
  8904. fclose(fptr1);
  8905. fclose(fptr2);
  8906. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8907. system(str);
  8908. // clear temp file
  8909. sprintf(str,"rm -f %s",temp);
  8910. system(str);
  8911. }
  8912. else
  8913. {
  8914. fclose(fptr1);
  8915. fclose(fptr2);
  8916. memset(str, 0, ARRAY_SIZE(str));
  8917. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8918. system(str);
  8919. resultRename = rename(temp, chargingProfiles[k]);
  8920. if(resultRename == 0)
  8921. {
  8922. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8923. }
  8924. else
  8925. {
  8926. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8927. }
  8928. if(comfirmstr[0]== 0)
  8929. {
  8930. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8931. }
  8932. //Check chargingProfile is empty file
  8933. /*------ Read the file ----------------*/
  8934. fptr1=fopen(chargingProfiles[k],"r");
  8935. ch=fgetc(fptr1);
  8936. rewind(fptr1);
  8937. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8938. if(ch!=EOF)
  8939. {
  8940. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8941. {
  8942. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8943. if(sLineWord[0]=='\0')
  8944. {
  8945. isEmptyFile = TRUE;
  8946. break;
  8947. }
  8948. else
  8949. {
  8950. isEmptyFile = FALSE;
  8951. break;
  8952. }
  8953. }
  8954. }
  8955. else
  8956. isEmptyFile = TRUE;
  8957. fclose(fptr1);
  8958. if(isEmptyFile == TRUE)
  8959. {
  8960. memset(str, 0, ARRAY_SIZE(str));
  8961. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8962. system(str);
  8963. }
  8964. }
  8965. }// End of while(int k=0; k < ChargePointCount; k++)
  8966. }
  8967. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8968. {
  8969. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8970. for(int k=0; k < ChargeProfileCount; k++)
  8971. {
  8972. fptr1 = fopen(chargingProfiles[k], "r");
  8973. fptr2 = fopen(temp, "w+");
  8974. //Check Charging Profile Count
  8975. while(fscanf(fptr1, "%s", word) != EOF)
  8976. {
  8977. //DEBUG_INFO("word=%s\n",word);
  8978. if(strstr(word, "chargingProfileId")!= NULL)
  8979. {
  8980. n_chargingProfile = n_chargingProfile + 1;
  8981. }
  8982. }
  8983. rewind(fptr1);
  8984. //search Charging Profile Element
  8985. //int i= 0;
  8986. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8987. {
  8988. json_object *tmpProfilee;
  8989. tmpProfilee = json_tokener_parse(sLineWord);
  8990. if(!is_error(tmpProfilee))
  8991. {
  8992. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8993. {
  8994. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8995. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8996. }
  8997. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8998. {
  8999. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9000. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9001. }
  9002. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9003. {
  9004. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9005. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9006. }
  9007. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9008. {
  9009. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9010. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9011. }
  9012. }
  9013. json_object_put(tmpProfilee);
  9014. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9015. {
  9016. //------- not write to fptr2-------//
  9017. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9018. //clearflag = TRUE;
  9019. }
  9020. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9021. {
  9022. //------- not write to fptr2-------//
  9023. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9024. }
  9025. else if(stackLevelIsNULL == TRUE)
  9026. {
  9027. //Clear Whole File
  9028. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9029. clearflag = TRUE;
  9030. break;
  9031. }
  9032. else
  9033. {
  9034. fprintf(fptr2, sLineWord);//writing data into file
  9035. }
  9036. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9037. }
  9038. if(clearflag == TRUE)
  9039. {
  9040. fclose(fptr1);
  9041. fclose(fptr2);
  9042. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9043. system(str);
  9044. // clear temp file
  9045. sprintf(str,"rm -f %s",temp);
  9046. system(str);
  9047. }
  9048. else
  9049. {
  9050. fclose(fptr1);
  9051. fclose(fptr2);
  9052. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9053. system(str);
  9054. resultRename = rename(temp, chargingProfiles[k]);
  9055. if(resultRename == 0)
  9056. {
  9057. DEBUG_INFO("File ChargingProfile renamed successfully");
  9058. }
  9059. else
  9060. {
  9061. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9062. }
  9063. if(comfirmstr[0]== 0)
  9064. {
  9065. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9066. }
  9067. //Check chargingProfile is empty file
  9068. /*------ Read the file ----------------*/
  9069. fptr1=fopen(chargingProfiles[k],"r");
  9070. ch=fgetc(fptr1);
  9071. rewind(fptr1);
  9072. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9073. if(ch!=EOF)
  9074. {
  9075. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9076. {
  9077. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9078. if(sLineWord[0]=='\0')
  9079. {
  9080. isEmptyFile = TRUE;
  9081. break;
  9082. }
  9083. else
  9084. {
  9085. isEmptyFile = FALSE;
  9086. break;
  9087. }
  9088. }
  9089. }
  9090. else
  9091. isEmptyFile = TRUE;
  9092. fclose(fptr1);
  9093. if(isEmptyFile == TRUE)
  9094. {
  9095. memset(str, 0, ARRAY_SIZE(str));
  9096. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9097. system(str);
  9098. }
  9099. /*------- End of reading ---------------*/
  9100. }
  9101. } // while(int k=0; k < ChargeProfileCount; k++)
  9102. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9103. end:
  9104. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9105. {
  9106. if(connectorIdInt == 0)
  9107. {
  9108. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9109. {
  9110. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  9111. }
  9112. }
  9113. else
  9114. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  9115. }
  9116. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9117. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9118. return result;
  9119. }
  9120. void createFirmwareVersionByDataTransfer(void)
  9121. {
  9122. json_object *FirmwareDataTransfer = json_object_new_object();
  9123. // AC & DC model
  9124. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9125. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9126. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9127. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9128. // DC model
  9129. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9130. {
  9131. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9132. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9133. (gunType[3] != GUN_TYPE_UNKNOWN))
  9134. {
  9135. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9136. }
  9137. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9138. {
  9139. // DS DM DW
  9140. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9141. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9142. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9143. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9144. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9145. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9146. }
  9147. else
  9148. {
  9149. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9150. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9151. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9152. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9153. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9154. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9155. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9156. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9157. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9158. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9159. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9160. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9161. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9162. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9163. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9164. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9165. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9166. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9167. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9168. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9169. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9170. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9171. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9172. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9173. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9174. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9175. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9176. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9177. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9178. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9179. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9180. }
  9181. }
  9182. // 4G model
  9183. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9184. {
  9185. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9186. }
  9187. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9188. json_object_put(FirmwareDataTransfer);
  9189. }
  9190. int handleDataTransferRequest(char *uuid, char *payload)
  9191. {
  9192. mtrace();
  9193. json_object *response = json_object_new_object();
  9194. int result = FAIL;
  9195. char tempvendorId[255]={0};
  9196. char tempmessageId[50]={0};
  9197. char tempdata[1024]={0};
  9198. char message[2048]={0};
  9199. DEBUG_INFO("handleDataTransferRequest...\n");
  9200. if((uuid != NULL) && (payload != NULL))
  9201. {
  9202. json_object *DataTransfer;
  9203. DataTransfer = json_tokener_parse(payload);
  9204. if(!is_error(DataTransfer))
  9205. {
  9206. // Required data
  9207. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9208. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9209. // Optional data
  9210. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9211. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9212. if(json_object_object_get(DataTransfer, "data") != NULL)
  9213. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9214. result = PASS;
  9215. }
  9216. json_object_put(DataTransfer);
  9217. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9218. {
  9219. // Send all moudle firmware version on EVSE
  9220. createFirmwareVersionByDataTransfer();
  9221. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9222. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData));
  9223. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9224. json_object_put(response);
  9225. }
  9226. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9227. {
  9228. system("/usr/bin/run_tmate_restart.sh &");
  9229. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9230. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9231. json_object_put(response);
  9232. }
  9233. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9234. {
  9235. json_object *data;
  9236. data = json_tokener_parse(tempdata);
  9237. if(!is_error(data))
  9238. {
  9239. 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))
  9240. {
  9241. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9242. memset(&ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9243. if(json_object_object_get(data, "SOC") != NULL)
  9244. {
  9245. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9246. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9247. }
  9248. if(json_object_object_get(data, "Energy") != NULL)
  9249. {
  9250. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9251. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9252. }
  9253. if(json_object_object_get(data, "Duration") != NULL)
  9254. {
  9255. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9256. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9257. }
  9258. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9259. }
  9260. else
  9261. {
  9262. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9263. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9264. }
  9265. }
  9266. else
  9267. {
  9268. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9269. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9270. }
  9271. json_object_put(data);
  9272. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9273. json_object_put(response);
  9274. }
  9275. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9276. {
  9277. json_object *data;
  9278. data = json_tokener_parse(tempdata);
  9279. if(!is_error(data))
  9280. {
  9281. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9282. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9283. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9284. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9285. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9286. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9287. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9288. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9289. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9290. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9291. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9292. }
  9293. else
  9294. {
  9295. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9296. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9297. }
  9298. json_object_put(data);
  9299. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9300. json_object_put(response);
  9301. }
  9302. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9303. {
  9304. json_object *data;
  9305. data = json_tokener_parse(tempdata);
  9306. if(!is_error(data))
  9307. {
  9308. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9309. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9310. if(json_object_object_get(data, "idToken") != NULL)
  9311. {
  9312. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9313. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9314. }
  9315. else
  9316. {
  9317. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9318. json_object_object_add(response, "data", json_object_new_string("idToken not found."));
  9319. }
  9320. if(json_object_object_get(data, "price") != NULL) //v1.0
  9321. {
  9322. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9323. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9324. }
  9325. else if(json_object_object_get(data, "priceText") != NULL) //v2.0
  9326. {
  9327. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  9328. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  9329. }
  9330. else
  9331. {
  9332. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9333. json_object_object_add(response, "data", json_object_new_string("price or priceText not found."));
  9334. }
  9335. }
  9336. else
  9337. {
  9338. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9339. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9340. }
  9341. json_object_put(data);
  9342. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9343. json_object_put(response);
  9344. }
  9345. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9346. {
  9347. json_object *data;
  9348. data = json_tokener_parse(tempdata);
  9349. if(!is_error(data))
  9350. {
  9351. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9352. if(json_object_object_get(data, "txId") != NULL)
  9353. {
  9354. // California pricing V1.0
  9355. DEBUG_INFO("California pricing V1.0\n");
  9356. DEBUG_INFO("txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9357. sprintf((char*)dmsVersion, "1.0");
  9358. for(int idx = 0;idx<gunTotalNumber;idx++)
  9359. {
  9360. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9361. {
  9362. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9363. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9364. if(json_object_object_get(data, "description") != NULL)
  9365. {
  9366. // California pricing V1.0
  9367. DEBUG_INFO("California pricing V1.0\n");
  9368. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9369. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9370. }
  9371. }
  9372. }
  9373. }
  9374. else if(json_object_object_get(data, "transactionId") != NULL)
  9375. {
  9376. // California pricing V2.0
  9377. DEBUG_INFO("California pricing V2.0\n");
  9378. DEBUG_INFO("transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9379. sprintf((char*)dmsVersion, "2.0");
  9380. for(int idx=0;idx<gunTotalNumber;idx++)
  9381. {
  9382. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9383. {
  9384. if(json_object_object_get(data, "timestamp") != NULL)
  9385. {
  9386. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9387. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9388. }
  9389. else
  9390. {
  9391. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9392. json_object_object_add(response, "data", json_object_new_string("timestamp not found."));
  9393. }
  9394. if(json_object_object_get(data, "meterValue") != NULL)
  9395. {
  9396. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9397. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9398. }
  9399. else
  9400. {
  9401. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9402. json_object_object_add(response, "data", json_object_new_string("meterValue not found."));
  9403. }
  9404. if(json_object_object_get(data, "cost") != NULL)
  9405. {
  9406. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9407. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9408. }
  9409. else
  9410. {
  9411. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9412. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  9413. }
  9414. if(json_object_object_get(data, "state") != NULL)
  9415. {
  9416. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9417. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9418. }
  9419. else
  9420. {
  9421. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9422. json_object_object_add(response, "data", json_object_new_string("state not found."));
  9423. }
  9424. if(json_object_object_get(data, "chargingPrice") != NULL)
  9425. {
  9426. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9427. {
  9428. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9429. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9430. }
  9431. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9432. {
  9433. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9434. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9435. }
  9436. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9437. {
  9438. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9439. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9440. }
  9441. }
  9442. else
  9443. {
  9444. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9445. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9446. }
  9447. if(json_object_object_get(data, "idlePrice") != NULL)
  9448. {
  9449. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9450. {
  9451. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9452. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9453. }
  9454. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9455. {
  9456. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9457. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9458. }
  9459. }
  9460. if(json_object_object_get(data, "nextPeriod") != NULL)
  9461. {
  9462. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9463. {
  9464. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9465. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9466. }
  9467. else
  9468. {
  9469. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9470. json_object_object_add(response, "data", json_object_new_string("atTime not found."));
  9471. }
  9472. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9473. {
  9474. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9475. {
  9476. 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")));
  9477. 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"));
  9478. }
  9479. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9480. {
  9481. 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")));
  9482. 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"));
  9483. }
  9484. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9485. {
  9486. 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")));
  9487. 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"));
  9488. }
  9489. }
  9490. else
  9491. {
  9492. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9493. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9494. }
  9495. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9496. {
  9497. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9498. {
  9499. 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")));
  9500. 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"));
  9501. }
  9502. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9503. {
  9504. 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")));
  9505. 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"));
  9506. }
  9507. }
  9508. }
  9509. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9510. {
  9511. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9512. {
  9513. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9514. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9515. }
  9516. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9517. {
  9518. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9519. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9520. }
  9521. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9522. {
  9523. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9524. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9525. }
  9526. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus") != NULL)
  9527. {
  9528. DEBUG_INFO("triggerMeterValue-atCPStatus: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  9529. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atCPStatus, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  9530. }
  9531. }
  9532. }
  9533. }
  9534. }
  9535. else
  9536. {
  9537. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9538. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  9539. }
  9540. }
  9541. else
  9542. {
  9543. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9544. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9545. }
  9546. json_object_put(data);
  9547. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9548. json_object_put(response);
  9549. }
  9550. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9551. {
  9552. json_object *data;
  9553. data = json_tokener_parse(tempdata);
  9554. if(!is_error(data))
  9555. {
  9556. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9557. if(json_object_object_get(data, "txId") != NULL)
  9558. {
  9559. DEBUG_INFO("v1.0 txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9560. for(int idx = 0;idx<gunTotalNumber;idx++)
  9561. {
  9562. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9563. {
  9564. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9565. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9566. if(json_object_object_get(data, "description") != NULL)
  9567. {
  9568. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9569. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  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("description not found."));
  9575. }
  9576. }
  9577. }
  9578. }
  9579. else if(json_object_object_get(data, "transactionId") != NULL)
  9580. {
  9581. DEBUG_INFO("v2.0 transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9582. for(int idx = 0;idx<gunTotalNumber;idx++)
  9583. {
  9584. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9585. {
  9586. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9587. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  9588. if(json_object_object_get(data, "cost") != NULL)
  9589. {
  9590. DEBUG_INFO("cost: %s\n", json_object_get_string(json_object_object_get(data, "cost")));
  9591. ShmOCPP16DataPH->Cost.FinalCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9592. }
  9593. else
  9594. {
  9595. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9596. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  9597. }
  9598. if(json_object_object_get(data, "priceText") != NULL)
  9599. {
  9600. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  9601. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].priceText, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  9602. }
  9603. else
  9604. {
  9605. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9606. json_object_object_add(response, "data", json_object_new_string("priceText not found."));
  9607. }
  9608. if(json_object_object_get(data, "qrCodeText") != NULL)
  9609. {
  9610. DEBUG_INFO(": %s\n", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  9611. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].qrCodeText, "%s", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  9612. }
  9613. }
  9614. }
  9615. }
  9616. else
  9617. {
  9618. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9619. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  9620. }
  9621. }
  9622. else
  9623. {
  9624. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9625. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9626. }
  9627. json_object_put(data);
  9628. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9629. json_object_put(response);
  9630. }
  9631. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9632. {
  9633. json_object *data;
  9634. data = json_tokener_parse(tempdata);
  9635. if(!is_error(data))
  9636. {
  9637. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9638. if(json_object_object_get(data, "Content_Type") != NULL)
  9639. {
  9640. 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))
  9641. {
  9642. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9643. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9644. {
  9645. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9646. }
  9647. }
  9648. else
  9649. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9650. }
  9651. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9652. }
  9653. else
  9654. {
  9655. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9656. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9657. }
  9658. json_object_put(data);
  9659. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9660. json_object_put(response);
  9661. }
  9662. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9663. {
  9664. json_object *data;
  9665. data = json_tokener_parse(tempdata);
  9666. if(!is_error(data))
  9667. {
  9668. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9669. if(json_object_object_get(data, "ConnectorId") != NULL)
  9670. {
  9671. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9672. }
  9673. if(json_object_object_get(data, "SerialNo") != NULL)
  9674. {
  9675. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9676. }
  9677. if(json_object_object_get(data, "Page_Index") != NULL)
  9678. {
  9679. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9680. }
  9681. if(json_object_object_get(data, "Duration") != NULL)
  9682. {
  9683. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9684. }
  9685. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9686. }
  9687. else
  9688. {
  9689. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9690. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9691. }
  9692. json_object_put(data);
  9693. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9694. json_object_put(response);
  9695. }
  9696. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9697. {
  9698. json_object *data;
  9699. data = json_tokener_parse(tempdata);
  9700. if(!is_error(data))
  9701. {
  9702. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9703. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9704. {
  9705. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9706. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9707. else
  9708. {
  9709. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9710. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9711. }
  9712. }
  9713. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9714. {
  9715. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9716. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9717. else
  9718. {
  9719. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9720. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9721. }
  9722. }
  9723. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9724. {
  9725. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9726. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9727. else
  9728. {
  9729. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9730. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9731. }
  9732. }
  9733. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9734. {
  9735. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9736. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9737. else
  9738. {
  9739. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9740. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9741. }
  9742. }
  9743. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9744. {
  9745. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9746. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9747. else
  9748. {
  9749. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9750. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9751. }
  9752. }
  9753. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9754. {
  9755. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9756. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9757. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9758. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9759. else
  9760. {
  9761. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9762. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9763. }
  9764. }
  9765. if(json_object_object_get(data, "isAuthentication") != NULL)
  9766. {
  9767. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9768. {
  9769. case 0:
  9770. case 1:
  9771. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9772. break;
  9773. default:
  9774. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9775. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9776. break;
  9777. }
  9778. }
  9779. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9780. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9781. }
  9782. else
  9783. {
  9784. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9785. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9786. }
  9787. json_object_put(data);
  9788. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9789. json_object_put(response);
  9790. }
  9791. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9792. {
  9793. json_object *data;
  9794. data = json_tokener_parse(tempdata);
  9795. if(!is_error(data))
  9796. {
  9797. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9798. if(json_object_object_get(data, "stationName") != NULL)
  9799. {
  9800. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9801. }
  9802. else
  9803. {
  9804. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9805. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9806. }
  9807. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9808. {
  9809. ShmOCPP16DataPH->TcciCustomData.ChargerInfoReq = 1;
  9810. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9811. ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name);
  9812. }
  9813. }
  9814. else
  9815. {
  9816. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9817. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9818. }
  9819. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9820. json_object_put(response);
  9821. }
  9822. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9823. {
  9824. json_object *data;
  9825. data = json_tokener_parse(tempdata);
  9826. if(!is_error(data))
  9827. {
  9828. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9829. if(json_object_object_get(data, "weatherId") != NULL)
  9830. {
  9831. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9832. }
  9833. else
  9834. {
  9835. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9836. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9837. }
  9838. if(json_object_object_get(data, "Temperature") != NULL)
  9839. {
  9840. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9841. }
  9842. else
  9843. {
  9844. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9845. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9846. }
  9847. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9848. {
  9849. ShmOCPP16DataPH->TcciCustomData.WeatherInfoReq = 1;
  9850. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9851. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId,
  9852. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature);
  9853. }
  9854. }
  9855. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9856. {
  9857. json_object *data;
  9858. data = json_tokener_parse(tempdata);
  9859. if(!is_error(data))
  9860. {
  9861. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9862. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9863. {
  9864. ShmOCPP16DataPH->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9865. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9866. }
  9867. else
  9868. {
  9869. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9870. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9871. }
  9872. }
  9873. else
  9874. {
  9875. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9876. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9877. }
  9878. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9879. json_object_put(response);
  9880. }
  9881. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  9882. {
  9883. json_object *data;
  9884. data = json_tokener_parse(tempdata);
  9885. if(!is_error(data))
  9886. {
  9887. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9888. {
  9889. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  9890. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9891. if(gun_index < gunTotalNumber)
  9892. {
  9893. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9894. {
  9895. json_object *responsedata = json_object_new_object();
  9896. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId));
  9897. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  9898. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16DataPH->TcciCustomData.SerialNo[gun_index]));
  9899. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp));
  9900. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  9901. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  9902. }
  9903. else
  9904. {
  9905. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9906. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  9907. }
  9908. }
  9909. else
  9910. {
  9911. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9912. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  9913. }
  9914. }
  9915. else
  9916. {
  9917. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9918. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9919. }
  9920. }
  9921. else
  9922. {
  9923. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9924. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9925. }
  9926. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9927. json_object_put(response);
  9928. }
  9929. else
  9930. {
  9931. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9932. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9933. }
  9934. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9935. json_object_put(response);
  9936. }
  9937. else
  9938. {
  9939. // Can not find valid message id
  9940. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9941. }
  9942. }
  9943. else
  9944. {
  9945. // Payload is null
  9946. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9947. }
  9948. LWS_Send(message);
  9949. return result;
  9950. }
  9951. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9952. {
  9953. mtrace();
  9954. int result = FAIL;
  9955. int connectorIdInt, durationInt;
  9956. char chargingRateUnitStr[4]={0};
  9957. char comfirmstr[20];
  9958. int confirmPeriods = 0;
  9959. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9960. json_object *GetCompositeSchedule;
  9961. GetCompositeSchedule = json_tokener_parse(payload);
  9962. if(!is_error(GetCompositeSchedule))
  9963. {
  9964. // Required data
  9965. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9966. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9967. else
  9968. connectorIdInt = -1;
  9969. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9970. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9971. else
  9972. durationInt = 86400;
  9973. // Optional data
  9974. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9975. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9976. }
  9977. json_object_put(GetCompositeSchedule);
  9978. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9979. if((connectorIdInt == 0) ||
  9980. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9981. {
  9982. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9983. struct StructChargingProfile tmpProfile[1];
  9984. if(strstr(chargingRateUnitStr, "W") != NULL)
  9985. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9986. else
  9987. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9988. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9989. {
  9990. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9991. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9992. }
  9993. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9994. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9995. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9996. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9997. {
  9998. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9999. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10000. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  10001. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  10002. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  10003. {
  10004. confirmPeriods = idx;
  10005. break;
  10006. }
  10007. }
  10008. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  10009. {
  10010. confirmPeriods += 1;
  10011. }
  10012. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  10013. }
  10014. else
  10015. {
  10016. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  10017. }
  10018. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  10019. return result;
  10020. }
  10021. int handleGetConfigurationRequest(char *uuid, char *payload)
  10022. {
  10023. mtrace();
  10024. int result = FAIL;
  10025. int MaxKeySupported = 0;
  10026. int n_keys = 0;
  10027. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  10028. DEBUG_INFO("handleGetConfigurationRequest...\n");
  10029. json_object *GetConfiguration;
  10030. GetConfiguration = json_tokener_parse(payload);
  10031. if(!is_error(GetConfiguration))
  10032. {
  10033. // Optional data
  10034. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10035. {
  10036. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10037. {
  10038. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10039. n_keys = idx + 1;
  10040. }
  10041. }
  10042. }
  10043. json_object_put(GetConfiguration);
  10044. UnknownKeynum = 0;
  10045. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10046. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10047. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10048. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10049. if(n_keys != 0)
  10050. {
  10051. for(int i=0;i<n_keys;i++)
  10052. {
  10053. getKeyValue(requestKey[i]);
  10054. }
  10055. }
  10056. else
  10057. {
  10058. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10059. getKeyValue("");
  10060. }
  10061. processUnkownKey();
  10062. sendGetConfigurationConfirmation(uuid);
  10063. return result;
  10064. }
  10065. static char fnamePlusPath[100]={0};
  10066. static char fnamePWithNoPath[60]={0};
  10067. void checkUploadLog(void)
  10068. {
  10069. FILE *fp;
  10070. /* Open the command for reading. */
  10071. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10072. if (fp == NULL) {
  10073. DEBUG_WARN("Failed to run command\n" );
  10074. exit(1);
  10075. }
  10076. int ftppathlen = 0;
  10077. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10078. int i = 0;
  10079. /* Read the output a line at a time - output it. */
  10080. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10081. if(i==0)
  10082. {
  10083. ftppathlen = strlen(fnamePlusPath);
  10084. DEBUG_INFO("%s\n", fnamePlusPath);
  10085. fnamePlusPath[ftppathlen]='\0';
  10086. break;
  10087. }
  10088. i= i+1;
  10089. }
  10090. /* close */
  10091. pclose(fp);
  10092. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10093. {
  10094. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10095. {
  10096. fnamePlusPath[k]='\0';
  10097. }
  10098. }
  10099. i=1;
  10100. //char fname[60]={0};
  10101. while(i < ftppathlen)
  10102. {
  10103. int len=ftppathlen-i;
  10104. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10105. {
  10106. DEBUG_INFO("compare '/' all right\n");
  10107. break;
  10108. }
  10109. i=i+1;
  10110. }
  10111. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  10112. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  10113. fnamePWithNoPath[i+1] = '\0';
  10114. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  10115. {
  10116. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  10117. {
  10118. fnamePWithNoPath[j]='\0';
  10119. }
  10120. }
  10121. FILE* fp1 = fopen(fnamePlusPath, "r");
  10122. if (fp1)
  10123. {
  10124. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  10125. // file exists
  10126. fclose(fp1);
  10127. }
  10128. else
  10129. {
  10130. // file doesn't exist
  10131. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  10132. }
  10133. }
  10134. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  10135. {
  10136. mtrace();
  10137. int result = FAIL;
  10138. time_t CurrentTime;
  10139. struct tm *tm;
  10140. pthread_t th_Status;
  10141. CurrentTime = time(NULL);
  10142. tm = localtime(&CurrentTime);
  10143. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  10144. 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);
  10145. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  10146. if(!interLock.isGetDiagnosticGoing)
  10147. {
  10148. interLock.isGetDiagnosticGoing = 1;
  10149. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  10150. sleep(1);
  10151. }
  10152. else
  10153. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  10154. return result;
  10155. }
  10156. void* GetDiagnosticsProcess(void* data)
  10157. {
  10158. pthread_detach(pthread_self());
  10159. mtrace();
  10160. int retriesInt=0, retryIntervalInt=0;
  10161. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  10162. 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};
  10163. int port=0;
  10164. int isSuccess = FALSE;
  10165. char ftpbuf[200]={0};
  10166. char cmdBuf[2048];
  10167. struct tm *tmNow;
  10168. time_t CurrentTime;
  10169. struct tm tmStart;
  10170. struct tm tmStop;
  10171. CurrentTime = time(NULL);
  10172. tmNow=localtime(&CurrentTime);
  10173. uint16_t targetYear, targetMonth;
  10174. json_object *GetDiagnostics;
  10175. DEBUG_INFO("GetDiagnosticsProcess...\n");
  10176. GetDiagnostics = json_tokener_parse(data);
  10177. if(!is_error(GetDiagnostics))
  10178. {
  10179. // Required data
  10180. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  10181. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  10182. // Optional data
  10183. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  10184. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  10185. else
  10186. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  10187. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  10188. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  10189. else
  10190. retryIntervalInt = 30;
  10191. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  10192. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  10193. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  10194. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  10195. }
  10196. json_object_put(GetDiagnostics);
  10197. // Pack log to compress file
  10198. 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) &&
  10199. (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))
  10200. {
  10201. // Pack system log
  10202. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10203. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10204. targetYear = tmStart.tm_year;
  10205. targetMonth = tmStart.tm_mon;
  10206. do
  10207. {
  10208. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10209. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  10210. if(targetMonth+1>=13)
  10211. {
  10212. targetYear += 1;
  10213. targetMonth = 1;
  10214. }
  10215. else
  10216. {
  10217. targetMonth += 1;
  10218. }
  10219. }while((targetYear < (tmNow->tm_year+1900)) ||
  10220. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10221. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  10222. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  10223. system(cmdBuf);
  10224. // Pack charging & event log
  10225. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10226. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  10227. targetYear = tmStart.tm_year;
  10228. targetMonth = tmStart.tm_mon;
  10229. do
  10230. {
  10231. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10232. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  10233. if(targetMonth+1>=13)
  10234. {
  10235. targetYear += 1;
  10236. targetMonth = 1;
  10237. }
  10238. else
  10239. {
  10240. targetMonth += 1;
  10241. }
  10242. }while((targetYear < (tmNow->tm_year+1900)) ||
  10243. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10244. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10245. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10246. system(cmdBuf);
  10247. // Combine log file
  10248. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10249. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10250. }
  10251. else
  10252. {
  10253. system("exec /root/logPackTools 'log' 6");
  10254. }
  10255. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  10256. system(cmdBuf);
  10257. checkUploadLog();
  10258. //****************location*******************/
  10259. if(strcmp(locationstr,"")==0)
  10260. {
  10261. DEBUG_INFO("location is <Empty>!\n");
  10262. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10263. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10264. goto end;
  10265. }
  10266. memset(protocol, 0, ARRAY_SIZE(protocol));
  10267. memset(user, 0, ARRAY_SIZE(user) );
  10268. memset(password, 0, ARRAY_SIZE(password));
  10269. memset(host, 0, ARRAY_SIZE(host));
  10270. memset(path, 0, ARRAY_SIZE(path));
  10271. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10272. memset(host1, 0, ARRAY_SIZE(host1));
  10273. memset(path1, 0, ARRAY_SIZE(path1));
  10274. /*location: ftp://user:password@host:port/path*/
  10275. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10276. if((access(fnamePlusPath,F_OK))!=-1)
  10277. {
  10278. DEBUG_INFO("fnamePlusPath exist.\n");
  10279. }
  10280. else
  10281. {
  10282. DEBUG_INFO("fnamePlusPath not exist!\n");
  10283. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10284. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10285. goto end;
  10286. }
  10287. if(strchr(locationstr,'@')==NULL)
  10288. {
  10289. sscanf(locationstr,
  10290. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10291. protocol, host, &port, path);
  10292. strcpy(user,"anonymous");
  10293. strcpy(password,"");
  10294. }
  10295. else
  10296. {
  10297. //DEBUG_INFO("pch=%s\n", pch);
  10298. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10299. protocol, user, password, host, &port, path);
  10300. }
  10301. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10302. {
  10303. DEBUG_INFO("protocol is not ftp/http ! \n");
  10304. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10305. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10306. goto end;
  10307. }
  10308. if(strncmp(locationstr,"http", 4) == 0)
  10309. {
  10310. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10311. sprintf(ftppath,"/%s", path);
  10312. do
  10313. {
  10314. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10315. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10316. sleep(3);
  10317. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10318. if(!isSuccess)
  10319. {
  10320. DEBUG_INFO("Diagnostics fail.\n");
  10321. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10322. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10323. sleep(retryIntervalInt);
  10324. }
  10325. else
  10326. {
  10327. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10328. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10329. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10330. }
  10331. retriesInt--;
  10332. }while((isSuccess == 0)&&(retriesInt >= 0));
  10333. }
  10334. else
  10335. {
  10336. sscanf(host,"%[^/]%s",host1, path1);
  10337. if(strlen(path) > 0)
  10338. sprintf(ftppath,"/%s", path);
  10339. else
  10340. sprintf(ftppath,"/%s", path1);
  10341. int ftppathlen=strlen(ftppath);
  10342. int i=1;
  10343. char filenametemp[50];
  10344. while(i < ftppathlen)
  10345. {
  10346. int len=ftppathlen-i;
  10347. if(ftppath[len]== 47) // '/' ascll code: 47
  10348. {
  10349. DEBUG_INFO("find '/' all right\n");
  10350. break;
  10351. }
  10352. i=i+1;
  10353. }
  10354. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10355. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10356. filenametemp[i+1] = 0;
  10357. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10358. if(port == 0)
  10359. port = 21;
  10360. do
  10361. {
  10362. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10363. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10364. sleep(3);
  10365. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10366. if(!isSuccess)
  10367. {
  10368. DEBUG_INFO("Diagnostics fail.\n");
  10369. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10370. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10371. sleep(retryIntervalInt);
  10372. }
  10373. else
  10374. {
  10375. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10376. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10377. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10378. }
  10379. retriesInt--;
  10380. }while((!isSuccess)&&(retriesInt >= 0));
  10381. }
  10382. end:
  10383. system("rm -f /mnt/*");
  10384. sleep(5);
  10385. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10386. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10387. interLock.isGetDiagnosticGoing = 0;
  10388. pthread_exit(NULL);
  10389. }
  10390. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10391. {
  10392. mtrace();
  10393. int result = FAIL;
  10394. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10395. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10396. {
  10397. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10398. locallistVersion = -1;
  10399. }
  10400. else
  10401. {
  10402. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10403. locallistVersion = 0;
  10404. OCPP_getListVerion();
  10405. }
  10406. //from db.OCPP_getListVerion
  10407. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10408. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  10409. sendGetLocalListVersionConfirmation(uuid,"");
  10410. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  10411. return result;
  10412. }
  10413. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10414. {
  10415. mtrace();
  10416. int result = FAIL;
  10417. int connectorIdInt=-1;
  10418. int tempIndex = 0;
  10419. int connectorIdIsNULL, chargingProfileIsNULL;
  10420. char comfirmstr[20]={0};
  10421. char cmdBuf[512];
  10422. json_object *RemoteStartTransaction;
  10423. FILE *fp;
  10424. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10425. if(server_pending == TRUE)
  10426. {
  10427. return 0;
  10428. }
  10429. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10430. RemoteStartTransaction = json_tokener_parse(payload);
  10431. if(!is_error(RemoteStartTransaction))
  10432. {
  10433. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10434. {
  10435. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10436. }
  10437. else
  10438. {
  10439. connectorIdIsNULL = TRUE;
  10440. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10441. {
  10442. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10443. {
  10444. connectorIdIsNULL = FALSE;
  10445. connectorIdInt = (gun_index+1);
  10446. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10447. break;
  10448. }
  10449. }
  10450. }
  10451. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10452. {
  10453. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10454. // Required data
  10455. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10456. // Optional data
  10457. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10458. {
  10459. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10460. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10461. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10462. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10463. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10464. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10465. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10466. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10467. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10468. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10469. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10470. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10471. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10472. {
  10473. 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")));
  10474. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10475. 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"));
  10476. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10477. 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"));
  10478. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10479. 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")));
  10480. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10481. {
  10482. 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++)
  10483. {
  10484. 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"));
  10485. 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"));
  10486. 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)
  10487. 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"));
  10488. }
  10489. }
  10490. }
  10491. }
  10492. else
  10493. {
  10494. chargingProfileIsNULL = TRUE;
  10495. }
  10496. }
  10497. }
  10498. else
  10499. {
  10500. connectorIdIsNULL = TRUE;
  10501. }
  10502. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10503. {
  10504. DEBUG_WARN("Connector id is NULL\n.");
  10505. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10506. goto end;
  10507. }
  10508. /*
  10509. enum _SYSTEM_STATUS
  10510. {
  10511. S_BOOTING = 0,
  10512. S_IDLE, = 1
  10513. S_AUTHORIZING, = 2
  10514. S_REASSIGN_CHECK, = 3
  10515. S_REASSIGN, = 4
  10516. S_PRECHARGE, = 5
  10517. S_PREPARING_FOR_EV, = 6
  10518. S_PREPARING_FOR_EVSE, = 7
  10519. S_CHARGING, = 8
  10520. S_TERMINATING, = 9
  10521. S_COMPLETE, = 10
  10522. S_ALARM, = 11
  10523. S_FAULT = 12
  10524. }
  10525. */
  10526. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10527. {
  10528. //check Transaction active
  10529. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10530. {
  10531. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10532. {
  10533. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10534. }
  10535. else
  10536. {
  10537. tempIndex = connectorIdInt -1;
  10538. }
  10539. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10540. {
  10541. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10542. {
  10543. 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))
  10544. {
  10545. //Reserved
  10546. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10547. }
  10548. 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))
  10549. {
  10550. //Reserved
  10551. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10552. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10553. goto end;
  10554. }
  10555. else
  10556. {
  10557. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10558. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10559. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10560. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10561. {
  10562. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10563. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10564. goto end;
  10565. }
  10566. }//END FOR ELSE
  10567. }
  10568. }// END FOR CHAdeMO_QUANTITY
  10569. }
  10570. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10571. {
  10572. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10573. {
  10574. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10575. }
  10576. else
  10577. {
  10578. tempIndex = connectorIdInt -1;
  10579. }
  10580. for (int index = 0; index < CCS_QUANTITY; index++)
  10581. {
  10582. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10583. {
  10584. 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))
  10585. {
  10586. //Reserved
  10587. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10588. }
  10589. 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))
  10590. {
  10591. //Reserved
  10592. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10593. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10594. goto end;
  10595. }
  10596. else
  10597. {
  10598. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10599. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10600. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10601. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10602. {
  10603. DEBUG_WARN("CCS connector not allow start\n.");
  10604. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10605. goto end;
  10606. }
  10607. }// END FOR ELSE
  10608. }
  10609. }// END FOR CCS_QUANTITY
  10610. }
  10611. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10612. {
  10613. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10614. {
  10615. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10616. }
  10617. else
  10618. {
  10619. tempIndex = connectorIdInt -1;
  10620. }
  10621. for (int index = 0; index < GB_QUANTITY; index++)
  10622. {
  10623. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10624. {
  10625. 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))
  10626. {
  10627. //Reserved
  10628. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10629. }
  10630. 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))
  10631. {
  10632. //Reserved
  10633. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10634. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10635. goto end;
  10636. }
  10637. else
  10638. {
  10639. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10640. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10641. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10642. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10643. {
  10644. DEBUG_WARN("GB connector not allow start\n.");
  10645. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10646. goto end;
  10647. }
  10648. }// END FOR ELSE
  10649. }
  10650. } // END FOR GB_QUANTITY
  10651. }
  10652. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10653. {
  10654. tempIndex = connectorIdInt -1;
  10655. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10656. {
  10657. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10658. {
  10659. 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))
  10660. {
  10661. //Reserved
  10662. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10663. }
  10664. 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))
  10665. {
  10666. //Reserved
  10667. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10668. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10669. goto end;
  10670. }
  10671. else
  10672. {
  10673. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10674. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10675. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10676. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10677. {
  10678. DEBUG_WARN("GB connector not allow start\n.");
  10679. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10680. goto end;
  10681. }
  10682. }// END FOR ELSE
  10683. }
  10684. } // END FOR GB_QUANTITY
  10685. }
  10686. else
  10687. {
  10688. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10689. {
  10690. tempIndex = 2;
  10691. }
  10692. else
  10693. {
  10694. tempIndex = connectorIdInt -1;
  10695. }
  10696. for (int index = 0; index < AC_QUANTITY; index++)
  10697. {
  10698. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10699. {
  10700. 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))
  10701. {
  10702. //Reserved
  10703. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10704. }
  10705. 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))
  10706. {
  10707. //Reserved
  10708. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10709. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10710. goto end;
  10711. }
  10712. else
  10713. {
  10714. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10715. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10716. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10717. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10718. {
  10719. DEBUG_WARN("AC connector not allow start\n.");
  10720. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10721. goto end;
  10722. }
  10723. }//END FOR ELSE
  10724. }
  10725. }// END FOR AC_QUANTITY
  10726. }
  10727. if(chargingProfileIsNULL == FALSE)
  10728. {
  10729. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10730. {
  10731. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10732. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10733. //memset idTag
  10734. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10735. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10736. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10737. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10738. // Save profile to file
  10739. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10740. system(cmdBuf);
  10741. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10742. fp = fopen(cmdBuf, "w");
  10743. 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));
  10744. fclose(fp);
  10745. }
  10746. else
  10747. {
  10748. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10749. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10750. }
  10751. }
  10752. else
  10753. {
  10754. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10755. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10756. //memset idTag
  10757. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10758. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10759. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10760. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10761. }
  10762. }
  10763. else
  10764. {
  10765. DEBUG_WARN("Connector id over\n.");
  10766. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10767. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10768. }
  10769. end:
  10770. json_object_put(RemoteStartTransaction);
  10771. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10772. {
  10773. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10774. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10775. }
  10776. //OCPP send RemoteStartConfirmation by first.
  10777. sendRemoteStartConfirmation(uuid, comfirmstr);
  10778. return result;
  10779. }
  10780. int handleRemoteStartRequest(char *uuid, char *payload)
  10781. {
  10782. mtrace();
  10783. int result = PASS;
  10784. int connectorIdInt=-1;
  10785. int tempIndex = 0;
  10786. char comfirmstr[20]={0};
  10787. char cmdBuf[512];
  10788. json_object *RemoteStartTransaction;
  10789. FILE *fp;
  10790. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10791. if(server_pending == TRUE)
  10792. {
  10793. result = FAIL;
  10794. }
  10795. RemoteStartTransaction = json_tokener_parse(payload);
  10796. if(!is_error(RemoteStartTransaction))
  10797. {
  10798. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10799. {
  10800. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10801. }
  10802. else
  10803. {
  10804. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10805. {
  10806. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10807. {
  10808. connectorIdInt = (gun_index+1);
  10809. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10810. break;
  10811. }
  10812. }
  10813. }
  10814. if(connectorIdInt == 0)
  10815. {
  10816. DEBUG_WARN("Connector id shall not equal 0.\n");
  10817. result = FAIL;
  10818. }
  10819. else if(connectorIdInt == -1)
  10820. {
  10821. DEBUG_INFO("Connector id does not specific.\n");
  10822. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10823. {
  10824. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10825. // Required data
  10826. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10827. // Optional data
  10828. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10829. {
  10830. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10831. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10832. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10833. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10834. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10835. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10836. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10837. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10838. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10839. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10840. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10841. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10842. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10843. {
  10844. 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")));
  10845. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10846. 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"));
  10847. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10848. 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"));
  10849. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10850. 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")));
  10851. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10852. {
  10853. 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++)
  10854. {
  10855. 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"));
  10856. 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"));
  10857. 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)
  10858. 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"));
  10859. }
  10860. }
  10861. }
  10862. }
  10863. else
  10864. {
  10865. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10866. }
  10867. }
  10868. }
  10869. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10870. {
  10871. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10872. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10873. // Required data
  10874. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10875. // Optional data
  10876. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10877. {
  10878. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10879. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10880. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10881. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10882. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10883. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10884. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10885. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10886. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10887. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10888. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10889. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10890. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10891. {
  10892. 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")));
  10893. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10894. 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"));
  10895. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10896. 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"));
  10897. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10898. 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")));
  10899. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10900. {
  10901. 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++)
  10902. {
  10903. 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"));
  10904. 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"));
  10905. 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)
  10906. 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"));
  10907. }
  10908. }
  10909. }
  10910. }
  10911. else
  10912. {
  10913. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10914. }
  10915. }
  10916. else
  10917. {
  10918. DEBUG_WARN("Connector id is over maximun value.\n");
  10919. result = FAIL;
  10920. }
  10921. }
  10922. if(result == PASS)
  10923. {
  10924. if(connectorIdInt > 0)
  10925. {
  10926. //check Transaction active
  10927. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10928. {
  10929. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10930. {
  10931. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10932. }
  10933. else
  10934. {
  10935. tempIndex = connectorIdInt -1;
  10936. }
  10937. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10938. {
  10939. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10940. {
  10941. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10942. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10943. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10944. {
  10945. //Reserved
  10946. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10947. }
  10948. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10949. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10950. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10951. {
  10952. //Reserved
  10953. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10954. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10955. goto end;
  10956. }
  10957. else
  10958. {
  10959. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10960. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10961. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10962. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10963. {
  10964. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10965. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10966. goto end;
  10967. }
  10968. }//END FOR ELSE
  10969. }
  10970. }// END FOR CHAdeMO_QUANTITY
  10971. }
  10972. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10973. {
  10974. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10975. {
  10976. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10977. }
  10978. else
  10979. {
  10980. tempIndex = connectorIdInt -1;
  10981. }
  10982. for (int index = 0; index < CCS_QUANTITY; index++)
  10983. {
  10984. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10985. {
  10986. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10987. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10988. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10989. {
  10990. //Reserved
  10991. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10992. }
  10993. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10994. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10995. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10996. {
  10997. //Reserved
  10998. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10999. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11000. goto end;
  11001. }
  11002. else
  11003. {
  11004. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11005. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11006. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11007. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11008. {
  11009. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11010. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11011. goto end;
  11012. }
  11013. }// END FOR ELSE
  11014. }
  11015. }// END FOR CCS_QUANTITY
  11016. }
  11017. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11018. {
  11019. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11020. {
  11021. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11022. }
  11023. else
  11024. {
  11025. tempIndex = connectorIdInt -1;
  11026. }
  11027. for (int index = 0; index < GB_QUANTITY; index++)
  11028. {
  11029. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11030. {
  11031. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11032. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11033. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11034. {
  11035. //Reserved
  11036. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11037. }
  11038. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11039. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11040. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11041. {
  11042. //Reserved
  11043. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11044. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11045. goto end;
  11046. }
  11047. else
  11048. {
  11049. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11050. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11051. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11052. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11053. {
  11054. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11055. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11056. goto end;
  11057. }
  11058. }// END FOR ELSE
  11059. }
  11060. } // END FOR GB_QUANTITY
  11061. }
  11062. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11063. {
  11064. tempIndex = connectorIdInt -1;
  11065. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11066. {
  11067. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11068. {
  11069. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11070. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11071. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11072. {
  11073. //Reserved
  11074. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11075. }
  11076. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11077. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11078. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11079. {
  11080. //Reserved
  11081. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11082. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11083. goto end;
  11084. }
  11085. else
  11086. {
  11087. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11088. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11089. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11090. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11091. {
  11092. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11093. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11094. goto end;
  11095. }
  11096. }// END FOR ELSE
  11097. }
  11098. } // END FOR GB_QUANTITY
  11099. }
  11100. else
  11101. {
  11102. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11103. {
  11104. tempIndex = 2;
  11105. }
  11106. else
  11107. {
  11108. tempIndex = connectorIdInt -1;
  11109. }
  11110. for (int index = 0; index < AC_QUANTITY; index++)
  11111. {
  11112. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11113. {
  11114. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11115. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11116. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11117. {
  11118. //Reserved
  11119. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11120. }
  11121. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11122. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11123. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11124. {
  11125. //Reserved
  11126. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11127. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11128. goto end;
  11129. }
  11130. else
  11131. {
  11132. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11133. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11134. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11135. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11136. {
  11137. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11138. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11139. goto end;
  11140. }
  11141. }//END FOR ELSE
  11142. }
  11143. }// END FOR AC_QUANTITY
  11144. }
  11145. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11146. {
  11147. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11148. {
  11149. // Save profile to file
  11150. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  11151. system(cmdBuf);
  11152. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  11153. fp = fopen(cmdBuf, "w");
  11154. 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));
  11155. fclose(fp);
  11156. }
  11157. else
  11158. {
  11159. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11160. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11161. goto end;
  11162. }
  11163. }
  11164. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11165. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11166. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11167. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11168. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11169. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11170. }
  11171. else
  11172. {
  11173. uint8_t isHasIdleConnector = FALSE;
  11174. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11175. {
  11176. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11177. {
  11178. isHasIdleConnector = TRUE;
  11179. break;
  11180. }
  11181. }
  11182. if(isHasIdleConnector == TRUE)
  11183. {
  11184. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11185. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11186. {
  11187. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11188. {
  11189. // Save profile to file
  11190. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  11191. system(cmdBuf);
  11192. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  11193. fp = fopen(cmdBuf, "w");
  11194. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11195. fclose(fp);
  11196. refreshStartTimer(&clientTime.RemoteStartWait);
  11197. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  11198. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11199. }
  11200. else
  11201. {
  11202. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11203. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11204. }
  11205. }
  11206. else
  11207. {
  11208. refreshStartTimer(&clientTime.RemoteStartWait);
  11209. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  11210. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11211. }
  11212. }
  11213. else
  11214. {
  11215. DEBUG_INFO("There is not any connector is idle.\n");
  11216. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11217. }
  11218. }
  11219. }
  11220. else
  11221. {
  11222. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11223. }
  11224. end:
  11225. json_object_put(RemoteStartTransaction);
  11226. sendRemoteStartConfirmation(uuid, comfirmstr);
  11227. return result;
  11228. }
  11229. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11230. {
  11231. mtrace();
  11232. int result = FAIL;
  11233. int match = FALSE;
  11234. int GunNO = 0;
  11235. int tempIndex = 0;
  11236. int transactionIdInt=0;
  11237. int transactionIdIsNULL= TRUE;
  11238. char comfirmstr[20];
  11239. json_object *RemoteStopTransaction;
  11240. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11241. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11242. if(server_pending == TRUE)
  11243. {
  11244. return 0;
  11245. }
  11246. RemoteStopTransaction = json_tokener_parse(payload);
  11247. if(!is_error(RemoteStopTransaction))
  11248. {
  11249. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11250. {
  11251. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11252. transactionIdIsNULL = FALSE;
  11253. }
  11254. }
  11255. json_object_put(RemoteStopTransaction);
  11256. if(transactionIdIsNULL == FALSE)
  11257. {
  11258. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11259. {
  11260. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11261. {
  11262. //check Transaction active
  11263. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11264. {
  11265. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11266. {
  11267. tempIndex = ((gun_index==2) ? 1: 0);
  11268. }
  11269. else
  11270. {
  11271. tempIndex = gun_index;
  11272. }
  11273. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11274. {
  11275. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11276. {
  11277. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11278. {
  11279. match = TRUE;
  11280. GunNO = gun_index;
  11281. }
  11282. }
  11283. }// END FOR CHAdeMO_QUANTITY
  11284. }
  11285. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11286. {
  11287. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11288. {
  11289. tempIndex = ((gun_index==2) ? 1: 0);
  11290. }
  11291. else
  11292. {
  11293. tempIndex = gun_index;
  11294. }
  11295. for (int index = 0; index < CCS_QUANTITY; index++)
  11296. {
  11297. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11298. {
  11299. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11300. {
  11301. match = TRUE;
  11302. GunNO = gun_index;
  11303. }
  11304. }
  11305. }// END FOR CCS_QUANTITY
  11306. }
  11307. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11308. {
  11309. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11310. {
  11311. tempIndex = ((gun_index==2) ? 1: 0);
  11312. }
  11313. else
  11314. {
  11315. tempIndex = gun_index;
  11316. }
  11317. for (int index = 0; index < GB_QUANTITY; index++)
  11318. {
  11319. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11320. {
  11321. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11322. {
  11323. match = TRUE;
  11324. GunNO = gun_index;
  11325. }
  11326. }
  11327. }// END FOR GB_QUANTITY
  11328. }
  11329. else if(gunType[gun_index] == GUN_TYPE_DO)
  11330. {
  11331. tempIndex = gun_index;
  11332. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11333. {
  11334. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11335. {
  11336. 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
  11337. {
  11338. match = TRUE;
  11339. GunNO = gun_index;
  11340. }
  11341. }
  11342. }// END FOR GB_QUANTITY
  11343. }
  11344. else
  11345. {
  11346. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11347. {
  11348. tempIndex = 2;
  11349. }
  11350. else
  11351. {
  11352. tempIndex = gun_index;
  11353. }
  11354. for (int index = 0; index < AC_QUANTITY; index++)
  11355. {
  11356. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11357. {
  11358. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11359. {
  11360. match = TRUE;
  11361. GunNO = gun_index;
  11362. }
  11363. }
  11364. }// END FOR CHAdeMO_QUANTITY
  11365. } // END FOR AC ELSE
  11366. }// CHECK IF ResponseTransactionId == transactionIdInt
  11367. }//END FOR
  11368. if( match == TRUE)
  11369. {
  11370. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11371. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11372. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11373. }
  11374. else
  11375. {
  11376. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11377. }
  11378. }
  11379. else
  11380. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11381. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11382. return result;
  11383. }
  11384. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11385. {
  11386. mtrace();
  11387. int result = FAIL;
  11388. int connectorIdInt=0, reservationIdInt=0;
  11389. int tempIndex = 0;
  11390. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11391. char comfirmstr[20]={0};
  11392. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11393. int c = 0;
  11394. char *loc;
  11395. //char *ptr;
  11396. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11397. strcpy(sstrtemp, stringtrimspace(payload));
  11398. //***(1)connectorId ****/
  11399. c=0;
  11400. loc = strstr(sstrtemp, "connectorId");
  11401. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11402. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11403. {
  11404. sstr[c] = loc[strlen("connectorId")+2+c];
  11405. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11406. c++;
  11407. }
  11408. sstr[c] = '\0';
  11409. connectorIdInt = atoi(sstr);
  11410. //***(2)expiryDate ****/
  11411. loc = strstr(sstrtemp, "expiryDate");
  11412. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11413. c = 0;
  11414. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11415. {
  11416. sstr[c] = loc[3+strlen("expiryDate")+c];
  11417. c++;
  11418. }
  11419. sstr[c] = '\0';
  11420. strcpy(expiryDatestr, sstr);
  11421. //***(3)idTag ****/
  11422. loc = strstr(sstrtemp, "idTag");
  11423. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11424. c = 0;
  11425. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11426. {
  11427. sstr[c] = loc[3+strlen("idTag")+c];
  11428. c++;
  11429. }
  11430. sstr[c] = '\0';
  11431. strcpy(idTagstr, sstr);
  11432. //***(4)parentIdTag ****/
  11433. loc = strstr(sstrtemp, "parentIdTag");
  11434. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11435. c = 0;
  11436. if(loc == NULL)
  11437. {
  11438. strcpy(parentIdTagstr, "");
  11439. }
  11440. else
  11441. {
  11442. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11443. {
  11444. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11445. c++;
  11446. }
  11447. sstr[c] = '\0';
  11448. strcpy(parentIdTagstr, sstr);
  11449. }
  11450. //***(5)reservationId ****/
  11451. c=0;
  11452. loc = strstr(sstrtemp, "reservationId");
  11453. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11454. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11455. {
  11456. sstr[c] = loc[strlen("reservationId")+2+c];
  11457. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11458. c++;
  11459. }
  11460. sstr[c] = '\0';
  11461. reservationIdInt = atoi(sstr);
  11462. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11463. /*
  11464. enum SYSTEM_STATUS
  11465. {
  11466. SYS_MODE_BOOTING = 0,
  11467. SYS_MODE_IDLE = 1,
  11468. SYS_MODE_AUTHORIZING = 2,
  11469. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11470. SYS_MODE_REASSIGN = 4,
  11471. SYS_MODE_PREPARING = 5,
  11472. SYS_MODE_PREPARE_FOR_EV = 6,
  11473. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11474. SYS_MODE_CHARGING = 8,
  11475. SYS_MODE_TERMINATING = 9,
  11476. SYS_MODE_COMPLETE = 10,
  11477. SYS_MODE_ALARM = 11,
  11478. SYS_MODE_FAULT = 12,
  11479. SYS_MODE_RESERVATION = 13,
  11480. SYS_MODE_BOOKING = 14,
  11481. SYS_MODE_MAINTAIN = 15,
  11482. SYS_MODE_DEBUG = 16,
  11483. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11484. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11485. SYS_MODE_UPDATE = 19
  11486. };
  11487. */
  11488. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11489. {
  11490. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11491. goto end;
  11492. }
  11493. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11494. {
  11495. //check Transaction active
  11496. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11497. {
  11498. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11499. {
  11500. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11501. }
  11502. else
  11503. {
  11504. tempIndex = connectorIdInt -1;
  11505. }
  11506. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11507. {
  11508. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11509. {
  11510. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11511. {
  11512. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11513. {
  11514. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11515. {
  11516. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  11517. {
  11518. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11519. }
  11520. else
  11521. {
  11522. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11523. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11524. }
  11525. }
  11526. 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'))
  11527. {
  11528. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11529. }
  11530. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11531. {
  11532. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11533. }
  11534. else
  11535. {
  11536. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11537. }
  11538. }
  11539. 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
  11540. {
  11541. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11542. }
  11543. }
  11544. else
  11545. {
  11546. //replace reservation
  11547. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11548. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11549. }
  11550. }
  11551. } // END FOR CHAdeMO_QUANTITY
  11552. }
  11553. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11554. {
  11555. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11556. {
  11557. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11558. }
  11559. else
  11560. {
  11561. tempIndex = connectorIdInt -1;
  11562. }
  11563. for (int index = 0; index < CCS_QUANTITY; index++)
  11564. {
  11565. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11566. {
  11567. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11568. {
  11569. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11570. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11571. {
  11572. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11573. {
  11574. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  11575. {
  11576. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11577. }
  11578. else
  11579. {
  11580. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11581. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11582. }
  11583. }
  11584. 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'))
  11585. {
  11586. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11587. }
  11588. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11589. {
  11590. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11591. }
  11592. else
  11593. {
  11594. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11595. }
  11596. }
  11597. 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
  11598. {
  11599. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11600. }
  11601. }
  11602. else
  11603. {
  11604. //replace reservation
  11605. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11606. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11607. }
  11608. }
  11609. } // END FOR CCS_QUANTITY
  11610. }
  11611. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11612. {
  11613. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11614. {
  11615. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11616. }
  11617. else
  11618. {
  11619. tempIndex = connectorIdInt -1;
  11620. }
  11621. for (int index = 0; index < GB_QUANTITY; index++)
  11622. {
  11623. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11624. {
  11625. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11626. {
  11627. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11628. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11629. {
  11630. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11631. {
  11632. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  11633. {
  11634. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11635. }
  11636. else
  11637. {
  11638. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11639. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11640. }
  11641. }
  11642. 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'))
  11643. {
  11644. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11645. }
  11646. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11647. {
  11648. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11649. }
  11650. else
  11651. {
  11652. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11653. }
  11654. }
  11655. 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
  11656. {
  11657. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11658. }
  11659. }
  11660. else
  11661. {
  11662. //replace reservation
  11663. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11664. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11665. }
  11666. }
  11667. }// END FOR GB_QUANTITY
  11668. }
  11669. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11670. {
  11671. tempIndex = connectorIdInt -1;
  11672. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11673. {
  11674. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11675. {
  11676. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11677. {
  11678. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11679. 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
  11680. {
  11681. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11682. {
  11683. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  11684. {
  11685. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11686. }
  11687. else
  11688. {
  11689. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11690. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11691. }
  11692. }
  11693. 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'))
  11694. {
  11695. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11696. }
  11697. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11698. {
  11699. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11700. }
  11701. else
  11702. {
  11703. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11704. }
  11705. }
  11706. 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
  11707. {
  11708. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11709. }
  11710. }
  11711. else
  11712. {
  11713. //replace reservation
  11714. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11715. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11716. }
  11717. }
  11718. }// END FOR GB_QUANTITY
  11719. }
  11720. else
  11721. {
  11722. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11723. {
  11724. tempIndex = 2;
  11725. }
  11726. else
  11727. {
  11728. tempIndex = (connectorIdInt -1);
  11729. }
  11730. for (int index = 0; index < AC_QUANTITY; index++)
  11731. {
  11732. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11733. {
  11734. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11735. {
  11736. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11737. {
  11738. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11739. {
  11740. 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))
  11741. {
  11742. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11743. }
  11744. else
  11745. {
  11746. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11747. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11748. }
  11749. }
  11750. 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'))
  11751. {
  11752. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11753. }
  11754. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11755. {
  11756. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11757. }
  11758. else
  11759. {
  11760. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11761. }
  11762. }
  11763. 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
  11764. {
  11765. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11766. }
  11767. }
  11768. else
  11769. {
  11770. //replace reservation
  11771. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11772. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11773. }
  11774. }
  11775. } // END FOR AC_QUANTITY
  11776. }
  11777. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11778. }
  11779. else if(connectorIdInt == 0)
  11780. {
  11781. //check Transaction active
  11782. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11783. {
  11784. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11785. {
  11786. 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'))
  11787. {
  11788. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11789. goto end;
  11790. }
  11791. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11792. {
  11793. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11794. goto end;
  11795. }
  11796. 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
  11797. {
  11798. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11799. goto end;
  11800. }
  11801. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11802. {
  11803. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11804. goto end;
  11805. }
  11806. }
  11807. }// END FOR CHAdeMO_QUANTITY
  11808. for (int index = 0; index < CCS_QUANTITY; index++)
  11809. {
  11810. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11811. {
  11812. 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'))
  11813. {
  11814. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11815. goto end;
  11816. }
  11817. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11818. {
  11819. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11820. goto end;
  11821. }
  11822. 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
  11823. {
  11824. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11825. goto end;
  11826. }
  11827. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11828. {
  11829. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11830. goto end;
  11831. }
  11832. }
  11833. } // END FOR CCS_QUANTITY
  11834. for (int index = 0; index < GB_QUANTITY; index++)
  11835. {
  11836. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11837. {
  11838. 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'))
  11839. {
  11840. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11841. goto end;
  11842. }
  11843. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11844. {
  11845. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11846. goto end;
  11847. }
  11848. 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
  11849. {
  11850. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11851. goto end;
  11852. }
  11853. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11854. {
  11855. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11856. goto end;
  11857. }
  11858. }
  11859. } // END FOR GB_QUANTITY
  11860. for (int index = 0; index < AC_QUANTITY; index++)
  11861. {
  11862. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11863. {
  11864. 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'))
  11865. {
  11866. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11867. goto end;
  11868. }
  11869. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11870. {
  11871. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11872. goto end;
  11873. }
  11874. 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
  11875. {
  11876. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11877. goto end;
  11878. }
  11879. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11880. {
  11881. 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))
  11882. {
  11883. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11884. goto end;
  11885. }
  11886. }
  11887. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11888. {
  11889. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11890. goto end;
  11891. }
  11892. }
  11893. }// END FOR AC_QUANTITY
  11894. //The connectorId is 0
  11895. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  11896. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11897. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11898. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  11899. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11900. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  11901. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11902. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  11903. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  11904. result = TRUE;
  11905. return result;
  11906. }
  11907. else
  11908. {
  11909. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11910. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11911. }
  11912. if(strcmp(comfirmstr,"Accepted") == 0)
  11913. {
  11914. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11915. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11916. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11917. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11918. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11919. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11920. result = TRUE;
  11921. return result;
  11922. }
  11923. end:
  11924. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11925. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11926. return result;
  11927. }
  11928. int handleResetRequest(char *uuid, char *payload)
  11929. {
  11930. mtrace();
  11931. int result = FAIL;
  11932. char sstr[10]={0},sstrtemp[30]={ 0 };
  11933. char typestr[10]={0};
  11934. char comfirmstr[20]={0};
  11935. int c = 0;
  11936. char *loc;
  11937. DEBUG_INFO("handleResetRequest...\n");
  11938. strcpy(sstrtemp, stringtrimspace(payload));
  11939. loc = strstr(sstrtemp, "type");
  11940. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11941. c = 0;
  11942. while (loc[3+strlen("type")+c] != '\"')
  11943. {
  11944. sstr[c] = loc[3+strlen("type")+c];
  11945. c++;
  11946. }
  11947. sstr[c] = '\0';
  11948. strcpy(typestr,sstr);
  11949. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11950. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11951. {
  11952. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11953. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11954. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11955. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11956. }
  11957. else
  11958. {
  11959. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11960. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11961. result = PASS;
  11962. }
  11963. sendResetConfirmation(uuid, comfirmstr);
  11964. return result;
  11965. }
  11966. int handleSendLocalListRequest(char *uuid, char *payload)
  11967. {
  11968. mtrace();
  11969. int result = FAIL;
  11970. char comfirmstr[20];
  11971. int checkState_Faulted = FALSE;
  11972. json_object *SendLocalList;
  11973. DEBUG_INFO("handleSendLocalListRequest...\n");
  11974. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11975. {
  11976. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11977. goto end;
  11978. }
  11979. //check Charge Point state
  11980. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11981. {
  11982. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11983. {
  11984. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11985. }
  11986. }
  11987. for (int index = 0; index < CCS_QUANTITY; index++)
  11988. {
  11989. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11990. {
  11991. checkState_Faulted = TRUE; //OCPP Status
  11992. }
  11993. }
  11994. for (int index = 0; index < GB_QUANTITY; index++)
  11995. {
  11996. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11997. {
  11998. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11999. }
  12000. }
  12001. //check Charge Point state
  12002. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12003. {
  12004. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12005. {
  12006. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12007. }
  12008. }
  12009. //check Charge Point state
  12010. for (int index = 0; index < AC_QUANTITY; index++)
  12011. {
  12012. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12013. {
  12014. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12015. }
  12016. }
  12017. if(checkState_Faulted == TRUE)
  12018. {
  12019. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12020. goto end;
  12021. }
  12022. // Parsing payload
  12023. SendLocalList = json_tokener_parse(payload);
  12024. if(!is_error(SendLocalList))
  12025. {
  12026. // Required data
  12027. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12028. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12029. // Optional data
  12030. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12031. {
  12032. //Check UpdateType
  12033. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12034. {
  12035. //Local list full update
  12036. DEBUG_INFO("Local list full update.\n");
  12037. locallistVersion = 0;
  12038. OCPP_getListVerion();
  12039. /*if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  12040. {
  12041. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12042. goto end;
  12043. }*/
  12044. OCPP_cleanLocalList();
  12045. }
  12046. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12047. {
  12048. //Local list different update
  12049. DEBUG_INFO("Local list different update.\n");
  12050. locallistVersion = 0;
  12051. OCPP_getListVerion();
  12052. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  12053. {
  12054. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12055. goto end;
  12056. }
  12057. }
  12058. else
  12059. {
  12060. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12061. goto end;
  12062. }
  12063. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12064. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12065. {
  12066. 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")));
  12067. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12068. {
  12069. 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")));
  12070. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12071. 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")));
  12072. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12073. 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")));
  12074. }
  12075. // Add to db
  12076. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12077. {
  12078. //Local list full update
  12079. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12080. idx,
  12081. ShmOCPP16DataPH->SendLocalList.ListVersion,
  12082. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  12083. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12084. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12085. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12086. // update list
  12087. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  12088. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  12089. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12090. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12091. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12092. }
  12093. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12094. {
  12095. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12096. idx,
  12097. ShmOCPP16DataPH->SendLocalList.ListVersion,
  12098. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  12099. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12100. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12101. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12102. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  12103. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  12104. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12105. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12106. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12107. }
  12108. }
  12109. }
  12110. else
  12111. {
  12112. //Check UpdateType
  12113. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12114. {
  12115. //Local list full update
  12116. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12117. OCPP_cleanLocalList();
  12118. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12119. goto end;
  12120. }
  12121. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12122. {
  12123. //Local list different update
  12124. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12125. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12126. goto end;
  12127. }
  12128. }
  12129. result = PASS;
  12130. }
  12131. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12132. end:
  12133. json_object_put(SendLocalList);
  12134. sendSendLocalListConfirmation(uuid, comfirmstr);
  12135. return result;
  12136. }
  12137. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12138. {
  12139. mtrace();
  12140. int result = FAIL;
  12141. struct StructSetChargingProfile SetProfileReq = {0};
  12142. int tempchargingProfileIdInt;
  12143. int tempstackLevelInt;
  12144. int chargingSchedulePeriodCount = 0;
  12145. char comfirmstr[20]={0};
  12146. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  12147. char rmFileCmd[128]={0};
  12148. int profileQuantity = 0;
  12149. int replaceableProfileCnt = 0;
  12150. json_object *SetChargingProfile;
  12151. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12152. SetChargingProfile = json_tokener_parse(payload);
  12153. if(!is_error(SetChargingProfile))
  12154. {
  12155. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12156. {
  12157. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12158. }
  12159. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12160. {
  12161. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12162. {
  12163. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12164. }
  12165. else
  12166. {
  12167. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12168. DEBUG_WARN("Cannot find chargingProfileId field.");
  12169. goto end;
  12170. }
  12171. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12172. {
  12173. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12174. }
  12175. else
  12176. {
  12177. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12178. DEBUG_WARN("Cannot find stackLevel field.");
  12179. goto end;
  12180. }
  12181. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12182. {
  12183. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12184. }
  12185. else
  12186. {
  12187. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12188. DEBUG_WARN("Cannot find chargingProfilePurpose field.");
  12189. goto end;
  12190. }
  12191. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12192. {
  12193. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12194. }
  12195. else
  12196. {
  12197. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12198. DEBUG_WARN("Cannot find chargingProfileKind field.");
  12199. goto end;
  12200. }
  12201. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12202. {
  12203. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12204. }
  12205. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12206. {
  12207. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12208. }
  12209. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12210. {
  12211. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12212. }
  12213. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12214. {
  12215. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12216. }
  12217. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12218. {
  12219. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12220. {
  12221. 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")));
  12222. }
  12223. else
  12224. {
  12225. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12226. DEBUG_WARN("Cannot find chargingRateUnit field.");
  12227. goto end;
  12228. }
  12229. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12230. {
  12231. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12232. }
  12233. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12234. {
  12235. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12236. }
  12237. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12238. {
  12239. 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")));
  12240. }
  12241. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12242. {
  12243. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12244. if(chargingSchedulePeriodCount <= 10)
  12245. {
  12246. 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++)
  12247. {
  12248. 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)
  12249. {
  12250. 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"));
  12251. }
  12252. else
  12253. {
  12254. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12255. DEBUG_WARN("Cannot find startPeriod field.");
  12256. goto end;
  12257. }
  12258. 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)
  12259. {
  12260. 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"));
  12261. }
  12262. else
  12263. {
  12264. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12265. DEBUG_WARN("Cannot find limit field.");
  12266. goto end;
  12267. }
  12268. 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)
  12269. {
  12270. 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"));
  12271. }
  12272. }
  12273. }
  12274. }
  12275. else
  12276. {
  12277. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12278. DEBUG_WARN("Cannot find chargingSchedulePeriod field.");
  12279. goto end;
  12280. }
  12281. }
  12282. else
  12283. {
  12284. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12285. DEBUG_WARN("Cannot find chargingSchedule field.");
  12286. goto end;
  12287. }
  12288. }
  12289. }
  12290. // Profile periods quantity check
  12291. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12292. {
  12293. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12294. goto end;
  12295. }
  12296. // Check invalid limit
  12297. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  12298. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  12299. {
  12300. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12301. {
  12302. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12303. {
  12304. 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)))) ||
  12305. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12306. {
  12307. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12308. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12309. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12310. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12311. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12312. goto end;
  12313. }
  12314. }
  12315. }
  12316. else
  12317. {
  12318. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12319. {
  12320. 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) ||
  12321. (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)))
  12322. {
  12323. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12324. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12325. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12326. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12327. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12328. goto end;
  12329. }
  12330. }
  12331. }
  12332. }
  12333. // Profile purpose info check
  12334. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12335. {
  12336. FILE *fp;
  12337. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12338. if(SetProfileReq.ConnectorId != 0)
  12339. {
  12340. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12341. goto end;
  12342. }
  12343. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12344. if (!fp)
  12345. {
  12346. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12347. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12348. }
  12349. else
  12350. {
  12351. char *line = NULL;
  12352. size_t len = 0;
  12353. while(getline(&line, &len, fp) != -1)
  12354. {
  12355. json_object *obj = NULL;
  12356. obj = json_tokener_parse(line);
  12357. if(is_error(obj))
  12358. {
  12359. DEBUG_ERROR("Parse txProfile from file error.\n");
  12360. }
  12361. else
  12362. {
  12363. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12364. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12365. {
  12366. profileQuantity += 1;
  12367. }
  12368. else
  12369. replaceableProfileCnt += 1;
  12370. }
  12371. }
  12372. }
  12373. fclose(fp);
  12374. }
  12375. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12376. {
  12377. FILE *fp;
  12378. char filename[128]={0};
  12379. int tmpProfileQuantity;
  12380. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12381. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12382. {
  12383. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12384. goto end;
  12385. }
  12386. if(SetProfileReq.ConnectorId == 0)
  12387. {
  12388. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12389. {
  12390. tmpProfileQuantity = 0;
  12391. memset(filename, 0, ARRAY_SIZE(filename));
  12392. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12393. fp = fopen(filename, "r");
  12394. if (!fp)
  12395. {
  12396. DEBUG_INFO("%s does not create.\n", filename);
  12397. fp = fopen(filename, "w+");
  12398. }
  12399. else
  12400. {
  12401. char *line = NULL;
  12402. size_t len = 0;
  12403. while(getline(&line, &len, fp) != -1)
  12404. {
  12405. json_object *obj = NULL;
  12406. obj = json_tokener_parse(line);
  12407. if(is_error(obj))
  12408. {
  12409. DEBUG_ERROR("Parse txProfile from file error.\n");
  12410. }
  12411. else
  12412. {
  12413. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12414. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12415. {
  12416. tmpProfileQuantity += 1;
  12417. }
  12418. else
  12419. replaceableProfileCnt += 1;
  12420. }
  12421. }
  12422. }
  12423. fclose(fp);
  12424. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12425. }
  12426. }
  12427. else
  12428. {
  12429. memset(filename, 0, ARRAY_SIZE(filename));
  12430. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12431. fp = fopen(filename, "r");
  12432. if (!fp)
  12433. {
  12434. DEBUG_INFO("%s does not create.\n", filename);
  12435. fp = fopen(filename, "w+");
  12436. }
  12437. else
  12438. {
  12439. char *line = NULL;
  12440. size_t len = 0;
  12441. while(getline(&line, &len, fp) != -1)
  12442. {
  12443. json_object *obj = NULL;
  12444. obj = json_tokener_parse(line);
  12445. if(is_error(obj))
  12446. {
  12447. DEBUG_ERROR("Parse txProfile from file error.\n");
  12448. }
  12449. else
  12450. {
  12451. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12452. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12453. {
  12454. profileQuantity += 1;
  12455. }
  12456. else
  12457. replaceableProfileCnt += 1;
  12458. }
  12459. }
  12460. }
  12461. fclose(fp);
  12462. }
  12463. }
  12464. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12465. {
  12466. int isMatchTransactiodId= FALSE;
  12467. FILE *fp;
  12468. char filename[128]={0};
  12469. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12470. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12471. if(SetProfileReq.ConnectorId == 0)
  12472. {
  12473. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12474. goto end;
  12475. }
  12476. int tempIndex = 0;
  12477. //check Transaction active
  12478. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12479. {
  12480. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12481. {
  12482. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12483. }
  12484. else
  12485. {
  12486. tempIndex = SetProfileReq.ConnectorId -1;
  12487. }
  12488. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12489. {
  12490. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12491. {
  12492. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12493. {
  12494. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12495. {
  12496. isMatchTransactiodId = TRUE;
  12497. break;
  12498. }
  12499. }
  12500. }
  12501. }
  12502. }
  12503. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12504. {
  12505. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12506. {
  12507. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12508. }
  12509. else
  12510. {
  12511. tempIndex = SetProfileReq.ConnectorId -1;
  12512. }
  12513. for (int index = 0; index < CCS_QUANTITY; index++)
  12514. {
  12515. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12516. {
  12517. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12518. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12519. {
  12520. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12521. {
  12522. isMatchTransactiodId = TRUE;
  12523. break;
  12524. }
  12525. }
  12526. }
  12527. }
  12528. }
  12529. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12530. {
  12531. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12532. {
  12533. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12534. }
  12535. else
  12536. {
  12537. tempIndex = SetProfileReq.ConnectorId -1;
  12538. }
  12539. for (int index = 0; index < GB_QUANTITY; index++)
  12540. {
  12541. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12542. {
  12543. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12544. {
  12545. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12546. {
  12547. isMatchTransactiodId = TRUE;
  12548. break;
  12549. }
  12550. }
  12551. }
  12552. }
  12553. }
  12554. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12555. {
  12556. tempIndex = SetProfileReq.ConnectorId -1;
  12557. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12558. {
  12559. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12560. {
  12561. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12562. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12563. {
  12564. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12565. {
  12566. isMatchTransactiodId = TRUE;
  12567. break;
  12568. }
  12569. }
  12570. }
  12571. }
  12572. }
  12573. else
  12574. {
  12575. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12576. {
  12577. tempIndex = 2;
  12578. }
  12579. else
  12580. {
  12581. tempIndex = (SetProfileReq.ConnectorId -1);
  12582. }
  12583. for (int index = 0; index < AC_QUANTITY; index++)
  12584. {
  12585. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12586. {
  12587. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12588. {
  12589. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12590. {
  12591. isMatchTransactiodId = TRUE;
  12592. break;
  12593. }
  12594. }
  12595. }
  12596. }
  12597. }
  12598. //check Transaction active
  12599. if(isMatchTransactiodId == FALSE)
  12600. {
  12601. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12602. goto end;
  12603. }
  12604. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12605. {
  12606. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12607. goto end;
  12608. }
  12609. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12610. fp = fopen(filename, "r");
  12611. if (!fp)
  12612. {
  12613. DEBUG_INFO("%s does not create.\n", filename);
  12614. fp = fopen(filename, "w+");
  12615. }
  12616. else
  12617. {
  12618. char *line = NULL;
  12619. size_t len = 0;
  12620. while(getline(&line, &len, fp) != -1)
  12621. {
  12622. json_object *obj = NULL;
  12623. obj = json_tokener_parse(line);
  12624. if(is_error(obj))
  12625. {
  12626. DEBUG_ERROR("Parse txProfile from file error.\n");
  12627. }
  12628. else
  12629. {
  12630. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12631. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12632. {
  12633. profileQuantity += 1;
  12634. }
  12635. else
  12636. replaceableProfileCnt += 1;
  12637. }
  12638. }
  12639. }
  12640. fclose(fp);
  12641. }
  12642. // Check ChargeProfileMaxStackLevel
  12643. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12644. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12645. {
  12646. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12647. goto end;
  12648. }
  12649. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12650. {
  12651. FILE *fp;
  12652. char dataLine[4096]={0};
  12653. char fnametemp[128]={0};
  12654. int tmpProfileQuantity;
  12655. //Check ChargePointMaxProfile.json exit
  12656. profileQuantity = 0;
  12657. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  12658. {
  12659. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  12660. //Check Charging Profile Count
  12661. tmpProfileQuantity = 0;
  12662. while(fscanf(fp, "%s", dataLine) != EOF)
  12663. {
  12664. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12665. {
  12666. profileQuantity += 1;
  12667. tmpProfileQuantity += 1;
  12668. }
  12669. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12670. }
  12671. fclose(fp);
  12672. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12673. }
  12674. //Check TxDefaultProfile_%d.json
  12675. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12676. {
  12677. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12678. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12679. if((access(fnametemp,F_OK))!=-1)
  12680. {
  12681. fp = fopen(fnametemp, "r");
  12682. //Check Charging Profile Count
  12683. tmpProfileQuantity = 0;
  12684. while(fscanf(fp, "%s", dataLine) != EOF)
  12685. {
  12686. //DEBUG_INFO("word=%s\n",word);
  12687. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12688. {
  12689. profileQuantity += 1;
  12690. tmpProfileQuantity += 1;
  12691. }
  12692. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12693. }
  12694. fclose(fp);
  12695. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12696. }
  12697. }
  12698. //Check TxProfile_%d.json
  12699. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12700. {
  12701. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12702. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  12703. if((access(fnametemp,F_OK))!=-1)
  12704. {
  12705. fp = fopen(fnametemp, "r");
  12706. //Check Charging Profile Count
  12707. tmpProfileQuantity = 0;
  12708. while(fscanf(fp, "%s", dataLine) != EOF)
  12709. {
  12710. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12711. {
  12712. profileQuantity += 1;
  12713. tmpProfileQuantity += 1;
  12714. }
  12715. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12716. }
  12717. fclose(fp);
  12718. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12719. }
  12720. }
  12721. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12722. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  12723. // To check total Profile quantity
  12724. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  12725. {
  12726. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12727. {
  12728. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12729. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12730. goto end;
  12731. }
  12732. }
  12733. else
  12734. {
  12735. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12736. {
  12737. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12738. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12739. goto end;
  12740. }
  12741. }
  12742. }
  12743. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12744. //**********************************Write to File********************************************************/
  12745. {
  12746. FILE *infile;
  12747. FILE *outfile;
  12748. char dataLine[4096]={0};
  12749. char filename[128]={0};
  12750. int chkChar=0;
  12751. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12752. {
  12753. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12754. {
  12755. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12756. }
  12757. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12758. {
  12759. if(SetProfileReq.ConnectorId==0)
  12760. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12761. else
  12762. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12763. }
  12764. else
  12765. {
  12766. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12767. }
  12768. infile = fopen (filename, "r");
  12769. outfile = fopen (tempfile, "w");
  12770. chkChar = fgetc(infile);
  12771. rewind(infile);
  12772. if(chkChar == EOF)
  12773. {
  12774. // Profile is empty
  12775. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12776. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12777. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12778. fclose(infile);
  12779. fclose(outfile);
  12780. sprintf(rmFileCmd,"rm -f %s",filename);
  12781. system(rmFileCmd);
  12782. rename(tempfile, filename);
  12783. }
  12784. else
  12785. {
  12786. // Profile is not empty
  12787. int ChargingProfileAdded = FALSE;
  12788. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12789. {
  12790. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12791. json_object *tmpChargingProfile;
  12792. tmpChargingProfile = json_tokener_parse(dataLine);
  12793. if(!is_error(SetChargingProfile))
  12794. {
  12795. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12796. {
  12797. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12798. {
  12799. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12800. }
  12801. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12802. {
  12803. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  12804. }
  12805. }
  12806. }
  12807. json_object_put(tmpChargingProfile);
  12808. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12809. {
  12810. if(ChargingProfileAdded == FALSE)
  12811. {
  12812. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12813. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12814. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12815. ChargingProfileAdded = TRUE;
  12816. }
  12817. }
  12818. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  12819. {
  12820. if(ChargingProfileAdded == FALSE)
  12821. {
  12822. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12823. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12824. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12825. ChargingProfileAdded = TRUE;
  12826. }
  12827. }
  12828. else
  12829. {
  12830. fprintf(outfile,"%s\n",dataLine);
  12831. if(ChargingProfileAdded == FALSE)
  12832. {
  12833. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12834. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12835. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12836. ChargingProfileAdded = TRUE;
  12837. }
  12838. }
  12839. } // end of while loop
  12840. fclose(infile);
  12841. fclose(outfile);
  12842. sprintf(rmFileCmd,"rm -f %s",filename);
  12843. system(rmFileCmd);
  12844. rename(tempfile, filename);
  12845. }
  12846. }
  12847. sleep(1);
  12848. result = TRUE;
  12849. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12850. }
  12851. end:
  12852. json_object_put(SetChargingProfile);
  12853. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12854. {
  12855. if(SetProfileReq.ConnectorId == 0)
  12856. {
  12857. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12858. {
  12859. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  12860. }
  12861. }
  12862. else
  12863. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12864. }
  12865. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12866. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12867. return result;
  12868. }
  12869. int handleTriggerMessageRequest(char *uuid, char *payload)
  12870. {
  12871. mtrace();
  12872. int result = FAIL;
  12873. int connectorIdIsNULL = FALSE;
  12874. int connectorIdInt =0;
  12875. char sstr[40]={0},sstrtemp[100]={ 0 };
  12876. char requestedMessagestr[40]={0};
  12877. char comfirmstr[20]={0};
  12878. int c = 0;
  12879. char *loc;
  12880. DEBUG_INFO("handleTriggerMessageRequest\n");
  12881. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12882. strcpy(sstrtemp, stringtrimspace(payload));
  12883. c = 0;
  12884. loc = strstr(sstrtemp, "requestedMessage");
  12885. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12886. {
  12887. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12888. c++;
  12889. }
  12890. sstr[c] = '\0';
  12891. strcpy(requestedMessagestr, sstr);
  12892. c = 0;
  12893. loc = strstr(sstrtemp, "connectorId");
  12894. if(loc == NULL)
  12895. {
  12896. connectorIdIsNULL = TRUE;
  12897. }
  12898. else
  12899. {
  12900. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12901. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12902. {
  12903. sstr[c] = loc[strlen("connectorId")+2+c];
  12904. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12905. c++;
  12906. }
  12907. sstr[c] = '\0';
  12908. connectorIdInt = atoi(sstr);
  12909. }
  12910. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12911. {
  12912. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12913. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12914. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12915. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12916. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12917. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12918. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12919. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12920. {
  12921. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12922. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12923. return TRUE;
  12924. }
  12925. else
  12926. {
  12927. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12928. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12929. }
  12930. }
  12931. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12932. {
  12933. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12934. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12935. return TRUE;
  12936. }
  12937. //==========================
  12938. // Trigger message
  12939. //==========================
  12940. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12941. {
  12942. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12943. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12944. {
  12945. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12946. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12947. }
  12948. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12949. }
  12950. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12951. {
  12952. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  12953. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12954. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12955. }
  12956. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12957. {
  12958. //sendBootNotificationRequest();
  12959. server_sign = FALSE;
  12960. }
  12961. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12962. {
  12963. refreshStartTimer(&clientTime.Heartbeat);
  12964. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12965. }
  12966. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12967. {
  12968. if(connectorIdIsNULL == FALSE)
  12969. {
  12970. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12971. {
  12972. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12973. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12974. }
  12975. }
  12976. else
  12977. {
  12978. for(int idx=0;idx< gunTotalNumber;idx++)
  12979. {
  12980. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12981. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12982. }
  12983. }
  12984. }
  12985. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12986. {
  12987. if(connectorIdIsNULL == FALSE)
  12988. {
  12989. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12990. {
  12991. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12992. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  12993. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12994. }
  12995. }
  12996. else
  12997. {
  12998. for(int idx=0;idx< gunTotalNumber;idx++)
  12999. {
  13000. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  13001. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13002. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13003. }
  13004. }
  13005. }
  13006. return result;
  13007. }
  13008. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13009. {
  13010. mtrace();
  13011. int result = FAIL;
  13012. int connectorIdInt =0;
  13013. char comfirmstr[20]={0};
  13014. int tempIndex = 0;
  13015. json_object *UnlockConnector;
  13016. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13017. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13018. UnlockConnector = json_tokener_parse(payload);
  13019. if(!is_error(UnlockConnector))
  13020. {
  13021. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13022. {
  13023. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13024. }
  13025. }
  13026. json_object_put(UnlockConnector);
  13027. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13028. if(gunTotalNumber == 0)
  13029. {
  13030. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13031. goto end;
  13032. }
  13033. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13034. {
  13035. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13036. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13037. goto end;
  13038. }
  13039. else
  13040. {
  13041. //check Transaction active
  13042. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13043. {
  13044. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13045. {
  13046. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13047. }
  13048. else
  13049. {
  13050. tempIndex = connectorIdInt -1;
  13051. }
  13052. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13053. {
  13054. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13055. {
  13056. //stop Transaction
  13057. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13058. }
  13059. }
  13060. }
  13061. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13062. {
  13063. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13064. {
  13065. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13066. }
  13067. else
  13068. {
  13069. tempIndex = connectorIdInt -1;
  13070. }
  13071. for (int index = 0; index < CCS_QUANTITY; index++)
  13072. {
  13073. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13074. {
  13075. //stop Transaction
  13076. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13077. }
  13078. }
  13079. }
  13080. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13081. {
  13082. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13083. {
  13084. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13085. }
  13086. else
  13087. {
  13088. tempIndex = connectorIdInt -1;
  13089. }
  13090. for (int index = 0; index < GB_QUANTITY; index++)
  13091. {
  13092. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13093. {
  13094. //stop Transaction
  13095. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13096. }
  13097. }
  13098. }
  13099. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13100. {
  13101. tempIndex = connectorIdInt -1;
  13102. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13103. {
  13104. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13105. {
  13106. //stop Transaction
  13107. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13108. }
  13109. }
  13110. }
  13111. else
  13112. {
  13113. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13114. {
  13115. tempIndex = 2;
  13116. }
  13117. else
  13118. {
  13119. tempIndex = connectorIdInt-1;
  13120. }
  13121. for (int index = 0; index < AC_QUANTITY; index++)
  13122. {
  13123. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  13124. {
  13125. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13126. }
  13127. }
  13128. }
  13129. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  13130. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  13131. result = TRUE;
  13132. return result;
  13133. }
  13134. end:
  13135. //json_object_put(obj); --- remove temporally
  13136. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  13137. return result;
  13138. }
  13139. static char UpdateFirmwarepayloadData[300]={0};
  13140. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13141. {
  13142. mtrace();
  13143. int result = FAIL;
  13144. pthread_t t;
  13145. sendUpdateFirmwareConfirmation(uuid);
  13146. memset(UpdateFirmwarepayloadData, 0, 300);
  13147. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  13148. if(!interLock.isUpdateFirmwareGoing)
  13149. {
  13150. interLock.isUpdateFirmwareGoing = 1;
  13151. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  13152. sleep(1);
  13153. }
  13154. else
  13155. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13156. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  13157. return result;
  13158. }
  13159. void *UpdateFirmwareProcess(void *data)
  13160. {
  13161. pthread_detach(pthread_self());
  13162. mtrace();
  13163. int retriesInt =0, retryIntervalInt=0;
  13164. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  13165. int port=0;
  13166. char locationstr[512]={0}, retrieveDatestr[36]={0};
  13167. int isSuccess = 0;
  13168. char ftpbuf[512];
  13169. char temp[100];
  13170. char * pch;
  13171. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13172. json_object *UpdateFirmware;
  13173. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  13174. if(!is_error(UpdateFirmware))
  13175. {
  13176. // Required data
  13177. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13178. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13179. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13180. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13181. // Optional data
  13182. if(json_object_object_get(UpdateFirmware, "retries"))
  13183. {
  13184. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13185. }
  13186. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13187. {
  13188. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13189. }
  13190. }
  13191. json_object_put(UpdateFirmware);
  13192. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13193. memset(path, 0, ARRAY_SIZE(path));
  13194. // Wait retrieveData
  13195. if(strlen(retrieveDatestr) > 10)
  13196. {
  13197. do
  13198. {
  13199. sleep(1);
  13200. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13201. }
  13202. // Ready to download
  13203. system("rm -f /mnt/*");
  13204. if(strncmp(locationstr,"http", 4) == 0)
  13205. {
  13206. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13207. sprintf(ftppath,"/%s", path);
  13208. DEBUG_INFO("locationstr: %s\n", locationstr);
  13209. DEBUG_INFO("protocol: %s\n",protocol);
  13210. DEBUG_INFO("host: %s\n",host);
  13211. DEBUG_INFO("path: %s\n",path);
  13212. DEBUG_INFO("ftppath: %s\n",ftppath);
  13213. int ftppathlen=strlen(ftppath);
  13214. int i=1;
  13215. char filenametemp[50];
  13216. while(i < ftppathlen)
  13217. {
  13218. int len=ftppathlen-i;
  13219. if(ftppath[len]== 47) // '/' ascll code: 47
  13220. {
  13221. DEBUG_INFO("compare '/' all right\n");
  13222. break;
  13223. }
  13224. i=i+1;
  13225. }
  13226. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13227. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13228. filenametemp[i+1] = 0;
  13229. do
  13230. {
  13231. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13232. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13233. sleep(1);
  13234. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13235. if(!isSuccess)
  13236. {
  13237. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13238. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13239. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13240. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13241. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13242. }
  13243. else
  13244. {
  13245. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13246. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13247. }
  13248. retriesInt--;
  13249. }while((isSuccess == 0)&&(retriesInt >= 0));
  13250. }
  13251. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  13252. {
  13253. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13254. memset(temp, 0, ARRAY_SIZE(temp));
  13255. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13256. strcpy(ftpbuf, locationstr);
  13257. int ftppathlen=strlen(ftpbuf);
  13258. int i=1;
  13259. char filenametemp[50];
  13260. while(i < ftppathlen)
  13261. {
  13262. int len=ftppathlen-i;
  13263. if(ftpbuf[len]== 47) // '/' ascii code: 47
  13264. {
  13265. DEBUG_INFO(" compare '/' all right\n");
  13266. break;
  13267. }
  13268. i=i+1;
  13269. }
  13270. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13271. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13272. filenametemp[i+1] = 0;
  13273. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13274. pch=strchr(temp,'@');
  13275. if(pch==NULL)
  13276. {
  13277. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13278. protocol, host, &port, path);
  13279. strcpy(user,"anonymous");
  13280. strcpy(password,"");
  13281. }
  13282. else
  13283. {
  13284. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  13285. protocol, user, host, &port, path);
  13286. }
  13287. sscanf(host,"%[^/]%s",host1, path1);
  13288. sprintf(ftppath,"%s:/%s", host,path);
  13289. if(port == 0)
  13290. {
  13291. port = 21;
  13292. }
  13293. do
  13294. {
  13295. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13296. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13297. sleep(1);
  13298. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, filenametemp, locationstr);
  13299. if(!isSuccess)
  13300. {
  13301. //BulldogUtil.sleepMs(interval*1000);
  13302. DEBUG_INFO("Update firmware request and download file fail.\n");
  13303. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13304. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13305. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13306. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13307. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13308. }
  13309. else
  13310. {
  13311. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13312. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13313. }
  13314. retriesInt--;
  13315. }while((!isSuccess)&&(retriesInt >= 0));
  13316. }
  13317. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13318. {
  13319. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13320. memset(temp, 0, ARRAY_SIZE(temp));
  13321. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13322. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13323. int ftppathlen=strlen(ftpbuf);
  13324. int i=1;
  13325. char filenametemp[50];
  13326. while(i < ftppathlen)
  13327. {
  13328. int len=ftppathlen-i;
  13329. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13330. {
  13331. DEBUG_INFO(" compare '/' all right\n");
  13332. break;
  13333. }
  13334. i=i+1;
  13335. }
  13336. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13337. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13338. filenametemp[i+1] = 0;
  13339. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13340. pch=strchr(temp,'@');
  13341. if(pch==NULL)
  13342. {
  13343. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13344. protocol, host, &port, path);
  13345. strcpy(user,"anonymous");
  13346. strcpy(password,"");
  13347. }
  13348. else
  13349. {
  13350. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13351. protocol, user, password, host, &port, path);
  13352. }
  13353. sscanf(host,"%[^/]%s",host1, path1);
  13354. sprintf(ftppath,"%s", path1);
  13355. //DEBUG_INFO("protocol =%s\n",protocol);
  13356. //DEBUG_INFO("user =%s\n",user);
  13357. //DEBUG_INFO("password =%s\n",password);
  13358. //DEBUG_INFO("host1 =%s\n",host1);
  13359. //DEBUG_INFO("port =%d\n",port);
  13360. //DEBUG_INFO("path1 =%s\n",path1);
  13361. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13362. //ftpFile(host, user, password, port, ftppath, fname);
  13363. //download firmware pthred
  13364. if(port == 0)
  13365. {
  13366. port = 21;
  13367. }
  13368. do
  13369. {
  13370. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13371. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13372. sleep(1);
  13373. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13374. if(!isSuccess)
  13375. {
  13376. //BulldogUtil.sleepMs(interval*1000);
  13377. DEBUG_INFO("Update firmware request and download file fail.\n");
  13378. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13379. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13380. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13381. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13382. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13383. }
  13384. else
  13385. {
  13386. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13387. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13388. }
  13389. retriesInt--;
  13390. }while((!isSuccess)&&(retriesInt >= 0));
  13391. }
  13392. else
  13393. {
  13394. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13395. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13396. sleep(1);
  13397. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13398. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13399. }
  13400. // OCPPPH only, must announce CSU upgrade firmware
  13401. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13402. interLock.isUpdateFirmwareGoing = 0;
  13403. pthread_exit(NULL);
  13404. }
  13405. int handleCertificateSignedRequest(char *uuid, char *payload)
  13406. {
  13407. mtrace();
  13408. int result = PASS;
  13409. json_object *CertificateSigned;
  13410. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13411. CertificateSigned = json_tokener_parse(payload);
  13412. if(!is_error(CertificateSigned))
  13413. {
  13414. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13415. }
  13416. json_object_put(CertificateSigned);
  13417. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  13418. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  13419. fclose(fp);
  13420. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13421. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  13422. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  13423. sendCertificateSignedConfirmation(uuid);
  13424. return result;
  13425. }
  13426. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13427. {
  13428. mtrace();
  13429. int result = PASS;
  13430. json_object *DeleteCertificate;
  13431. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13432. DeleteCertificate = json_tokener_parse(payload);
  13433. if(!is_error(DeleteCertificate))
  13434. {
  13435. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13436. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13437. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13438. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13439. }
  13440. json_object_put(DeleteCertificate);
  13441. /*
  13442. * TODO: Delete certificateSigned process
  13443. */
  13444. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  13445. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  13446. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  13447. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  13448. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  13449. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  13450. sendDeleteCertificateConfirmation(uuid);
  13451. return result;
  13452. }
  13453. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13454. {
  13455. mtrace();
  13456. int result = PASS;
  13457. json_object *ExtendedTriggerMessage;
  13458. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13459. ExtendedTriggerMessage = json_tokener_parse(payload);
  13460. if(!is_error(ExtendedTriggerMessage))
  13461. {
  13462. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13463. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13464. {
  13465. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13466. }
  13467. else
  13468. {
  13469. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  13470. }
  13471. }
  13472. json_object_put(ExtendedTriggerMessage);
  13473. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  13474. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  13475. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13476. {
  13477. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13478. }
  13479. else
  13480. {
  13481. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13482. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13483. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13484. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13485. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13486. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13487. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13488. {
  13489. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13490. }
  13491. else
  13492. {
  13493. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13494. }
  13495. }
  13496. sendExtendedTriggerMessageConfirmation(uuid);
  13497. //==========================
  13498. // Trigger message
  13499. //==========================
  13500. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13501. {
  13502. //sendBootNotificationRequest();
  13503. server_sign = FALSE;
  13504. }
  13505. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13506. {
  13507. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  13508. }
  13509. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13510. {
  13511. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  13512. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13513. {
  13514. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13515. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13516. }
  13517. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13518. }
  13519. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13520. {
  13521. refreshStartTimer(&clientTime.Heartbeat);
  13522. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  13523. }
  13524. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13525. {
  13526. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13527. {
  13528. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13529. }
  13530. else
  13531. {
  13532. for(int idx=0;idx< gunTotalNumber;idx++)
  13533. {
  13534. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13535. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13536. }
  13537. }
  13538. }
  13539. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13540. {
  13541. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  13542. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  13543. {
  13544. 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\" &");
  13545. }
  13546. }
  13547. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13548. {
  13549. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13550. {
  13551. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13552. }
  13553. else
  13554. {
  13555. for(int idx=0;idx< gunTotalNumber;idx++)
  13556. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13557. }
  13558. }
  13559. return result;
  13560. }
  13561. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13562. {
  13563. mtrace();
  13564. int result = PASS;
  13565. json_object *GetInstalledCertificateIds;
  13566. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13567. GetInstalledCertificateIds = json_tokener_parse(payload);
  13568. if(!is_error(GetInstalledCertificateIds))
  13569. {
  13570. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13571. }
  13572. json_object_put(GetInstalledCertificateIds);
  13573. /*
  13574. * TODO: Return installed certificate process
  13575. */
  13576. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13577. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  13578. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13579. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  13580. sendGetInstalledCertificateIdsConfirmation(uuid);
  13581. return result;
  13582. }
  13583. int handleGetLogRequest(char *uuid, char *payload)
  13584. {
  13585. mtrace();
  13586. int result = PASS;
  13587. json_object *GetLog;
  13588. DEBUG_INFO("handleGetLogRequest...\n");
  13589. GetLog = json_tokener_parse(payload);
  13590. if(!is_error(GetLog))
  13591. {
  13592. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13593. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13594. if(json_object_object_get(GetLog, "retries") != NULL)
  13595. {
  13596. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13597. }
  13598. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13599. {
  13600. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13601. }
  13602. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13603. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13604. {
  13605. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13606. }
  13607. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13608. {
  13609. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13610. }
  13611. }
  13612. json_object_put(GetLog);
  13613. /*
  13614. * TODO: Upload log process
  13615. */
  13616. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  13617. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  13618. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  13619. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  13620. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  13621. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  13622. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  13623. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  13624. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  13625. sendGetLogConfirmation(uuid);
  13626. return result;
  13627. }
  13628. int handleInstallCertificateRequest(char *uuid, char *payload)
  13629. {
  13630. mtrace();
  13631. int result = PASS;
  13632. json_object *InstallCertificate;
  13633. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13634. InstallCertificate = json_tokener_parse(payload);
  13635. if(!is_error(InstallCertificate))
  13636. {
  13637. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13638. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13639. /*
  13640. * TODO: Install certificate process
  13641. */
  13642. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  13643. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  13644. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  13645. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  13646. sendInstallCertificateConfirmation(uuid);
  13647. }
  13648. json_object_put(InstallCertificate);
  13649. return result;
  13650. }
  13651. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13652. {
  13653. mtrace();
  13654. int result = PASS;
  13655. json_object *SignedUpdateFirmware;
  13656. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13657. SignedUpdateFirmware = json_tokener_parse(payload);
  13658. if(!is_error(SignedUpdateFirmware))
  13659. {
  13660. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13661. {
  13662. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13663. }
  13664. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13665. {
  13666. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13667. }
  13668. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13669. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13670. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13671. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13672. {
  13673. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13674. }
  13675. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13676. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13677. }
  13678. json_object_put(SignedUpdateFirmware);
  13679. /*
  13680. * TODO: Upgrade firmware process
  13681. */
  13682. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13683. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  13684. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  13685. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  13686. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  13687. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  13688. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  13689. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  13690. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  13691. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  13692. sendInstallCertificateConfirmation(uuid);
  13693. return result;
  13694. }
  13695. int handleUnknownRequest(char *uuid, char *payload)
  13696. {
  13697. mtrace();
  13698. int result = PASS;
  13699. DEBUG_INFO("handleUnknownRequest...\n");
  13700. sendUnknownConfirmation(uuid);
  13701. result = PASS;
  13702. return result;
  13703. }
  13704. //==========================================
  13705. // Handle server response routine
  13706. //==========================================
  13707. void handleAuthorizeResponse(char *payload, int gun_index)
  13708. {
  13709. mtrace();
  13710. char expiryDatestr[36]={0};
  13711. char parentIdTagstr[21]={0};
  13712. char statusstr[20]={0};
  13713. int expiryDateISNULL=FALSE;
  13714. int parentIdTagISNULL=FALSE;
  13715. DEBUG_INFO("handleAuthorizeResponse...\n");
  13716. json_object *Authorize;
  13717. Authorize = json_tokener_parse(payload);
  13718. if(!is_error(Authorize))
  13719. {
  13720. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13721. {
  13722. // Required data
  13723. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13724. // Optional data
  13725. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13726. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13727. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13728. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13729. }
  13730. }
  13731. json_object_put(Authorize);
  13732. if(expiryDateISNULL == FALSE)
  13733. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13734. if(parentIdTagISNULL == FALSE)
  13735. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13736. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  13737. //Update idTag information to authorization cache if supproted
  13738. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13739. {
  13740. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13741. }
  13742. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  13743. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13744. authorizeRetryTimes = 0;
  13745. }
  13746. void handleBootNotificationResponse(char *payload, int gun_index)
  13747. {
  13748. mtrace();
  13749. char statusStr[12]={0};
  13750. char currentTimeStr[30]={0};
  13751. int intervalInt = 0;
  13752. DEBUG_INFO("handleBootNotificationResponse...\n");
  13753. json_object *BootNotification;
  13754. BootNotification = json_tokener_parse(payload);
  13755. if(!is_error(BootNotification))
  13756. {
  13757. // Required data
  13758. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13759. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13760. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13761. }
  13762. json_object_put(BootNotification);
  13763. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13764. BootNotificationInterval = intervalInt;
  13765. //write back to ShmOCPP16DataPH->BootNotification
  13766. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  13767. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13768. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  13769. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13770. {
  13771. BootNotificationInterval = 0;
  13772. if((intervalInt == 0) || (intervalInt >= 10))
  13773. {
  13774. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13775. HeartBeatWaitTime = intervalInt;
  13776. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13777. }
  13778. server_sign = TRUE;
  13779. server_pending =FALSE;
  13780. }
  13781. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13782. {
  13783. server_pending = TRUE;
  13784. }
  13785. //syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  13786. srand(time(NULL));
  13787. refreshStartTimer(&clientTime.Heartbeat);
  13788. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13789. SetOcppConnStatus(TRUE);
  13790. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  13791. }
  13792. void handleDataTransferResponse(char *payload, int gun_index)
  13793. {
  13794. json_object *DataTransfer = json_tokener_parse(payload);
  13795. if(!is_error(DataTransfer))
  13796. {
  13797. // Required data
  13798. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13799. // Optional data
  13800. if(json_object_object_get(DataTransfer, "data") != NULL)
  13801. {
  13802. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13803. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13804. if(!is_error(Data))
  13805. {
  13806. if(json_object_object_get(Data, "msgId") != NULL)
  13807. {
  13808. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13809. {
  13810. 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")));
  13811. }
  13812. }
  13813. }
  13814. json_object_put(Data);
  13815. }
  13816. }
  13817. json_object_put(DataTransfer);
  13818. }
  13819. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13820. {
  13821. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13822. //struct json_object *obj;
  13823. // obj = json_tokener_parse(payload);
  13824. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13825. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13826. //No fields are defined.
  13827. }
  13828. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13829. {
  13830. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13831. //struct json_object *obj;
  13832. // obj = json_tokener_parse(payload);
  13833. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13834. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13835. //No fields are defined.
  13836. }
  13837. void handleHeartbeatResponse(char *payload, int gun_index)
  13838. {
  13839. mtrace();
  13840. DEBUG_INFO("handleHeartbeatResponse...\n");
  13841. json_object *Heartbeat;
  13842. Heartbeat = json_tokener_parse(payload);
  13843. if(!is_error(Heartbeat))
  13844. {
  13845. // Required data
  13846. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13847. }
  13848. json_object_put(Heartbeat);
  13849. if(FirstHeartBeat == 0)
  13850. {
  13851. FirstHeartBeat = 1;
  13852. DEBUG_INFO("FirstHeartBeat \n");
  13853. }
  13854. HeartBeatWithNOResponse = 0;
  13855. refreshStartTimer(&clientTime.Heartbeat);
  13856. //syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  13857. }
  13858. void handleMeterValuesResponse(char *payload, int gun_index)
  13859. {
  13860. mtrace();
  13861. DEBUG_INFO("handleMeterValuesResponse...\n");
  13862. isQueueSendable = 1;
  13863. }
  13864. void handleStartTransactionResponse(char *payload, int gun_index)
  13865. {
  13866. mtrace();
  13867. //int transactionIdInt = 0;
  13868. FILE *outfile;
  13869. char data[100]={0};
  13870. DEBUG_INFO("handleStartTransactionResponse...\n");
  13871. json_object *StartTransaction;
  13872. StartTransaction = json_tokener_parse(payload);
  13873. if(!is_error(StartTransaction))
  13874. {
  13875. // Required data
  13876. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13877. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13878. // Optional data
  13879. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13880. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13881. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13882. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13883. }
  13884. json_object_put(StartTransaction);
  13885. isQueueSendable = 1;
  13886. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13887. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13888. //-----------Start : write to the Queue TransactionId file -----------------//
  13889. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  13890. {}
  13891. else
  13892. {
  13893. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  13894. if(log == NULL)
  13895. {
  13896. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13897. return ;
  13898. }
  13899. else
  13900. {
  13901. fclose(log);
  13902. }
  13903. }
  13904. // open file for writing
  13905. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13906. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  13907. {
  13908. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  13909. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13910. fputs(data, outfile);
  13911. fclose (outfile);
  13912. }
  13913. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13914. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13915. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13916. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  13917. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13918. }
  13919. void handleStatusNotificationResponse(char *payload, int gun_index)
  13920. {
  13921. mtrace();
  13922. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13923. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13924. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13925. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13926. }
  13927. void handleStopTransactionnResponse(char *payload, int gun_index)
  13928. {
  13929. mtrace();
  13930. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13931. json_object *StopTransaction;
  13932. StopTransaction = json_tokener_parse(payload);
  13933. if(!is_error(StopTransaction))
  13934. {
  13935. // Optional data
  13936. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13937. {
  13938. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13939. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13940. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13941. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13942. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13943. }
  13944. }
  13945. json_object_put(StopTransaction);
  13946. isQueueSendable = 1;
  13947. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13948. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13949. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13950. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13951. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13952. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13953. }
  13954. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13955. {
  13956. mtrace();
  13957. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13958. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  13959. }
  13960. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13961. {
  13962. mtrace();
  13963. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13964. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  13965. }
  13966. void handleSignCertificateResponse(char *payload, int gun_index)
  13967. {
  13968. mtrace();
  13969. DEBUG_INFO("handleSignCertificateResponse...\n");
  13970. json_object *SignCertificate;
  13971. SignCertificate = json_tokener_parse(payload);
  13972. if(!is_error(SignCertificate))
  13973. {
  13974. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13975. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  13976. }
  13977. json_object_put(SignCertificate);
  13978. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  13979. }
  13980. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13981. {
  13982. mtrace();
  13983. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13984. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13985. }
  13986. //==========================================
  13987. // Handle Error routine
  13988. //==========================================
  13989. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13990. {
  13991. mtrace();
  13992. #ifdef SystemLogMessage
  13993. DEBUG_INFO("errorCode: %s\n", errorCode);
  13994. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13995. DEBUG_INFO("errorDetails: %s\n", payload);
  13996. #endif
  13997. }
  13998. //===============================================
  13999. // Common routine
  14000. //===============================================
  14001. int initialConfigurationTable(void)
  14002. {
  14003. //clock_t start_t, end_t, total_t;
  14004. FILE *fp;
  14005. FILE *outfile;
  14006. char str[512]={0};
  14007. char sstr[256]={0};
  14008. int c = 0;
  14009. char *loc;
  14010. int confVersion = 15;
  14011. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  14012. //start_t = clock();
  14013. //printf("Starting of the program, start_t = %ld\n", start_t);
  14014. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  14015. // Check configuration file size is correct
  14016. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  14017. {
  14018. struct stat st;
  14019. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  14020. if(st.st_size < 3100)
  14021. {
  14022. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  14023. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  14024. }
  14025. }
  14026. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  14027. {
  14028. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  14029. if(outfile == NULL)
  14030. {
  14031. DEBUG_INFO("Error opening file\n");
  14032. return FALSE;
  14033. }
  14034. /*Core Profile*/
  14035. //AllowOfflineTxForUnknownId
  14036. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14037. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14038. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  14039. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14040. //AuthorizationCacheEnabled
  14041. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14042. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14043. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14044. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14045. //AuthorizeRemoteTxRequests
  14046. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14047. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14048. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  14049. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14050. //BlinkRepeat
  14051. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14052. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14053. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14054. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14055. //ClockAlignedDataInterval
  14056. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14057. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14058. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14059. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14060. //ConnectionTimeOut
  14061. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14062. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14063. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14064. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14065. //GetConfigurationMaxKeys
  14066. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14067. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14068. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  14069. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14070. // HeartbeatInterval
  14071. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14072. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14073. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  14074. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14075. // LightIntensity
  14076. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14077. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14078. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14079. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14080. // LocalAuthorizeOffline
  14081. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  14082. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14083. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14084. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14085. // LocalPreAuthorize
  14086. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  14087. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14088. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14089. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14090. // MaxEnergyOnInvalidId
  14091. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14092. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14093. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14094. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14095. // MeterValuesAlignedData
  14096. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14097. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14098. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14099. 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" );
  14100. else
  14101. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14102. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14103. // MeterValuesAlignedDataMaxLength
  14104. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14105. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14106. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14107. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  14108. else
  14109. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  14110. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14111. // MeterValuesSampledData
  14112. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14113. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14114. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14115. 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" );
  14116. else
  14117. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14118. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14119. // MeterValuesSampledDataMaxLength
  14120. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14121. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14122. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14123. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  14124. else
  14125. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  14126. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14127. // MeterValueSampleInterval
  14128. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14129. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14130. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  14131. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14132. // MinimumStatusDuration
  14133. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14134. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14135. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  14136. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  14137. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14138. // NumberOfConnectors
  14139. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14140. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14141. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14142. {
  14143. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14144. }
  14145. else
  14146. {
  14147. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14148. }
  14149. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14150. // ResetRetries
  14151. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14152. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14153. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14154. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14155. // ConnectorPhaseRotation
  14156. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14157. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14158. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14159. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14160. // ConnectorPhaseRotationMaxLength
  14161. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14162. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14163. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14165. // StopTransactionOnEVSideDisconnect
  14166. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14167. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14168. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14169. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14170. // StopTransactionOnInvalidId
  14171. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  14172. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14173. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14174. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14175. // StopTxnAlignedData
  14176. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  14177. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14178. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  14179. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14180. // StopTxnAlignedDataMaxLength
  14181. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14182. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14183. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14184. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14185. // StopTxnSampledData
  14186. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14187. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14188. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14189. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  14190. else
  14191. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  14192. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14193. // StopTxnSampledDataMaxLength
  14194. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14195. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14196. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14197. {
  14198. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  14199. }
  14200. else
  14201. {
  14202. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  14203. }
  14204. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14205. // SupportedFeatureProfiles
  14206. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14207. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14208. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14209. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14210. // SupportedFeatureProfilesMaxLength
  14211. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14212. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14213. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14214. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14215. // TransactionMessageAttempts
  14216. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14217. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14218. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14219. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14220. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14221. // TransactionMessageRetryInterval
  14222. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14223. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14224. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14225. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14226. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14227. // UnlockConnectorOnEVSideDisconnect
  14228. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14229. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14230. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14231. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14232. // WebSocketPingInterval
  14233. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14234. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14235. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14236. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14237. // QueueOffLineMeterValues
  14238. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  14239. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14240. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  14241. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14242. // AuthorizationKey
  14243. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14244. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14245. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword );
  14246. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14247. // SecurityProfile
  14248. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14249. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14250. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  14251. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14252. // DefaultPrice
  14253. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14254. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14255. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14256. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14257. // CustomDisplayCostAndPrice
  14258. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14259. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14260. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14261. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14262. // CustomIdleFeeAfterStop
  14263. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14264. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14265. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14266. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14267. // SystemUptimeSec
  14268. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14269. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14270. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14271. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14272. // FreeVend
  14273. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14274. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14275. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14276. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14277. // FreeVendIdtag
  14278. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14279. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14280. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14281. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14282. // OcppServer
  14283. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14284. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14285. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14286. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14287. // MaintainServer
  14288. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14289. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14290. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  14291. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14292. // StatusNotificationPeriodically
  14293. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  14294. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14295. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14296. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14297. // StatusNotificationInterval
  14298. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14299. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14300. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14301. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14302. // isEnableLocalPowerSharing
  14303. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  14304. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  14305. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  14306. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  14307. // PowerSharingServerIP
  14308. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  14309. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  14310. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  14311. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  14312. // EVCCID_PREFIX
  14313. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  14314. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  14315. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  14316. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  14317. // OffLineMaxChargingPower
  14318. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  14319. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  14320. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "0" );
  14321. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  14322. // Configuration Version
  14323. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  14324. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14325. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  14326. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14327. //* Local Auth List Management Profile*/
  14328. #if 0
  14329. //For OCTT Test Case
  14330. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14331. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  14332. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14333. #endif
  14334. #if 1
  14335. //LocalAuthListEnabled
  14336. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14337. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14338. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14339. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14340. #endif
  14341. //LocalAuthListMaxLength
  14342. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14343. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14344. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14345. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14346. //SendLocalListMaxLength
  14347. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14348. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14349. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  14350. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14351. //ReserveConnectorZeroSupported
  14352. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14353. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14354. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14355. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14356. //* Smart Charging Profile */
  14357. //ChargeProfileMaxStackLevel
  14358. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14359. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14360. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  14361. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14362. // ChargingScheduleAllowedChargingRateUnit
  14363. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14364. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14365. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  14366. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14367. // ChargingScheduleMaxPeriods
  14368. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14369. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14370. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14371. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14372. // ConnectorSwitch3to1PhaseSupported
  14373. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14374. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14375. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  14376. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14377. // MaxChargingProfilesInstalled
  14378. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14379. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14380. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  14381. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14382. fclose(outfile);
  14383. }
  14384. else
  14385. {
  14386. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  14387. char keystr[60]={0};
  14388. char readonlystr[10]={0};
  14389. char valuestr[256]={0};
  14390. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  14391. if(fp == NULL) {
  14392. DEBUG_INFO("Error opening file");
  14393. return FALSE;
  14394. }
  14395. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  14396. {
  14397. //DEBUG_INFO("Get Configuration \n");
  14398. if(strlen(str) > 0)
  14399. {
  14400. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14401. //*************************key*********************************/
  14402. if(strstr(str, "key") != NULL)
  14403. {
  14404. loc = strstr(str, "key");
  14405. c = 0;
  14406. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14407. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14408. {
  14409. sstr[c] = loc[strlen("key")+3+c];
  14410. c++;
  14411. }
  14412. sstr[c] = '\0';
  14413. strcpy(keystr,sstr);
  14414. }
  14415. //*************************readonly*********************************/
  14416. if(strstr(str, "readonly") != NULL)
  14417. {
  14418. loc = strstr(str, "readonly");
  14419. c = 0;
  14420. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14421. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  14422. {
  14423. sstr[c] = loc[strlen("readonly")+2+c];
  14424. c++;
  14425. }
  14426. sstr[c] = '\0';
  14427. strcpy(readonlystr,sstr);
  14428. }
  14429. //*************************value*********************************/
  14430. if(strstr(str, "value") != NULL)
  14431. {
  14432. loc = strstr(str, "value");
  14433. c = 0;
  14434. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14435. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14436. {
  14437. sstr[c] = loc[strlen("value")+3+c];
  14438. c++;
  14439. }
  14440. sstr[c] = '\0';
  14441. strcpy(valuestr,sstr);
  14442. }
  14443. // DEBUG_INFO("keystr=%s\n",keystr);
  14444. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  14445. // DEBUG_INFO("valuestr=%s\n",valuestr);
  14446. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  14447. {
  14448. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14449. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14450. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14451. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14452. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14453. }
  14454. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14455. {
  14456. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14457. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14458. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14459. }
  14460. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14461. {
  14462. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14463. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14464. }
  14465. if(strcmp(keystr, "BlinkRepeat") == 0)
  14466. {
  14467. //Charger.BlinkRepeat = Integer.parseInt(value);
  14468. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14469. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14470. }
  14471. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14472. {
  14473. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14474. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14475. }
  14476. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14477. {
  14478. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14479. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14480. }
  14481. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14482. {
  14483. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14484. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14485. }
  14486. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14487. {
  14488. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14489. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14490. HeartBeatWaitTime = atoi(valuestr);
  14491. }
  14492. if(strcmp(keystr, "LightIntensity") == 0)
  14493. {
  14494. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14495. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14496. }
  14497. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14498. {
  14499. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14500. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14501. }
  14502. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14503. {
  14504. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14505. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14506. }
  14507. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14508. {
  14509. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14510. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14511. }
  14512. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14513. {
  14514. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14515. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14516. }
  14517. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14518. {
  14519. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14520. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14521. }
  14522. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14523. {
  14524. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14525. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14526. }
  14527. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14528. {
  14529. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14530. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14531. }
  14532. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14533. {
  14534. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14535. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14536. }
  14537. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14538. {
  14539. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14540. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14541. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14542. }
  14543. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14544. {
  14545. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14546. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14547. }
  14548. if(strcmp(keystr, "ResetRetries") == 0)
  14549. {
  14550. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14551. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14552. }
  14553. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14554. {
  14555. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14556. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14557. }
  14558. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14559. {
  14560. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14561. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14562. }
  14563. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14564. {
  14565. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14566. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14567. }
  14568. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14569. {
  14570. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14571. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14572. }
  14573. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14574. {
  14575. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14576. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14577. }
  14578. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14579. {
  14580. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14581. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14582. }
  14583. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14584. {
  14585. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14586. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14587. }
  14588. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14589. {
  14590. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14591. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14592. }
  14593. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14594. {
  14595. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14596. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14597. }
  14598. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14599. {
  14600. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14601. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14602. }
  14603. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14604. {
  14605. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14606. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14607. TransactionMessageAttemptsValue = atoi(valuestr);
  14608. }
  14609. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14610. {
  14611. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14612. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14613. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14614. }
  14615. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14616. {
  14617. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14618. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14619. }
  14620. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14621. {
  14622. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14623. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14624. }
  14625. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14626. {
  14627. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14628. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14629. }
  14630. if(strcmp(keystr, "AuthorizationKey") == 0)
  14631. {
  14632. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14633. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14634. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword);
  14635. }
  14636. if(strcmp(keystr, "SecurityProfile") == 0)
  14637. {
  14638. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14639. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  14640. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  14641. }
  14642. if(strcmp(keystr, "DefaultPrice") == 0)
  14643. {
  14644. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14645. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14646. }
  14647. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14648. {
  14649. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14650. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14651. }
  14652. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14653. {
  14654. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14655. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14656. }
  14657. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14658. {
  14659. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14660. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  14661. }
  14662. if(strcmp(keystr, "FreeVend") == 0)
  14663. {
  14664. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14665. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14666. }
  14667. if(strcmp(keystr, "FreeVendIdtag") == 0)
  14668. {
  14669. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14670. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  14671. }
  14672. if(strcmp(keystr, "OcppServer") == 0)
  14673. {
  14674. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14675. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14676. }
  14677. if(strcmp(keystr, "MaintainServer") == 0)
  14678. {
  14679. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14680. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14681. }
  14682. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14683. {
  14684. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14685. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14686. }
  14687. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14688. {
  14689. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14690. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14691. }
  14692. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  14693. {
  14694. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14695. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  14696. }
  14697. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  14698. {
  14699. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14700. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  14701. }
  14702. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  14703. {
  14704. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14705. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  14706. }
  14707. if(strcmp(keystr, "OffLineMaxChargingPower") == 0)
  14708. {
  14709. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14710. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", valuestr);
  14711. }
  14712. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14713. {
  14714. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14715. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14716. }
  14717. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14718. {
  14719. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14720. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14721. }
  14722. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14723. {
  14724. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14725. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14726. }
  14727. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14728. {
  14729. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14730. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14731. }
  14732. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14733. {
  14734. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14735. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14736. }
  14737. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14738. {
  14739. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14740. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14741. }
  14742. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14743. {
  14744. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14745. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14746. }
  14747. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14748. {
  14749. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14750. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14751. }
  14752. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14753. {
  14754. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14755. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14756. }
  14757. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14758. {
  14759. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14760. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14761. }
  14762. }
  14763. }
  14764. fclose(fp);
  14765. }
  14766. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14767. {
  14768. return PASS;
  14769. }
  14770. else
  14771. {
  14772. return FAIL;
  14773. }
  14774. }
  14775. void StoreConfigurationTable(void)
  14776. {
  14777. FILE *outfile;
  14778. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  14779. if(outfile == NULL)
  14780. {
  14781. DEBUG_INFO("Error opening file");
  14782. return ;
  14783. }
  14784. /*Core Profile*/
  14785. //AllowOfflineTxForUnknownId
  14786. /*
  14787. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14788. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14789. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14790. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14791. */
  14792. //DEBUG_INFO("data=%s\n",data);
  14793. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14794. //AuthorizationCacheEnabled
  14795. /*
  14796. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14797. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14798. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14799. */
  14800. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14801. //AuthorizeRemoteTxRequests
  14802. /*
  14803. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14804. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14805. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14806. */
  14807. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14808. //BlinkRepeat
  14809. /*
  14810. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14811. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14812. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14813. */
  14814. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14815. //ClockAlignedDataInterval
  14816. /*
  14817. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14818. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14819. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14820. */
  14821. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14822. //ConnectionTimeOut
  14823. /*
  14824. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14825. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14826. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14827. */
  14828. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14829. //GetConfigurationMaxKeys
  14830. /*
  14831. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14832. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14833. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14834. */
  14835. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14836. // HeartbeatInterval
  14837. /*
  14838. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14839. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14840. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14841. */
  14842. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14843. // LightIntensity
  14844. /*
  14845. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14846. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14847. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14848. */
  14849. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14850. // LocalAuthorizeOffline
  14851. /*
  14852. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14853. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14854. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14855. */
  14856. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14857. // LocalPreAuthorize
  14858. /*
  14859. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14860. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14861. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14862. */
  14863. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14864. // MaxEnergyOnInvalidId
  14865. /*
  14866. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14867. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14868. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14869. */
  14870. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14871. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14872. // MeterValuesAlignedData
  14873. /*
  14874. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14875. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14876. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14877. */
  14878. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14879. // MeterValuesAlignedDataMaxLength
  14880. /*
  14881. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14882. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14883. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14884. */
  14885. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14886. // MeterValuesSampledData
  14887. /*
  14888. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14889. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14890. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14891. */
  14892. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14893. // MeterValuesSampledDataMaxLength
  14894. /*
  14895. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14896. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14897. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14898. */
  14899. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14900. // MeterValueSampleInterval
  14901. /*
  14902. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14903. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14904. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14905. */
  14906. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14907. // MinimumStatusDuration
  14908. /*
  14909. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14910. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14911. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14912. */
  14913. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14914. // NumberOfConnectors
  14915. /*
  14916. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14917. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14918. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14919. {
  14920. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14921. }
  14922. else
  14923. {
  14924. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14925. }
  14926. */
  14927. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14928. // ResetRetries
  14929. /*
  14930. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14931. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14932. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14933. */
  14934. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14935. // ConnectorPhaseRotation
  14936. /*
  14937. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14938. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14939. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14940. */
  14941. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14942. // ConnectorPhaseRotationMaxLength
  14943. /*
  14944. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14945. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14946. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14947. */
  14948. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14949. // StopTransactionOnEVSideDisconnect
  14950. /*
  14951. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14952. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14953. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14954. */
  14955. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14956. // StopTransactionOnInvalidId
  14957. /*
  14958. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14959. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14960. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14961. */
  14962. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14963. // StopTxnAlignedData
  14964. /*
  14965. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14966. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14967. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14968. */
  14969. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14970. // StopTxnAlignedDataMaxLength
  14971. /*
  14972. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14973. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14974. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14975. */
  14976. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14977. // StopTxnSampledData
  14978. /*
  14979. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14980. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14981. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14982. */
  14983. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14984. // StopTxnSampledDataMaxLength
  14985. /*
  14986. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14987. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14988. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14989. */
  14990. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14991. // SupportedFeatureProfiles
  14992. /*
  14993. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14994. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14995. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14996. */
  14997. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14998. // SupportedFeatureProfilesMaxLength
  14999. /*
  15000. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  15001. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  15002. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  15003. */
  15004. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  15005. // TransactionMessageAttempts
  15006. /*
  15007. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  15008. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  15009. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  15010. */
  15011. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15012. // TransactionMessageRetryInterval
  15013. /*
  15014. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  15015. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  15016. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  15017. */
  15018. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15019. // UnlockConnectorOnEVSideDisconnect
  15020. /*
  15021. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  15022. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  15023. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  15024. */
  15025. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15026. // WebSocketPingInterval
  15027. /*
  15028. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15029. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15030. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15031. */
  15032. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15033. // QueueOffLineMeterValues
  15034. /*
  15035. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  15036. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15037. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  15038. */
  15039. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15040. // AuthorizationKey
  15041. /*
  15042. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15043. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15044. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  15045. */
  15046. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15047. // SecurityProfile
  15048. /*
  15049. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15050. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15051. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  15052. */
  15053. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15054. // DefaultPrice
  15055. /*
  15056. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15057. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15058. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15059. */
  15060. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15061. // CustomDisplayCostAndPrice
  15062. /*
  15063. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15064. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15065. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15066. */
  15067. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15068. // CustomIdleFeeAfterStop
  15069. /*
  15070. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15071. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15072. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15073. */
  15074. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15075. // SystemUptimeSec
  15076. /*
  15077. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15078. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15079. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15080. */
  15081. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15082. // FreeVend
  15083. /*
  15084. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15085. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15086. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  15087. */
  15088. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15089. // FreeVendIdtag
  15090. /*
  15091. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15092. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15093. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15094. */
  15095. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15096. // OcppServer
  15097. /*
  15098. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15099. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15100. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  15101. */
  15102. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15103. // MaintainServer
  15104. /*
  15105. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15106. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15107. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  15108. */
  15109. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15110. // StatusNotificationPeriodically
  15111. /*
  15112. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  15113. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15114. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15115. */
  15116. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15117. // StatusNotificationInterval
  15118. /*
  15119. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15120. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15121. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15122. */
  15123. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15124. // isEnableLocalPowerSharing
  15125. /*
  15126. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  15127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  15128. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  15129. */
  15130. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  15131. // PowerSharingServerIP
  15132. /*
  15133. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  15134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  15135. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  15136. */
  15137. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  15138. // EVCCID_PREFIX
  15139. /*
  15140. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  15141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  15142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  15143. */
  15144. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  15145. // OffLineMaxChargingPower
  15146. /*
  15147. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  15148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  15149. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "" );
  15150. */
  15151. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  15152. // ConfigurationVersion
  15153. /*
  15154. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  15155. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15156. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  15157. */
  15158. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15159. //* Local Auth List Management Profile*/
  15160. //LocalAuthListEnabled
  15161. /*
  15162. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15163. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15164. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15165. */
  15166. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15167. //LocalAuthListMaxLength
  15168. /*
  15169. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15170. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15171. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  15172. */
  15173. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15174. //SendLocalListMaxLength
  15175. /*
  15176. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15177. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15178. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  15179. */
  15180. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15181. //ReserveConnectorZeroSupported
  15182. /*
  15183. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15184. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15185. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15186. */
  15187. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15188. //* Smart Charging Profile */
  15189. //ChargeProfileMaxStackLevel
  15190. /*
  15191. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  15192. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  15193. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  15194. */
  15195. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15196. // ChargingScheduleAllowedChargingRateUnit
  15197. /*
  15198. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  15199. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  15200. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  15201. */
  15202. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15203. // ChargingScheduleMaxPeriods
  15204. /*
  15205. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  15206. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  15207. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  15208. */
  15209. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15210. // ConnectorSwitch3to1PhaseSupported
  15211. /*
  15212. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  15213. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  15214. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  15215. */
  15216. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15217. // MaxChargingProfilesInstalled
  15218. /*
  15219. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  15220. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  15221. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  15222. */
  15223. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15224. fclose(outfile);
  15225. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15226. }
  15227. void getKeyValue(char *keyReq)
  15228. {
  15229. int isEmpty = FALSE;
  15230. int isKnowKey = FALSE;
  15231. DEBUG_INFO("keyReq = %s\n", keyReq);
  15232. if((keyReq == NULL) || (strlen(keyReq) == 0))
  15233. isEmpty = TRUE;
  15234. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  15235. {
  15236. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  15237. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  15238. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15239. {
  15240. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  15241. }
  15242. else
  15243. {
  15244. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  15245. }
  15246. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  15247. isKnowKey = TRUE;
  15248. }
  15249. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  15250. {
  15251. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  15252. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  15253. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15254. {
  15255. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  15256. }
  15257. else
  15258. {
  15259. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  15260. }
  15261. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  15262. isKnowKey = TRUE;
  15263. }
  15264. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  15265. {
  15266. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  15267. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  15268. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15269. {
  15270. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  15271. }
  15272. else
  15273. {
  15274. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  15275. }
  15276. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  15277. isKnowKey = TRUE;
  15278. }
  15279. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  15280. {
  15281. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  15282. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  15283. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15284. {
  15285. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  15286. }
  15287. else
  15288. {
  15289. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  15290. }
  15291. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  15292. isKnowKey = TRUE;
  15293. }
  15294. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  15295. {
  15296. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  15297. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  15298. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15299. {
  15300. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  15301. }
  15302. else
  15303. {
  15304. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  15305. }
  15306. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  15307. isKnowKey = TRUE;
  15308. }
  15309. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  15310. {
  15311. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  15312. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  15313. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15314. {
  15315. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  15316. }
  15317. else
  15318. {
  15319. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  15320. }
  15321. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  15322. isKnowKey = TRUE;
  15323. }
  15324. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  15325. {
  15326. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  15327. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  15328. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15329. {
  15330. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  15331. }
  15332. else
  15333. {
  15334. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  15335. }
  15336. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  15337. isKnowKey = TRUE;
  15338. }
  15339. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  15340. {
  15341. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  15342. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  15343. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15344. {
  15345. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  15346. }
  15347. else
  15348. {
  15349. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  15350. }
  15351. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  15352. isKnowKey = TRUE;
  15353. }
  15354. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  15355. {
  15356. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  15357. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  15358. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15359. {
  15360. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  15361. }
  15362. else
  15363. {
  15364. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  15365. }
  15366. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  15367. isKnowKey = TRUE;
  15368. }
  15369. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  15370. {
  15371. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  15372. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  15373. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15374. {
  15375. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  15376. }
  15377. else
  15378. {
  15379. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  15380. }
  15381. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  15382. isKnowKey = TRUE;
  15383. }
  15384. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  15385. {
  15386. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  15387. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  15388. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15389. {
  15390. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  15391. }
  15392. else
  15393. {
  15394. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  15395. }
  15396. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  15397. isKnowKey = TRUE;
  15398. }
  15399. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  15400. {
  15401. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  15402. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  15403. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15404. {
  15405. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15406. }
  15407. else
  15408. {
  15409. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15410. }
  15411. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  15412. isKnowKey = TRUE;
  15413. }
  15414. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  15415. {
  15416. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  15417. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  15418. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15419. {
  15420. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15421. }
  15422. else
  15423. {
  15424. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15425. }
  15426. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  15427. isKnowKey = TRUE;
  15428. }
  15429. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  15430. {
  15431. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  15432. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  15433. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15434. {
  15435. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15436. }
  15437. else
  15438. {
  15439. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15440. }
  15441. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  15442. isKnowKey = TRUE;
  15443. }
  15444. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  15445. {
  15446. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  15447. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  15448. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15449. {
  15450. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  15451. }
  15452. else
  15453. {
  15454. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  15455. }
  15456. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  15457. isKnowKey = TRUE;
  15458. }
  15459. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  15460. {
  15461. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  15462. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  15463. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15464. {
  15465. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15466. }
  15467. else
  15468. {
  15469. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15470. }
  15471. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  15472. isKnowKey = TRUE;
  15473. }
  15474. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  15475. {
  15476. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  15477. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  15478. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15479. {
  15480. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  15481. }
  15482. else
  15483. {
  15484. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  15485. }
  15486. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  15487. isKnowKey = TRUE;
  15488. }
  15489. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  15490. {
  15491. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  15492. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  15493. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15494. {
  15495. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  15496. }
  15497. else
  15498. {
  15499. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  15500. }
  15501. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  15502. isKnowKey = TRUE;
  15503. }
  15504. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  15505. {
  15506. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  15507. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  15508. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15509. {
  15510. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  15511. }
  15512. else
  15513. {
  15514. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15515. }
  15516. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15517. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15518. isKnowKey = TRUE;
  15519. }
  15520. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15521. {
  15522. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15523. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15524. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15525. {
  15526. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15527. }
  15528. else
  15529. {
  15530. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15531. }
  15532. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15533. isKnowKey = TRUE;
  15534. }
  15535. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15536. {
  15537. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15538. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15539. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15540. {
  15541. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15542. }
  15543. else
  15544. {
  15545. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15546. }
  15547. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15548. isKnowKey = TRUE;
  15549. }
  15550. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15551. {
  15552. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15553. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15554. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15555. {
  15556. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15557. }
  15558. else
  15559. {
  15560. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15561. }
  15562. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15563. isKnowKey = TRUE;
  15564. }
  15565. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15566. {
  15567. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15568. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15569. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15570. {
  15571. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15572. }
  15573. else
  15574. {
  15575. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15576. }
  15577. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15578. isKnowKey = TRUE;
  15579. }
  15580. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15581. {
  15582. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15583. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15584. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15585. {
  15586. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15587. }
  15588. else
  15589. {
  15590. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15591. }
  15592. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15593. isKnowKey = TRUE;
  15594. }
  15595. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15596. {
  15597. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15598. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15599. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15600. {
  15601. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15602. }
  15603. else
  15604. {
  15605. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15606. }
  15607. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15608. isKnowKey = TRUE;
  15609. }
  15610. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15611. {
  15612. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15613. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15614. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15615. {
  15616. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15617. }
  15618. else
  15619. {
  15620. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15621. }
  15622. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15623. isKnowKey = TRUE;
  15624. }
  15625. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15626. {
  15627. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15628. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15629. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15630. {
  15631. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15632. }
  15633. else
  15634. {
  15635. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15636. }
  15637. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15638. isKnowKey = TRUE;
  15639. }
  15640. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15641. {
  15642. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15643. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15644. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15645. {
  15646. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15647. }
  15648. else
  15649. {
  15650. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15651. }
  15652. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15653. isKnowKey = TRUE;
  15654. }
  15655. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15656. {
  15657. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15658. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15659. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15660. {
  15661. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15662. }
  15663. else
  15664. {
  15665. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15666. }
  15667. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15668. isKnowKey = TRUE;
  15669. }
  15670. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15671. {
  15672. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15673. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15674. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15675. {
  15676. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15677. }
  15678. else
  15679. {
  15680. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15681. }
  15682. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15683. isKnowKey = TRUE;
  15684. }
  15685. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15686. {
  15687. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15688. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15689. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15690. {
  15691. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15692. }
  15693. else
  15694. {
  15695. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15696. }
  15697. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15698. isKnowKey = TRUE;
  15699. }
  15700. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15701. {
  15702. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15703. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15704. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15705. {
  15706. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15707. }
  15708. else
  15709. {
  15710. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15711. }
  15712. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15713. isKnowKey = TRUE;
  15714. }
  15715. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15716. {
  15717. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15718. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15719. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15720. {
  15721. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15722. }
  15723. else
  15724. {
  15725. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15726. }
  15727. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15728. isKnowKey = TRUE;
  15729. }
  15730. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15731. {
  15732. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15733. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15734. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15735. {
  15736. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15737. }
  15738. else
  15739. {
  15740. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15741. }
  15742. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15743. isKnowKey = TRUE;
  15744. }
  15745. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15746. {
  15747. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15748. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15749. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15750. {
  15751. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15752. }
  15753. else
  15754. {
  15755. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15756. }
  15757. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15758. isKnowKey = TRUE;
  15759. }
  15760. /*
  15761. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15762. {
  15763. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15764. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15765. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15766. {
  15767. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15768. }
  15769. else
  15770. {
  15771. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15772. }
  15773. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15774. isKnowKey = TRUE;
  15775. }*/
  15776. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15777. {
  15778. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15779. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15780. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15781. {
  15782. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15783. }
  15784. else
  15785. {
  15786. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15787. }
  15788. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15789. isKnowKey = TRUE;
  15790. }
  15791. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15792. {
  15793. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15794. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15795. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15796. {
  15797. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15798. }
  15799. else
  15800. {
  15801. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15802. }
  15803. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15804. isKnowKey = TRUE;
  15805. }
  15806. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15807. {
  15808. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15809. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15810. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15811. {
  15812. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15813. }
  15814. else
  15815. {
  15816. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15817. }
  15818. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15819. isKnowKey = TRUE;
  15820. }
  15821. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15822. {
  15823. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15824. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15825. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15826. {
  15827. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15828. }
  15829. else
  15830. {
  15831. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15832. }
  15833. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15834. isKnowKey = TRUE;
  15835. }
  15836. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15837. {
  15838. struct sysinfo s_info;
  15839. int error = sysinfo(&s_info);
  15840. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15841. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15842. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15843. {
  15844. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15845. }
  15846. else
  15847. {
  15848. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15849. }
  15850. if(error != 0)
  15851. {
  15852. DEBUG_WARN("System uptime get error: %d\n", error);
  15853. }
  15854. else
  15855. {
  15856. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15857. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15858. }
  15859. isKnowKey = TRUE;
  15860. }
  15861. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15862. {
  15863. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15864. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15865. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15866. {
  15867. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15868. }
  15869. else
  15870. {
  15871. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15872. }
  15873. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15874. isKnowKey = TRUE;
  15875. }
  15876. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  15877. {
  15878. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  15879. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  15880. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  15881. {
  15882. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  15883. }
  15884. else
  15885. {
  15886. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  15887. }
  15888. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15889. isKnowKey = TRUE;
  15890. }
  15891. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15892. {
  15893. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15894. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15895. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15896. {
  15897. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15898. }
  15899. else
  15900. {
  15901. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15902. }
  15903. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15904. isKnowKey = TRUE;
  15905. }
  15906. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15907. {
  15908. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15909. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15910. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15911. {
  15912. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15913. }
  15914. else
  15915. {
  15916. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15917. }
  15918. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15919. isKnowKey = TRUE;
  15920. }
  15921. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15922. {
  15923. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15924. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15925. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15926. {
  15927. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15928. }
  15929. else
  15930. {
  15931. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15932. }
  15933. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15934. isKnowKey = TRUE;
  15935. }
  15936. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15937. {
  15938. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15939. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15940. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15941. {
  15942. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15943. }
  15944. else
  15945. {
  15946. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15947. }
  15948. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15949. isKnowKey = TRUE;
  15950. }
  15951. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  15952. {
  15953. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  15954. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  15955. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  15956. {
  15957. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  15958. }
  15959. else
  15960. {
  15961. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  15962. }
  15963. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  15964. isKnowKey = TRUE;
  15965. }
  15966. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  15967. {
  15968. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  15969. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  15970. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  15971. {
  15972. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  15973. }
  15974. else
  15975. {
  15976. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  15977. }
  15978. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  15979. isKnowKey = TRUE;
  15980. }
  15981. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  15982. {
  15983. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  15984. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  15985. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  15986. {
  15987. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  15988. }
  15989. else
  15990. {
  15991. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  15992. }
  15993. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  15994. isKnowKey = TRUE;
  15995. }
  15996. if(isEmpty || strcmp(keyReq, "OffLineMaxChargingPower") == 0 )
  15997. {
  15998. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OffLineMaxChargingPower].Item, "OffLineMaxChargingPower");
  15999. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Key, "OffLineMaxChargingPower");
  16000. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  16001. {
  16002. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "0"/*"FALSE"*/);
  16003. }
  16004. else
  16005. {
  16006. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "1"/*"TRUE"*/);
  16007. }
  16008. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData );
  16009. isKnowKey = TRUE;
  16010. }
  16011. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  16012. {
  16013. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  16014. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  16015. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  16016. {
  16017. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  16018. }
  16019. else
  16020. {
  16021. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  16022. }
  16023. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  16024. isKnowKey = TRUE;
  16025. }
  16026. #if 1
  16027. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  16028. {
  16029. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  16030. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  16031. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16032. {
  16033. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  16034. }
  16035. else
  16036. {
  16037. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  16038. }
  16039. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  16040. isKnowKey = TRUE;
  16041. }
  16042. #endif
  16043. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  16044. {
  16045. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  16046. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  16047. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16048. {
  16049. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16050. }
  16051. else
  16052. {
  16053. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16054. }
  16055. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  16056. isKnowKey = TRUE;
  16057. }
  16058. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  16059. {
  16060. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  16061. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  16062. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16063. {
  16064. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16065. }
  16066. else
  16067. {
  16068. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16069. }
  16070. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  16071. isKnowKey = TRUE;
  16072. }
  16073. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  16074. {
  16075. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  16076. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  16077. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16078. {
  16079. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  16080. }
  16081. else
  16082. {
  16083. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  16084. }
  16085. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16086. isKnowKey = TRUE;
  16087. }
  16088. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  16089. {
  16090. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  16091. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  16092. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16093. {
  16094. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  16095. }
  16096. else
  16097. {
  16098. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  16099. }
  16100. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16101. isKnowKey = TRUE;
  16102. }
  16103. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  16104. {
  16105. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  16106. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  16107. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16108. {
  16109. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  16110. }
  16111. else
  16112. {
  16113. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  16114. }
  16115. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16116. isKnowKey = TRUE;
  16117. }
  16118. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  16119. {
  16120. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  16121. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  16122. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16123. {
  16124. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  16125. }
  16126. else
  16127. {
  16128. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  16129. }
  16130. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16131. isKnowKey = TRUE;
  16132. }
  16133. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  16134. {
  16135. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  16136. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  16137. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16138. {
  16139. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  16140. }
  16141. else
  16142. {
  16143. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  16144. }
  16145. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16146. isKnowKey = TRUE;
  16147. }
  16148. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  16149. {
  16150. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  16151. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  16152. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16153. {
  16154. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  16155. }
  16156. else
  16157. {
  16158. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  16159. }
  16160. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16161. isKnowKey = TRUE;
  16162. }
  16163. //=========================================================
  16164. if(!isEmpty && !isKnowKey)
  16165. {
  16166. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  16167. strcpy(unknownkey[UnknownKeynum], keyReq);
  16168. UnknownKeynum = UnknownKeynum + 1;
  16169. }
  16170. }
  16171. void processUnkownKey(void)
  16172. {
  16173. DEBUG_INFO("processUnkownKey...\n");
  16174. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  16175. for(int index=0; index < UnknownKeynum; index++)
  16176. {
  16177. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  16178. {
  16179. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  16180. }
  16181. }
  16182. }
  16183. int setKeyValue(char *key, char *value)
  16184. {
  16185. int isSuccess = NotSupported;
  16186. int check_ascii=0;
  16187. char str[501]={0};
  16188. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  16189. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  16190. {
  16191. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  16192. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16193. {
  16194. strcpy(str, (const char*)value);
  16195. for(int i = 0; str[i]; i++){
  16196. str[i] = tolower(str[i]);
  16197. }
  16198. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16199. isSuccess = ConfigurationStatus_Accepted;
  16200. }
  16201. else
  16202. {
  16203. isSuccess = ConfigurationStatus_Rejected;
  16204. }
  16205. }
  16206. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  16207. {
  16208. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  16209. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16210. {
  16211. strcpy(str, (const char*)value);
  16212. for(int i = 0; str[i]; i++){
  16213. str[i] = tolower(str[i]);
  16214. }
  16215. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16216. isSuccess = ConfigurationStatus_Accepted;
  16217. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  16218. }
  16219. else
  16220. {
  16221. isSuccess = ConfigurationStatus_Rejected;
  16222. }
  16223. }
  16224. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  16225. {
  16226. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16227. {
  16228. strcpy(str, (const char*)value);
  16229. for(int i = 0; str[i]; i++)
  16230. {
  16231. str[i] = tolower(str[i]);
  16232. }
  16233. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  16234. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16235. isSuccess = ConfigurationStatus_Accepted;
  16236. }
  16237. else
  16238. {
  16239. isSuccess = ConfigurationStatus_Rejected;
  16240. }
  16241. }
  16242. if(strcmp(key, "BlinkRepeat") == 0)
  16243. {
  16244. //Charger.BlinkRepeat = Integer.parseInt(value);
  16245. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16246. {
  16247. check_ascii = value[0];
  16248. if( (check_ascii < 48) || (check_ascii > 57) )
  16249. {
  16250. isSuccess = ConfigurationStatus_Rejected;
  16251. }
  16252. else
  16253. {
  16254. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  16255. isSuccess = ConfigurationStatus_Accepted;
  16256. }
  16257. }
  16258. else
  16259. {
  16260. isSuccess = ConfigurationStatus_Rejected;
  16261. }
  16262. }
  16263. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  16264. {
  16265. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16266. {
  16267. check_ascii = value[0];
  16268. if( (check_ascii < 48) || (check_ascii > 57) )
  16269. {
  16270. isSuccess = ConfigurationStatus_Rejected;
  16271. }
  16272. else
  16273. {
  16274. if((atoi(value) == 0) || (atoi(value) >= 5))
  16275. {
  16276. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  16277. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  16278. isSuccess = ConfigurationStatus_Accepted;
  16279. }
  16280. else
  16281. isSuccess = ConfigurationStatus_Rejected;
  16282. }
  16283. }
  16284. else
  16285. {
  16286. isSuccess = ConfigurationStatus_Rejected;
  16287. }
  16288. }
  16289. if(strcmp(key, "ConnectionTimeOut") == 0 )
  16290. {
  16291. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  16292. {
  16293. check_ascii = value[0];
  16294. if( (check_ascii < 48) || (check_ascii > 57) )
  16295. {
  16296. isSuccess = ConfigurationStatus_Rejected;
  16297. }
  16298. else
  16299. {
  16300. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  16301. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  16302. isSuccess = ConfigurationStatus_Accepted;
  16303. }
  16304. }
  16305. else
  16306. {
  16307. isSuccess = ConfigurationStatus_Rejected;
  16308. }
  16309. }
  16310. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  16311. {
  16312. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  16313. {
  16314. check_ascii = value[0];
  16315. if( (check_ascii < 48) || (check_ascii > 57) )
  16316. {
  16317. isSuccess = ConfigurationStatus_Rejected;
  16318. }
  16319. else
  16320. {
  16321. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16322. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  16323. isSuccess = ConfigurationStatus_Accepted;
  16324. }
  16325. }
  16326. else
  16327. {
  16328. isSuccess = ConfigurationStatus_Rejected;
  16329. }
  16330. }
  16331. if(strcmp(key, "HeartbeatInterval") == 0)
  16332. {
  16333. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  16334. {
  16335. check_ascii = value[0];
  16336. if( (check_ascii < 48) || (check_ascii > 57) )
  16337. {
  16338. isSuccess = ConfigurationStatus_Rejected;
  16339. }
  16340. else
  16341. {
  16342. if((atoi(value) == 0) || (atoi(value) >= 10))
  16343. {
  16344. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16345. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  16346. HeartBeatWaitTime = atoi(value);
  16347. isSuccess = ConfigurationStatus_Accepted;
  16348. }
  16349. else
  16350. {
  16351. isSuccess = ConfigurationStatus_Rejected;
  16352. }
  16353. }
  16354. }
  16355. else
  16356. {
  16357. isSuccess = ConfigurationStatus_Rejected;
  16358. }
  16359. }
  16360. if(strcmp(key, "LightIntensity") == 0)
  16361. {
  16362. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16363. {
  16364. check_ascii = value[0];
  16365. if( (check_ascii < 48) || (check_ascii > 57) )
  16366. {
  16367. isSuccess = ConfigurationStatus_Rejected;
  16368. }
  16369. else
  16370. {
  16371. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  16372. isSuccess = ConfigurationStatus_Accepted;
  16373. }
  16374. }
  16375. else
  16376. {
  16377. isSuccess = ConfigurationStatus_Rejected;
  16378. }
  16379. }
  16380. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  16381. {
  16382. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  16383. {
  16384. strcpy(str, (const char*)value);
  16385. for(int i = 0; str[i]; i++)
  16386. {
  16387. str[i] = tolower(str[i]);
  16388. }
  16389. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16390. isSuccess = ConfigurationStatus_Accepted;
  16391. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16392. }
  16393. else
  16394. {
  16395. isSuccess = ConfigurationStatus_Rejected;
  16396. }
  16397. }
  16398. if(strcmp(key, "LocalPreAuthorize") == 0)
  16399. {
  16400. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16401. {
  16402. strcpy(str, (const char*)value);
  16403. for(int i = 0; str[i]; i++)
  16404. {
  16405. str[i] = tolower(str[i]);
  16406. }
  16407. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16408. isSuccess = ConfigurationStatus_Accepted;
  16409. }
  16410. else
  16411. {
  16412. isSuccess = ConfigurationStatus_Rejected;
  16413. }
  16414. }
  16415. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  16416. {
  16417. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  16418. {
  16419. check_ascii = value[0];
  16420. if( (check_ascii < 48) || (check_ascii > 57) )
  16421. {
  16422. isSuccess = ConfigurationStatus_Rejected;
  16423. }
  16424. else
  16425. {
  16426. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  16427. isSuccess = ConfigurationStatus_Accepted;
  16428. }
  16429. }
  16430. else
  16431. {
  16432. isSuccess = ConfigurationStatus_Rejected;
  16433. }
  16434. }
  16435. if(strcmp(key, "MeterValuesAlignedData") == 0)
  16436. {
  16437. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  16438. {
  16439. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  16440. isSuccess = ConfigurationStatus_Accepted;
  16441. }
  16442. else
  16443. {
  16444. isSuccess = ConfigurationStatus_Rejected;
  16445. }
  16446. }
  16447. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  16448. {
  16449. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  16450. {
  16451. check_ascii = value[0];
  16452. if( (check_ascii < 48) || (check_ascii > 57) )
  16453. {
  16454. isSuccess = ConfigurationStatus_Rejected;
  16455. }
  16456. else
  16457. {
  16458. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16459. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  16460. isSuccess = ConfigurationStatus_Accepted;
  16461. }
  16462. }
  16463. else
  16464. {
  16465. isSuccess = ConfigurationStatus_Rejected;
  16466. }
  16467. }
  16468. if(strcmp(key, "MeterValuesSampledData") == 0 )
  16469. {
  16470. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  16471. {
  16472. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  16473. isSuccess = ConfigurationStatus_Accepted;
  16474. }
  16475. else
  16476. {
  16477. isSuccess = ConfigurationStatus_Rejected;
  16478. }
  16479. }
  16480. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  16481. {
  16482. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16483. {
  16484. check_ascii = value[0];
  16485. if( (check_ascii < 48) || (check_ascii > 57) )
  16486. {
  16487. isSuccess = ConfigurationStatus_Rejected;
  16488. }
  16489. else
  16490. {
  16491. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16492. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  16493. isSuccess = ConfigurationStatus_Accepted;
  16494. }
  16495. }
  16496. else
  16497. {
  16498. isSuccess = ConfigurationStatus_Rejected;
  16499. }
  16500. }
  16501. if(strcmp(key, "MeterValueSampleInterval") == 0)
  16502. {
  16503. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16504. {
  16505. check_ascii = value[0];
  16506. if( (check_ascii < 48) || (check_ascii > 57) )
  16507. {
  16508. isSuccess = ConfigurationStatus_Rejected;
  16509. }
  16510. else
  16511. {
  16512. if((atoi(value) == 0) || (atoi(value) >= 3))
  16513. {
  16514. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16515. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  16516. isSuccess = ConfigurationStatus_Accepted;
  16517. }
  16518. else
  16519. {
  16520. isSuccess = ConfigurationStatus_Rejected;
  16521. }
  16522. }
  16523. }
  16524. else
  16525. {
  16526. isSuccess = ConfigurationStatus_Rejected;
  16527. }
  16528. }
  16529. if(strcmp(key, "MinimumStatusDuration") == 0)
  16530. {
  16531. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16532. {
  16533. check_ascii = value[0];
  16534. if( (check_ascii < 48) || (check_ascii > 57) )
  16535. {
  16536. isSuccess = ConfigurationStatus_Rejected;
  16537. }
  16538. else
  16539. {
  16540. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  16541. {
  16542. isSuccess = ConfigurationStatus_Rejected;
  16543. }
  16544. else
  16545. {
  16546. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16547. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16548. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16549. isSuccess = ConfigurationStatus_Accepted;
  16550. }
  16551. }
  16552. }
  16553. else
  16554. {
  16555. isSuccess = ConfigurationStatus_Rejected;
  16556. }
  16557. }
  16558. if(strcmp(key, "NumberOfConnectors") == 0)
  16559. {
  16560. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16561. {
  16562. check_ascii = value[0];
  16563. if( (check_ascii < 48) || (check_ascii > 57) )
  16564. {
  16565. isSuccess = ConfigurationStatus_Rejected;
  16566. }
  16567. else
  16568. {
  16569. //Charger.ResetRetries = Integer.parseInt(value);
  16570. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16571. isSuccess = ConfigurationStatus_Accepted;
  16572. }
  16573. }
  16574. else
  16575. {
  16576. isSuccess = ConfigurationStatus_Rejected;
  16577. }
  16578. }
  16579. if(strcmp(key, "ResetRetries") == 0)
  16580. {
  16581. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16582. {
  16583. check_ascii = value[0];
  16584. if( (check_ascii < 48) || (check_ascii > 57) )
  16585. {
  16586. isSuccess = ConfigurationStatus_Rejected;
  16587. }
  16588. else
  16589. {
  16590. //Charger.ResetRetries = Integer.parseInt(value);
  16591. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16592. isSuccess = ConfigurationStatus_Accepted;
  16593. }
  16594. }
  16595. else
  16596. {
  16597. isSuccess = ConfigurationStatus_Rejected;
  16598. }
  16599. }
  16600. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16601. {
  16602. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16603. {
  16604. strcpy(str, (const char*)value);
  16605. for(int i = 0; str[i]; i++)
  16606. {
  16607. str[i] = tolower(str[i]);
  16608. }
  16609. if(strcmp(str, "notapplicable")== 0)
  16610. {
  16611. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16612. isSuccess = ConfigurationStatus_Accepted;
  16613. }
  16614. else if(strcmp(str, "unknown")== 0)
  16615. {
  16616. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16617. isSuccess = ConfigurationStatus_Accepted;
  16618. }
  16619. else if(strcmp(str, "rst")== 0)
  16620. {
  16621. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16622. isSuccess = ConfigurationStatus_Accepted;
  16623. }
  16624. else if(strcmp(str, "rts")== 0)
  16625. {
  16626. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16627. isSuccess = ConfigurationStatus_Accepted;
  16628. }
  16629. else if(strcmp(str, "srt")== 0)
  16630. {
  16631. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16632. isSuccess = ConfigurationStatus_Accepted;
  16633. }
  16634. else if(strcmp(str, "str")== 0)
  16635. {
  16636. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16637. isSuccess = ConfigurationStatus_Accepted;
  16638. }
  16639. else if(strcmp(str, "trs")== 0)
  16640. {
  16641. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16642. isSuccess = ConfigurationStatus_Accepted;
  16643. }
  16644. else if(strcmp(str, "tsr")== 0)
  16645. {
  16646. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16647. isSuccess = ConfigurationStatus_Accepted;
  16648. }
  16649. else
  16650. {
  16651. isSuccess = ConfigurationStatus_Rejected;
  16652. }
  16653. }
  16654. else
  16655. {
  16656. isSuccess = ConfigurationStatus_Rejected;
  16657. }
  16658. }
  16659. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16660. {
  16661. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16662. {
  16663. check_ascii = value[0];
  16664. if( (check_ascii < 48) || (check_ascii > 57) )
  16665. {
  16666. isSuccess = ConfigurationStatus_Rejected;
  16667. }
  16668. else
  16669. {
  16670. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16671. isSuccess = ConfigurationStatus_Accepted;
  16672. }
  16673. }
  16674. else
  16675. {
  16676. isSuccess = ConfigurationStatus_Rejected;
  16677. }
  16678. }
  16679. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16680. {
  16681. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16682. {
  16683. strcpy(str, (const char*)value);
  16684. for(int i = 0; str[i]; i++)
  16685. {
  16686. str[i] = tolower(str[i]);
  16687. }
  16688. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16689. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16690. isSuccess = ConfigurationStatus_Accepted;
  16691. }
  16692. else
  16693. {
  16694. isSuccess = ConfigurationStatus_Rejected;
  16695. }
  16696. }
  16697. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16698. {
  16699. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16700. {
  16701. strcpy(str, (const char*)value);
  16702. for(int i = 0; str[i]; i++)
  16703. {
  16704. str[i] = tolower(str[i]);
  16705. }
  16706. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16707. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16708. isSuccess = ConfigurationStatus_Accepted;
  16709. }
  16710. else
  16711. {
  16712. isSuccess = ConfigurationStatus_Rejected;
  16713. }
  16714. }
  16715. if(strcmp(key, "StopTxnAlignedData") == 0)
  16716. {
  16717. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16718. {
  16719. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16720. isSuccess = ConfigurationStatus_Accepted;
  16721. }
  16722. else
  16723. {
  16724. isSuccess = ConfigurationStatus_Rejected;
  16725. }
  16726. }
  16727. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16728. {
  16729. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16730. {
  16731. check_ascii = value[0];
  16732. if( (check_ascii < 48) || (check_ascii > 57) )
  16733. {
  16734. isSuccess = ConfigurationStatus_Rejected;
  16735. }
  16736. else
  16737. {
  16738. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16739. isSuccess = ConfigurationStatus_Accepted;
  16740. }
  16741. }
  16742. else
  16743. {
  16744. isSuccess = ConfigurationStatus_Rejected;
  16745. }
  16746. }
  16747. if(strcmp(key, "StopTxnSampledData") == 0)
  16748. {
  16749. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16750. {
  16751. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16752. isSuccess = ConfigurationStatus_Accepted;
  16753. }
  16754. else
  16755. {
  16756. isSuccess = ConfigurationStatus_Rejected;
  16757. }
  16758. }
  16759. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16760. {
  16761. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16762. {
  16763. check_ascii = value[0];
  16764. if( (check_ascii < 48) || (check_ascii > 57) )
  16765. {
  16766. isSuccess = ConfigurationStatus_Rejected;
  16767. }
  16768. else
  16769. {
  16770. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16771. isSuccess = ConfigurationStatus_Accepted;
  16772. }
  16773. }
  16774. else
  16775. {
  16776. isSuccess = ConfigurationStatus_Rejected;
  16777. }
  16778. }
  16779. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16780. {
  16781. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16782. {
  16783. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16784. isSuccess = ConfigurationStatus_Accepted;
  16785. }
  16786. else
  16787. {
  16788. isSuccess = ConfigurationStatus_Rejected;
  16789. }
  16790. }
  16791. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16792. {
  16793. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16794. {
  16795. check_ascii = value[0];
  16796. if( (check_ascii < 48) || (check_ascii > 57) )
  16797. {
  16798. isSuccess = ConfigurationStatus_Rejected;
  16799. }
  16800. else
  16801. {
  16802. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16803. isSuccess = ConfigurationStatus_Accepted;
  16804. }
  16805. }
  16806. else
  16807. {
  16808. isSuccess = ConfigurationStatus_Rejected;
  16809. }
  16810. }
  16811. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16812. {
  16813. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16814. {
  16815. check_ascii = value[0];
  16816. if( (check_ascii < 48) || (check_ascii > 57) )
  16817. {
  16818. isSuccess = ConfigurationStatus_Rejected;
  16819. }
  16820. else
  16821. {
  16822. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16823. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16824. TransactionMessageAttemptsValue = atoi(value);
  16825. isSuccess = ConfigurationStatus_Accepted;
  16826. }
  16827. }
  16828. else
  16829. {
  16830. isSuccess = ConfigurationStatus_Rejected;
  16831. }
  16832. }
  16833. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16834. {
  16835. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16836. {
  16837. check_ascii = value[0];
  16838. if( (check_ascii < 48) || (check_ascii > 57) )
  16839. {
  16840. isSuccess = ConfigurationStatus_Rejected;
  16841. }
  16842. else
  16843. {
  16844. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16845. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16846. TransactionMessageRetryIntervalValue = atoi(value);
  16847. isSuccess = ConfigurationStatus_Accepted;
  16848. }
  16849. }
  16850. else
  16851. {
  16852. isSuccess = ConfigurationStatus_Rejected;
  16853. }
  16854. }
  16855. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16856. {
  16857. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16858. {
  16859. strcpy(str, (const char*)value);
  16860. for(int i = 0; str[i]; i++)
  16861. {
  16862. str[i] = tolower(str[i]);
  16863. }
  16864. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16865. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16866. isSuccess = ConfigurationStatus_Accepted;
  16867. }
  16868. else
  16869. {
  16870. isSuccess = ConfigurationStatus_Rejected;
  16871. }
  16872. }
  16873. if(strcmp(key, "WebSocketPingInterval") == 0)
  16874. {
  16875. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16876. {
  16877. check_ascii = value[0];
  16878. if( (check_ascii < 48) || (check_ascii > 57) )
  16879. {
  16880. isSuccess = ConfigurationStatus_Rejected;
  16881. }
  16882. else
  16883. {
  16884. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16885. isSuccess = ConfigurationStatus_Accepted;
  16886. if((atoi(value) == 0) || (atoi(value) >= 10))
  16887. {
  16888. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16889. isSuccess = ConfigurationStatus_Accepted;
  16890. }
  16891. else
  16892. isSuccess = ConfigurationStatus_Rejected;
  16893. }
  16894. }
  16895. else
  16896. {
  16897. isSuccess = ConfigurationStatus_Rejected;
  16898. }
  16899. }
  16900. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16901. {
  16902. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16903. {
  16904. strcpy(str, (const char*)value);
  16905. for(int i = 0; str[i]; i++)
  16906. {
  16907. str[i] = tolower(str[i]);
  16908. }
  16909. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16910. isSuccess = ConfigurationStatus_Accepted;
  16911. }
  16912. else
  16913. {
  16914. isSuccess = ConfigurationStatus_Rejected;
  16915. }
  16916. }
  16917. if(strcmp(key, "AuthorizationKey") == 0)
  16918. {
  16919. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16920. {
  16921. strcpy(str, (const char*)value);
  16922. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16923. strcpy((char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16924. isSuccess = ConfigurationStatus_Accepted;
  16925. }
  16926. else
  16927. {
  16928. isSuccess = ConfigurationStatus_Rejected;
  16929. }
  16930. }
  16931. if(strcmp(key, "SecurityProfile") == 0)
  16932. {
  16933. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16934. {
  16935. check_ascii = value[0];
  16936. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16937. {
  16938. isSuccess = ConfigurationStatus_Rejected;
  16939. }
  16940. else if(check_ascii == 0x33)
  16941. {
  16942. isSuccess = NotSupported;
  16943. }
  16944. else
  16945. {
  16946. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16947. {
  16948. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16949. ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = atoi(value);
  16950. isSuccess = ConfigurationStatus_Accepted;
  16951. }
  16952. else
  16953. isSuccess = ConfigurationStatus_Rejected;
  16954. }
  16955. }
  16956. else
  16957. {
  16958. isSuccess = ConfigurationStatus_Rejected;
  16959. }
  16960. }
  16961. if(strcmp(key, "DefaultPrice") == 0)
  16962. {
  16963. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16964. {
  16965. strcpy(str, (const char*)value);
  16966. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16967. isSuccess = ConfigurationStatus_Accepted;
  16968. }
  16969. else
  16970. {
  16971. isSuccess = ConfigurationStatus_Rejected;
  16972. }
  16973. }
  16974. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16975. {
  16976. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16977. {
  16978. strcpy(str, (const char*)value);
  16979. for(int i = 0; str[i]; i++)
  16980. {
  16981. str[i] = tolower(str[i]);
  16982. }
  16983. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16984. isSuccess = ConfigurationStatus_Accepted;
  16985. }
  16986. else
  16987. {
  16988. isSuccess = ConfigurationStatus_Rejected;
  16989. }
  16990. }
  16991. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16992. {
  16993. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16994. {
  16995. strcpy(str, (const char*)value);
  16996. for(int i = 0; str[i]; i++)
  16997. {
  16998. str[i] = tolower(str[i]);
  16999. }
  17000. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17001. isSuccess = ConfigurationStatus_Accepted;
  17002. }
  17003. else
  17004. {
  17005. isSuccess = ConfigurationStatus_Rejected;
  17006. }
  17007. }
  17008. if(strcmp(key, "SystemUptimeSec") == 0)
  17009. {
  17010. isSuccess = NotSupported;
  17011. }
  17012. if(strcmp(key, "FreeVend") == 0)
  17013. {
  17014. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17015. {
  17016. strcpy(str, (const char*)value);
  17017. for(int i = 0; str[i]; i++)
  17018. {
  17019. str[i] = tolower(str[i]);
  17020. }
  17021. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  17022. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17023. isSuccess = ConfigurationStatus_Accepted;
  17024. }
  17025. else
  17026. {
  17027. isSuccess = ConfigurationStatus_Rejected;
  17028. }
  17029. }
  17030. if(strcmp(key, "FreeVendIdtag") == 0)
  17031. {
  17032. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17033. {
  17034. strcpy(str, (const char*)value);
  17035. if(strlen(str) <= 20)
  17036. {
  17037. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  17038. isSuccess = ConfigurationStatus_Accepted;
  17039. }
  17040. else
  17041. {
  17042. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  17043. isSuccess = ConfigurationStatus_Rejected;
  17044. }
  17045. }
  17046. else
  17047. {
  17048. isSuccess = ConfigurationStatus_Rejected;
  17049. }
  17050. }
  17051. if(strcmp(key, "OcppServer") == 0)
  17052. {
  17053. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17054. {
  17055. strcpy(str, (const char*)value);
  17056. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  17057. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  17058. isSuccess = ConfigurationStatus_Accepted;
  17059. }
  17060. else
  17061. {
  17062. isSuccess = ConfigurationStatus_Rejected;
  17063. }
  17064. }
  17065. if(strcmp(key, "MaintainServer") == 0)
  17066. {
  17067. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17068. {
  17069. strcpy(str, (const char*)value);
  17070. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  17071. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  17072. isSuccess = ConfigurationStatus_Accepted;
  17073. }
  17074. else
  17075. {
  17076. isSuccess = ConfigurationStatus_Rejected;
  17077. }
  17078. }
  17079. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  17080. {
  17081. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17082. {
  17083. strcpy(str, (const char*)value);
  17084. for(int i = 0; str[i]; i++)
  17085. {
  17086. str[i] = tolower(str[i]);
  17087. }
  17088. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  17089. isSuccess = ConfigurationStatus_Accepted;
  17090. }
  17091. else
  17092. {
  17093. isSuccess = ConfigurationStatus_Rejected;
  17094. }
  17095. }
  17096. if(strcmp(key, "StatusNotificationInterval") == 0)
  17097. {
  17098. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17099. {
  17100. check_ascii = value[0];
  17101. if( (check_ascii < 48) || (check_ascii > 57) )
  17102. {
  17103. isSuccess = ConfigurationStatus_Rejected;
  17104. }
  17105. else
  17106. {
  17107. if((atoi(value) == 0) || (atoi(value) >= 10))
  17108. {
  17109. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  17110. isSuccess = ConfigurationStatus_Accepted;
  17111. }
  17112. else
  17113. isSuccess = ConfigurationStatus_Rejected;
  17114. }
  17115. }
  17116. else
  17117. {
  17118. isSuccess = ConfigurationStatus_Rejected;
  17119. }
  17120. }
  17121. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  17122. {
  17123. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  17124. {
  17125. check_ascii = value[0];
  17126. if( (check_ascii < 48) || (check_ascii > 57) )
  17127. {
  17128. isSuccess = ConfigurationStatus_Rejected;
  17129. }
  17130. else
  17131. {
  17132. if(atoi(value) >= 0)
  17133. {
  17134. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value) );
  17135. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  17136. isSuccess = ConfigurationStatus_Accepted;
  17137. }
  17138. else
  17139. isSuccess = ConfigurationStatus_Rejected;
  17140. }
  17141. }
  17142. else
  17143. {
  17144. isSuccess = ConfigurationStatus_Rejected;
  17145. }
  17146. }
  17147. if(strcmp(key, "PowerSharingServerIP") == 0)
  17148. {
  17149. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  17150. {
  17151. strcpy(str, (const char*)value);
  17152. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  17153. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  17154. isSuccess = ConfigurationStatus_Accepted;
  17155. }
  17156. else
  17157. {
  17158. isSuccess = ConfigurationStatus_Rejected;
  17159. }
  17160. }
  17161. if(strcmp(key, "EVCCID_PREFIX") == 0)
  17162. {
  17163. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  17164. {
  17165. strcpy(str, (const char*)value);
  17166. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  17167. isSuccess = ConfigurationStatus_Accepted;
  17168. }
  17169. else
  17170. {
  17171. isSuccess = ConfigurationStatus_Rejected;
  17172. }
  17173. }
  17174. if(strcmp(key, "OffLineMaxChargingPower") == 0)
  17175. {
  17176. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  17177. {
  17178. strcpy(str, (const char*)value);
  17179. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", str );
  17180. isSuccess = ConfigurationStatus_Accepted;
  17181. }
  17182. else
  17183. {
  17184. isSuccess = ConfigurationStatus_Rejected;
  17185. }
  17186. }
  17187. #if 0
  17188. //For OCPP Test Case
  17189. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  17190. {
  17191. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17192. {
  17193. strcpy(str, (const char*)value);
  17194. for(int i = 0; str[i]; i++)
  17195. {
  17196. str[i] = tolower(str[i]);
  17197. }
  17198. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17199. isSuccess = ConfigurationStatus_Accepted;
  17200. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17201. }
  17202. else
  17203. {
  17204. isSuccess = ConfigurationStatus_Rejected;
  17205. }
  17206. }
  17207. #endif
  17208. #if 1
  17209. if(strcmp(key, "LocalAuthListEnabled") == 0)
  17210. {
  17211. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17212. {
  17213. strcpy(str, (const char*)value);
  17214. for(int i = 0; str[i]; i++)
  17215. {
  17216. str[i] = tolower(str[i]);
  17217. }
  17218. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17219. isSuccess = ConfigurationStatus_Accepted;
  17220. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17221. }
  17222. else
  17223. {
  17224. isSuccess = ConfigurationStatus_Rejected;
  17225. }
  17226. }
  17227. #endif
  17228. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  17229. {
  17230. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  17231. {
  17232. check_ascii = value[0];
  17233. if( (check_ascii < 48) || (check_ascii > 57) )
  17234. {
  17235. isSuccess = ConfigurationStatus_Rejected;
  17236. }
  17237. else
  17238. {
  17239. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  17240. isSuccess = ConfigurationStatus_Accepted;
  17241. }
  17242. }
  17243. else
  17244. {
  17245. isSuccess = ConfigurationStatus_Rejected;
  17246. }
  17247. }
  17248. if(strcmp(key, "SendLocalListMaxLength") == 0)
  17249. {
  17250. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17251. {
  17252. check_ascii = value[0];
  17253. if( (check_ascii < 48) || (check_ascii > 57) )
  17254. {
  17255. isSuccess = ConfigurationStatus_Rejected;
  17256. }
  17257. else
  17258. {
  17259. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  17260. isSuccess = ConfigurationStatus_Accepted;
  17261. }
  17262. }
  17263. else
  17264. {
  17265. isSuccess = ConfigurationStatus_Rejected;
  17266. }
  17267. }
  17268. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  17269. {
  17270. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17271. {
  17272. strcpy(str, (const char*)value);
  17273. for(int i = 0; str[i]; i++)
  17274. {
  17275. str[i] = tolower(str[i]);
  17276. }
  17277. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17278. isSuccess = ConfigurationStatus_Accepted;
  17279. }
  17280. else
  17281. {
  17282. isSuccess = ConfigurationStatus_Rejected;
  17283. }
  17284. }
  17285. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  17286. {
  17287. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17288. {
  17289. check_ascii = value[0];
  17290. if( (check_ascii < 48) || (check_ascii > 57) )
  17291. {
  17292. isSuccess = ConfigurationStatus_Rejected;
  17293. }
  17294. else
  17295. {
  17296. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  17297. isSuccess = ConfigurationStatus_Accepted;
  17298. }
  17299. }
  17300. else
  17301. {
  17302. isSuccess = ConfigurationStatus_Rejected;
  17303. }
  17304. }
  17305. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  17306. {
  17307. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17308. {
  17309. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  17310. isSuccess = ConfigurationStatus_Accepted;
  17311. }
  17312. else
  17313. {
  17314. isSuccess = ConfigurationStatus_Rejected;
  17315. }
  17316. }
  17317. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  17318. {
  17319. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17320. {
  17321. check_ascii = value[0];
  17322. if( (check_ascii < 48) || (check_ascii > 57) )
  17323. {
  17324. isSuccess = ConfigurationStatus_Rejected;
  17325. }
  17326. else
  17327. {
  17328. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  17329. isSuccess = ConfigurationStatus_Accepted;
  17330. }
  17331. }
  17332. else
  17333. {
  17334. isSuccess = ConfigurationStatus_Rejected;
  17335. }
  17336. }
  17337. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  17338. {
  17339. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17340. {
  17341. strcpy(str, (const char*)value);
  17342. for(int i = 0; str[i]; i++)
  17343. {
  17344. str[i] = tolower(str[i]);
  17345. }
  17346. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17347. isSuccess = ConfigurationStatus_Accepted;
  17348. }
  17349. else
  17350. {
  17351. isSuccess = ConfigurationStatus_Rejected;
  17352. }
  17353. }
  17354. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  17355. {
  17356. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  17357. {
  17358. check_ascii = value[0];
  17359. if( (check_ascii < 48) || (check_ascii > 57) )
  17360. {
  17361. isSuccess = ConfigurationStatus_Rejected;
  17362. }
  17363. else
  17364. {
  17365. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  17366. isSuccess = ConfigurationStatus_Accepted;
  17367. }
  17368. }
  17369. else
  17370. {
  17371. isSuccess = ConfigurationStatus_Rejected;
  17372. }
  17373. }
  17374. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17375. return isSuccess;
  17376. }
  17377. int TransactionMessageAttemptsGet(void)
  17378. {
  17379. return TransactionMessageAttemptsValue;
  17380. }
  17381. int FirstHeartBeatResponse(void)
  17382. {
  17383. return FirstHeartBeat;
  17384. }
  17385. int TransactionMessageRetryIntervalGet(void)
  17386. {
  17387. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17388. }
  17389. int ReadHttpStatus(int sock)
  17390. {
  17391. //char c;
  17392. char buff[1024]="",*ptr=buff+1;
  17393. int bytes_received, status;
  17394. DEBUG_INFO("Begin Response ..\n");
  17395. while((bytes_received = recv(sock, ptr, 1, 0))){
  17396. if(bytes_received==-1){
  17397. perror("ReadHttpStatus");
  17398. exit(1);
  17399. }
  17400. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  17401. ptr++;
  17402. }
  17403. *ptr=0;
  17404. ptr=buff+1;
  17405. sscanf(ptr,"%*s %d ", &status);
  17406. DEBUG_INFO("%s\n",ptr);
  17407. DEBUG_INFO("status=%d\n",status);
  17408. DEBUG_INFO("End Response ..\n");
  17409. return (bytes_received>0)?status:0;
  17410. }
  17411. //the only filed that it parsed is 'Content-Length'
  17412. int ParseHeader(int sock)
  17413. {
  17414. //char c;
  17415. char buff[1024]="",*ptr=buff+4;
  17416. int bytes_received;
  17417. DEBUG_INFO("Begin HEADER ..\n");
  17418. while((bytes_received = recv(sock, ptr, 1, 0))){
  17419. if(bytes_received==-1){
  17420. perror("Parse Header");
  17421. exit(1);
  17422. }
  17423. if(
  17424. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  17425. (ptr[-1]=='\r') && (*ptr=='\n' )
  17426. ) break;
  17427. ptr++;
  17428. }
  17429. *ptr=0;
  17430. ptr=buff+4;
  17431. //printf("%s",ptr);
  17432. if(bytes_received){
  17433. ptr=strstr(ptr,"Content-Length:");
  17434. if(ptr){
  17435. sscanf(ptr,"%*s %d",&bytes_received);
  17436. }else
  17437. bytes_received=-1; //unknown size
  17438. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  17439. }
  17440. DEBUG_INFO("End HEADER ..\n");
  17441. return bytes_received ;
  17442. }
  17443. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  17444. {
  17445. int result = TRUE;
  17446. char rmFileCmd[100]={0};
  17447. char FilePath[100]={0};
  17448. char ftpbuf[200];
  17449. int systemresult;
  17450. sprintf(FilePath,"/mnt/%s",filename);
  17451. system("ping 8.8.8.8 &");
  17452. if((access(FilePath,F_OK))!=-1)
  17453. {
  17454. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17455. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17456. system(rmFileCmd);
  17457. }
  17458. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17459. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  17460. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17461. systemresult = system(ftpbuf);
  17462. if(systemresult != 0)
  17463. {
  17464. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  17465. result = FALSE;
  17466. }
  17467. system("pkill ping");
  17468. return result;
  17469. }
  17470. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  17471. {
  17472. int result = TRUE;
  17473. char rmFileCmd[100]={0};
  17474. char FilePath[100]={0};
  17475. char ftpbuf[200];
  17476. int systemresult;
  17477. sprintf(FilePath,"/mnt/%s",filename);
  17478. system("ping 8.8.8.8 &");
  17479. if((access(FilePath,F_OK))!=-1)
  17480. {
  17481. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17482. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17483. system(rmFileCmd);
  17484. }
  17485. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17486. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  17487. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17488. systemresult = system(ftpbuf);
  17489. if(systemresult != 0)
  17490. {
  17491. DEBUG_WARN("scp error!\n");
  17492. result = FALSE;
  17493. }
  17494. system("pkill ping");
  17495. return result;
  17496. }
  17497. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  17498. {
  17499. int result = TRUE;
  17500. char rmFileCmd[100]={0};
  17501. char FilePath[100]={0};
  17502. char ftpbuf[200];
  17503. int systemresult;
  17504. sprintf(FilePath,"/mnt/%s",filename);
  17505. system("ping 8.8.8.8 &");
  17506. if((access(FilePath,F_OK))!=-1)
  17507. {
  17508. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17509. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17510. system(rmFileCmd);
  17511. }
  17512. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17513. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  17514. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17515. systemresult = system(ftpbuf);
  17516. if(systemresult != 0)
  17517. {
  17518. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  17519. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17520. systemresult = system(ftpbuf);
  17521. if(systemresult != 0)
  17522. {
  17523. DEBUG_WARN("FTP download fail!\n");
  17524. result = FALSE;
  17525. }
  17526. }
  17527. system("pkill ping");
  17528. return result;
  17529. }
  17530. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17531. {
  17532. char rmFileCmd[100]={0};
  17533. char FilePath[100]={0};
  17534. char buf[512];
  17535. int systemresult = 0;
  17536. //DEBUG_INFO("filename=%s\n",filename);
  17537. //DEBUG_INFO("url=%s\n",url);
  17538. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17539. if((access(FilePath,F_OK))!=-1)
  17540. {
  17541. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17542. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17543. system(rmFileCmd);
  17544. }
  17545. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17546. if(fp == NULL)
  17547. {
  17548. DEBUG_INFO("log is NULL\n");
  17549. return FALSE;
  17550. }
  17551. else
  17552. {
  17553. fprintf(fp, "%s\n", url);
  17554. fprintf(fp, "%s\n", filename);
  17555. fclose(fp);
  17556. }
  17557. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  17558. if(phpFP == NULL)
  17559. {
  17560. DEBUG_INFO("PHP upload fail.\n");
  17561. return FALSE;
  17562. }
  17563. else
  17564. {
  17565. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17566. {
  17567. if(strstr(buf, "result") != NULL)
  17568. {
  17569. sscanf(buf, "result: %d", &systemresult);
  17570. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17571. }
  17572. }
  17573. pclose(phpFP);
  17574. }
  17575. if(systemresult != 1)
  17576. {
  17577. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  17578. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  17579. if(phpFP == NULL)
  17580. {
  17581. DEBUG_WARN("PHP PUT upload fail.\n");
  17582. return FALSE;
  17583. }
  17584. else
  17585. {
  17586. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17587. {
  17588. if(strstr(buf, "result") != NULL)
  17589. {
  17590. sscanf(buf, "result: %d", &systemresult);
  17591. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  17592. }
  17593. }
  17594. pclose(phpFP);
  17595. }
  17596. }
  17597. if(systemresult != 1)
  17598. {
  17599. DEBUG_WARN("PHP PUT upload fail.\n");
  17600. return FALSE;
  17601. }
  17602. return TRUE;
  17603. }
  17604. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17605. {
  17606. int result = FALSE;
  17607. char ftpbuf[200];
  17608. int systemresult;
  17609. /*
  17610. // Domaind name transfer to IP address
  17611. struct hostent* server;
  17612. char *IPbuffer;
  17613. server = gethostbyname(location);
  17614. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17615. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17616. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17617. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  17618. systemresult = system(ftpbuf);
  17619. if(systemresult != 0)
  17620. {
  17621. DEBUG_INFO("ftpput error!\n");
  17622. }
  17623. else
  17624. {
  17625. result = TRUE;
  17626. DEBUG_INFO("ftpput OK!\n");
  17627. }
  17628. return result;
  17629. }
  17630. int GetOcppServerURL()
  17631. {
  17632. int result = FALSE;
  17633. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  17634. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  17635. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  17636. struct yuarel url;
  17637. char urlStr[512];
  17638. // OCPPPH only
  17639. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  17640. if((ShmSysConfigAndInfo->SysConfig.MaintainServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) )
  17641. {
  17642. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  17643. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17644. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17645. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.MaintainServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  17646. if(yuarel_parse(&url, urlStr) != -1)
  17647. {
  17648. sprintf(OcppProtocol, "%s", url.scheme);
  17649. sprintf(OcppHost, "%s", url.host);
  17650. if(url.path == NULL)
  17651. OcppTempPath[0] = '\0';
  17652. else
  17653. sprintf(OcppTempPath, "%s", url.path);
  17654. if(url.port == 0)
  17655. {
  17656. if(strcmp(OcppProtocol, "wss") == 0)
  17657. OcppPort = 443;
  17658. else
  17659. OcppPort = 80;
  17660. }
  17661. else
  17662. OcppPort = url.port;
  17663. result = TRUE;
  17664. }
  17665. }
  17666. else
  17667. {
  17668. strcpy(OcppHost,"");
  17669. }
  17670. return result;
  17671. }
  17672. int GetOcppPath()
  17673. {
  17674. int result = FALSE;
  17675. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  17676. {
  17677. if(OcppTempPath == NULL)
  17678. {
  17679. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  17680. }
  17681. else
  17682. {
  17683. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  17684. }
  17685. result = TRUE;
  17686. goto End;
  17687. }
  17688. else
  17689. {
  17690. strcpy(OcppPath,"");
  17691. }
  17692. End:
  17693. return result;
  17694. }
  17695. int GetOcppPort()
  17696. {
  17697. return OcppPort;
  17698. }
  17699. int GetOcppConnStatus(void)
  17700. {
  17701. return ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus;
  17702. }
  17703. void SetOcppConnStatus(uint8_t status)
  17704. {
  17705. ShmOCPP16DataPH->OcppConnStatus = status;
  17706. ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus = status;
  17707. }
  17708. int GetHeartBeatWithNOResponse(void)
  17709. {
  17710. return HeartBeatWithNOResponse;
  17711. }
  17712. void SetHeartBeatWithNOResponse(void)
  17713. {
  17714. HeartBeatWithNOResponse = 0;
  17715. }
  17716. void GetStartTransactionIdTag(int gun_index)
  17717. {
  17718. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17719. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  17720. }
  17721. int GetStartTransactionId(int gun_index)
  17722. {
  17723. return ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  17724. }
  17725. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17726. {
  17727. char ch;
  17728. FILE *fptr1;
  17729. int temptransactionId;
  17730. char str[100]={0};
  17731. temptransactionId = 0;
  17732. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17733. {
  17734. DEBUG_INFO("IdTag is empty.\n");
  17735. return temptransactionId;
  17736. }
  17737. /*------ Read the file ----------------*/
  17738. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  17739. if (!fptr1)
  17740. {
  17741. DEBUG_INFO("QueueTransactionId file open error.\n");
  17742. //printf(" File not found or unable to open the input file!!\n");
  17743. return temptransactionId;
  17744. }
  17745. ch=fgetc(fptr1);
  17746. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  17747. rewind(fptr1);
  17748. if(ch!=EOF)
  17749. {
  17750. // printf("%c",ch);
  17751. while (fgets(str, 100, fptr1) != NULL)
  17752. {
  17753. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17754. if(str[0]=='\0')
  17755. {
  17756. break;
  17757. }
  17758. char *revbuf[8] = {0}; // Variable store string split
  17759. int num = 0;// Quantity after string split
  17760. DEBUG_INFO("Transaction queue data= %s\n", str);
  17761. splitstring(str,",",revbuf,&num); // String split
  17762. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17763. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17764. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17765. DEBUG_INFO("------------------------------\n");
  17766. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17767. {
  17768. if(isStopTransaction)
  17769. {
  17770. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17771. {
  17772. temptransactionId = atoi(revbuf[2]);
  17773. //break;
  17774. }
  17775. }
  17776. else
  17777. {
  17778. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17779. {
  17780. temptransactionId = atoi(revbuf[2]);
  17781. //break;
  17782. }
  17783. }
  17784. }
  17785. }
  17786. }
  17787. else
  17788. DEBUG_INFO("EOF\n");
  17789. fclose(fptr1);
  17790. /*------- End of reading ---------------*/
  17791. return temptransactionId;
  17792. }
  17793. void SetTransactionIdZero(int transactionId)
  17794. {
  17795. char ch;
  17796. FILE *fptr1, *fptr2;
  17797. int temptransactionId = 0;
  17798. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  17799. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  17800. if (!fptr1)
  17801. {
  17802. //printf(" File not found or unable to open the input file!!\n");
  17803. return ;
  17804. }
  17805. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17806. if (!fptr2)
  17807. {
  17808. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17809. fclose(fptr1);
  17810. return ;
  17811. }
  17812. ch=fgetc(fptr1);
  17813. rewind(fptr1);
  17814. if(ch!=EOF)
  17815. {
  17816. // copy all contents to the temporary file except the specific line
  17817. while (fgets(str, 100, fptr1) != NULL)
  17818. {
  17819. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17820. if(str[0]=='\0')
  17821. {
  17822. break;
  17823. }
  17824. char *revbuf[8] = {0};
  17825. int num = 0;
  17826. strcpy(strtemp, str);
  17827. splitstring(str,",",revbuf,&num);
  17828. if(revbuf[2][0] != '\0')
  17829. {
  17830. temptransactionId = atoi(revbuf[2]);
  17831. if(transactionId != temptransactionId)
  17832. {
  17833. fprintf(fptr2, "%s\n", strtemp);
  17834. }
  17835. }
  17836. }
  17837. }
  17838. fclose(fptr1);
  17839. fclose(fptr2);
  17840. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  17841. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  17842. /*------ Read the file ----------------*/
  17843. }
  17844. int InternetDisconnect(void)
  17845. {
  17846. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  17847. }
  17848. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17849. void storeTempStopTransaction(int gun_index)
  17850. {
  17851. char guid[37]={0};
  17852. int tempIndex = 0;
  17853. char TempStopTransaction[256];
  17854. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17855. DEBUG_INFO("storeTempStopTransaction...\n");
  17856. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  17857. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  17858. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  17859. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17860. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17861. {
  17862. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17863. {
  17864. tempIndex = ((gun_index==2) ? 1: 0);
  17865. }
  17866. else
  17867. {
  17868. tempIndex = gun_index;
  17869. }
  17870. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17871. {
  17872. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17873. {
  17874. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  17875. }
  17876. }// END OF CHAdeMO_QUANTITY
  17877. }
  17878. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17879. {
  17880. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17881. {
  17882. tempIndex = ((gun_index==2) ? 1: 0);
  17883. }
  17884. else
  17885. {
  17886. tempIndex = gun_index;
  17887. }
  17888. for (int index = 0; index < CCS_QUANTITY; index++)
  17889. {
  17890. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17891. {
  17892. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  17893. }
  17894. }// END OF CCS_QUANTITY
  17895. }
  17896. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17897. {
  17898. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17899. {
  17900. tempIndex = ((gun_index==2) ? 1: 0);
  17901. }
  17902. else
  17903. {
  17904. tempIndex = gun_index;
  17905. }
  17906. for (int index = 0; index < GB_QUANTITY; index++)
  17907. {
  17908. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17909. {
  17910. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17911. }
  17912. }// END OF GB_QUANTITY
  17913. }
  17914. else if(gunType[gun_index] == GUN_TYPE_DO)
  17915. {
  17916. tempIndex = gun_index;
  17917. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17918. {
  17919. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17920. {
  17921. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17922. }
  17923. }
  17924. }
  17925. else
  17926. {
  17927. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17928. {
  17929. tempIndex = 2;
  17930. }
  17931. else
  17932. {
  17933. tempIndex = gun_index;
  17934. }
  17935. for (int index = 0; index < AC_QUANTITY; index++)
  17936. {
  17937. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17938. {
  17939. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17940. }
  17941. }// END OF AC_QUANTITY
  17942. }
  17943. //Stop Transaction Time
  17944. struct timeval tmnow;
  17945. struct tm *tm;
  17946. char buf[28];//, usec_buf[6];
  17947. gettimeofday(&tmnow, NULL);
  17948. time_t t;
  17949. t = time(NULL);
  17950. /*UTC time and date*/
  17951. tm = gmtime(&t);
  17952. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17953. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  17954. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  17955. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  17956. random_uuid(guid);
  17957. /***********************************transactionData******************************************************/
  17958. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17959. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17960. //=================================
  17961. //1. Transaction_Begin
  17962. //=================================
  17963. //============================== Energy.Active.Import.Interval ===========================================
  17964. //=================================
  17965. //2. Transaction_End
  17966. //=================================
  17967. //2.1====================================== Current.Import L1 ==============================================
  17968. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17969. {
  17970. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17971. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17972. {
  17973. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17974. {
  17975. tempIndex = ((gun_index==2) ? 1: 0);
  17976. }
  17977. else
  17978. {
  17979. tempIndex = gun_index;
  17980. }
  17981. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17982. {
  17983. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17984. {
  17985. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17986. }
  17987. }// End of for CHAdeMO_QUANTITY
  17988. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17989. }
  17990. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17991. {
  17992. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17993. {
  17994. tempIndex = ((gun_index==2) ? 1: 0);
  17995. }
  17996. else
  17997. {
  17998. tempIndex = gun_index;
  17999. }
  18000. for (int index = 0; index < CCS_QUANTITY; index++)
  18001. {
  18002. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18003. {
  18004. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18005. }
  18006. }// End of for CCS_QUANTITY
  18007. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18008. }
  18009. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18010. {
  18011. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18012. {
  18013. tempIndex = ((gun_index==2) ? 1: 0);
  18014. }
  18015. else
  18016. {
  18017. tempIndex = gun_index;
  18018. }
  18019. for (int index = 0; index < GB_QUANTITY; index++)
  18020. {
  18021. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18022. {
  18023. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18024. }
  18025. }// End of for GB_QUANTITY
  18026. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18027. }
  18028. else if(gunType[gun_index] == GUN_TYPE_DO)
  18029. {
  18030. tempIndex = gun_index;
  18031. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18032. {
  18033. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18034. {
  18035. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18036. }
  18037. }
  18038. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18039. }
  18040. else
  18041. {
  18042. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18043. {
  18044. tempIndex = 2;
  18045. }
  18046. else
  18047. {
  18048. tempIndex = gun_index;
  18049. }
  18050. for (int index = 0; index < AC_QUANTITY; index++)
  18051. {
  18052. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18053. {
  18054. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  18055. }
  18056. }// End of for AC_QUANTITY
  18057. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18058. }
  18059. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18060. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  18061. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  18062. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18063. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  18064. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18065. }
  18066. //2.2===================================== Energy.Active.Import.Interval ==========================================
  18067. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  18068. {
  18069. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18070. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18071. {
  18072. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18073. {
  18074. tempIndex = ((gun_index==2) ? 1: 0);
  18075. }
  18076. else
  18077. {
  18078. tempIndex = gun_index;
  18079. }
  18080. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18081. {
  18082. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18083. {
  18084. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  18085. }
  18086. }// END OF CHAdeMO_QUANTITY
  18087. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18088. }
  18089. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18090. {
  18091. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18092. {
  18093. tempIndex = ((gun_index==2) ? 1: 0);
  18094. }
  18095. else
  18096. {
  18097. tempIndex = gun_index;
  18098. }
  18099. for (int index = 0; index < CCS_QUANTITY; index++)
  18100. {
  18101. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18102. {
  18103. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  18104. }
  18105. }// END OF CCS_QUANTITY
  18106. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18107. }
  18108. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18109. {
  18110. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18111. {
  18112. tempIndex = ((gun_index==2) ? 1: 0);
  18113. }
  18114. else
  18115. {
  18116. tempIndex = gun_index;
  18117. }
  18118. for (int index = 0; index < GB_QUANTITY; index++)
  18119. {
  18120. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18121. {
  18122. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  18123. }
  18124. }// END OF GB_QUANTITY
  18125. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18126. }
  18127. else if(gunType[gun_index] == GUN_TYPE_DO)
  18128. {
  18129. tempIndex = gun_index;
  18130. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18131. {
  18132. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18133. {
  18134. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  18135. }
  18136. }
  18137. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18138. }
  18139. else
  18140. {
  18141. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18142. {
  18143. tempIndex = 2;
  18144. }
  18145. else
  18146. {
  18147. tempIndex = gun_index;
  18148. }
  18149. for (int index = 0; index < AC_QUANTITY; index++)
  18150. {
  18151. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18152. {
  18153. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  18154. }
  18155. }// END OF AC_QUANTITY
  18156. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18157. }
  18158. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18159. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  18160. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  18161. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18162. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  18163. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  18164. }
  18165. //2.3====================================== Power.Active.Import =========================================
  18166. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  18167. {
  18168. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18169. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18170. {
  18171. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18172. {
  18173. tempIndex = ((gun_index==2) ? 1: 0);
  18174. }
  18175. else
  18176. {
  18177. tempIndex = gun_index;
  18178. }
  18179. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18180. {
  18181. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18182. {
  18183. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18184. }
  18185. } // End for CHAdeMO_QUANTITY
  18186. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18187. }
  18188. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18189. {
  18190. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18191. {
  18192. tempIndex = ((gun_index==2) ? 1: 0);
  18193. }
  18194. else
  18195. {
  18196. tempIndex = gun_index;
  18197. }
  18198. for (int index = 0; index < CCS_QUANTITY; index++)
  18199. {
  18200. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18201. {
  18202. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18203. }
  18204. } // END for CCS_QUANTITY
  18205. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18206. }
  18207. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18208. {
  18209. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18210. {
  18211. tempIndex = ((gun_index==2) ? 1: 0);
  18212. }
  18213. else
  18214. {
  18215. tempIndex = gun_index;
  18216. }
  18217. for (int index = 0; index < GB_QUANTITY; index++)
  18218. {
  18219. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18220. {
  18221. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18222. }
  18223. }// END for GB_QUANTITY
  18224. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18225. }
  18226. else if(gunType[gun_index] == GUN_TYPE_DO)
  18227. {
  18228. tempIndex = gun_index;
  18229. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18230. {
  18231. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18232. {
  18233. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18234. }
  18235. }
  18236. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18237. }
  18238. else
  18239. {
  18240. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18241. {
  18242. tempIndex = 2;
  18243. }
  18244. else
  18245. {
  18246. tempIndex = gun_index;
  18247. }
  18248. for (int index = 0; index < AC_QUANTITY; index++)
  18249. {
  18250. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18251. {
  18252. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18253. }
  18254. } // END for AC_QUANTITY
  18255. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18256. }
  18257. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18258. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  18259. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  18260. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18261. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  18262. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  18263. }
  18264. //2.4====================================== Voltage L1 ====================================================
  18265. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18266. {
  18267. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18268. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18269. {
  18270. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18271. {
  18272. tempIndex = ((gun_index==2) ? 1: 0);
  18273. }
  18274. else
  18275. {
  18276. tempIndex = gun_index;
  18277. }
  18278. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18279. {
  18280. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18281. {
  18282. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18283. }
  18284. } // END OF FOR CHAdeMO_QUANTITY
  18285. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18286. }
  18287. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18288. {
  18289. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18290. {
  18291. tempIndex = ((gun_index==2) ? 1: 0);
  18292. }
  18293. else
  18294. {
  18295. tempIndex = gun_index;
  18296. }
  18297. for (int index = 0; index < CCS_QUANTITY; index++)
  18298. {
  18299. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18300. {
  18301. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18302. }
  18303. } // END OF FOR CCS_QUANTITY
  18304. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18305. }
  18306. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18307. {
  18308. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18309. {
  18310. tempIndex = ((gun_index==2) ? 1: 0);
  18311. }
  18312. else
  18313. {
  18314. tempIndex = gun_index;
  18315. }
  18316. for (int index = 0; index < GB_QUANTITY; index++)
  18317. {
  18318. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18319. {
  18320. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18321. }
  18322. } // END OF FOR GB_QUANTITY
  18323. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18324. }
  18325. else if(gunType[gun_index] == GUN_TYPE_DO)
  18326. {
  18327. tempIndex = gun_index;
  18328. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18329. {
  18330. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18331. {
  18332. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18333. }
  18334. }
  18335. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18336. }
  18337. else
  18338. {
  18339. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18340. {
  18341. tempIndex = 2;
  18342. }
  18343. else
  18344. {
  18345. tempIndex = gun_index;
  18346. }
  18347. for (int index = 0; index < AC_QUANTITY; index++)
  18348. {
  18349. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18350. {
  18351. 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
  18352. }
  18353. } // END OF FOR AC_QUANTITY
  18354. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18355. }
  18356. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18357. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  18358. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  18359. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18360. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  18361. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18362. }
  18363. //2.5============================================== End SoC =========================================================
  18364. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18365. {
  18366. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18367. 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))
  18368. {
  18369. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18370. {
  18371. tempIndex = ((gun_index==2) ? 1: 0);
  18372. }
  18373. else
  18374. {
  18375. tempIndex = gun_index;
  18376. }
  18377. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18378. {
  18379. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18380. {
  18381. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18382. {
  18383. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  18384. }
  18385. }
  18386. }
  18387. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18388. {
  18389. for (int index = 0; index < CCS_QUANTITY; index++)
  18390. {
  18391. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18392. {
  18393. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  18394. }
  18395. }
  18396. }
  18397. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18398. {
  18399. for (int index = 0; index < GB_QUANTITY; index++)
  18400. {
  18401. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18402. {
  18403. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  18404. }
  18405. }
  18406. }
  18407. else if(gunType[gun_index] == GUN_TYPE_DO)
  18408. {
  18409. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18410. {
  18411. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18412. {
  18413. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  18414. }
  18415. }
  18416. }
  18417. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18418. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  18419. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18420. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  18421. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  18422. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18423. } // END FOR DC CASE
  18424. }
  18425. //2.6====================================== Current.Import L2 ==============================================
  18426. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18427. {
  18428. // AC 3 phase L2 current
  18429. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18430. {
  18431. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18432. {
  18433. tempIndex = 2;
  18434. }
  18435. else
  18436. {
  18437. tempIndex = gun_index;
  18438. }
  18439. for (int index = 0; index < AC_QUANTITY; index++)
  18440. {
  18441. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18442. {
  18443. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  18444. }
  18445. }// End of for AC_QUANTITY
  18446. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  18447. }
  18448. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18449. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  18450. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  18451. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  18452. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18453. }
  18454. //2.7====================================== Current.Import L3 ==============================================
  18455. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18456. {
  18457. // AC 3 phase L3 current
  18458. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18459. {
  18460. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18461. {
  18462. tempIndex = 2;
  18463. }
  18464. else
  18465. {
  18466. tempIndex = gun_index;
  18467. }
  18468. for (int index = 0; index < AC_QUANTITY; index++)
  18469. {
  18470. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18471. {
  18472. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  18473. }
  18474. }// End of for AC_QUANTITY
  18475. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  18476. }
  18477. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18478. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  18479. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  18480. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  18481. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18482. }
  18483. //2.9====================================== Voltage L2 ====================================================
  18484. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18485. {
  18486. // AC 3 phase L2 volatge
  18487. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18488. {
  18489. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18490. {
  18491. tempIndex = 2;
  18492. }
  18493. else
  18494. {
  18495. tempIndex = gun_index;
  18496. }
  18497. for (int index = 0; index < AC_QUANTITY; index++)
  18498. {
  18499. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18500. {
  18501. 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
  18502. }
  18503. } // END OF FOR AC_QUANTITY
  18504. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  18505. }
  18506. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18507. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  18508. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  18509. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  18510. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18511. }
  18512. //2.10====================================== Voltage L3 ====================================================
  18513. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18514. {
  18515. // AC 3 phase L3 volatge
  18516. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18517. {
  18518. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18519. {
  18520. tempIndex = 2;
  18521. }
  18522. else
  18523. {
  18524. tempIndex = gun_index;
  18525. }
  18526. for (int index = 0; index < AC_QUANTITY; index++)
  18527. {
  18528. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18529. {
  18530. 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
  18531. }
  18532. } // END OF FOR AC_QUANTITY
  18533. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  18534. }
  18535. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18536. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  18537. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  18538. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  18539. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18540. }
  18541. //====================== Start SoC ================================
  18542. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18543. {
  18544. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18545. 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))
  18546. {
  18547. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18548. {
  18549. tempIndex = ((gun_index==2) ? 1: 0);
  18550. }
  18551. else
  18552. {
  18553. tempIndex = gun_index;
  18554. }
  18555. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18556. {
  18557. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18558. {
  18559. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18560. {
  18561. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  18562. }
  18563. }
  18564. }
  18565. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18566. {
  18567. for (int index = 0; index < CCS_QUANTITY; index++)
  18568. {
  18569. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18570. {
  18571. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  18572. }
  18573. }
  18574. }
  18575. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18576. {
  18577. for (int index = 0; index < GB_QUANTITY; index++)
  18578. {
  18579. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18580. {
  18581. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  18582. }
  18583. }
  18584. }
  18585. else if(gunType[gun_index] == GUN_TYPE_DO)
  18586. {
  18587. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18588. {
  18589. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18590. {
  18591. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  18592. }
  18593. }
  18594. }
  18595. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18596. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  18597. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18598. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  18599. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  18600. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18601. } // END FOR DC CASE
  18602. }
  18603. //======================================== Message create ==============================================
  18604. json_object *StopTransaction = json_object_new_object();
  18605. json_object *transactionDatas = json_object_new_array();
  18606. json_object *sampledValues = json_object_new_array();
  18607. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  18608. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  18609. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  18610. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  18611. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  18612. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  18613. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  18614. {
  18615. json_object *transactionData = json_object_new_object();
  18616. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  18617. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  18618. {
  18619. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  18620. {
  18621. json_object *sampledValue = json_object_new_object();
  18622. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  18623. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  18624. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  18625. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  18626. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  18627. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  18628. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  18629. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  18630. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  18631. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  18632. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  18633. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  18634. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  18635. json_object_array_add(sampledValues, sampledValue);
  18636. }
  18637. }
  18638. json_object_object_add(transactionData, "sampledValue", sampledValues);
  18639. json_object_array_add(transactionDatas, transactionData);
  18640. }
  18641. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  18642. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  18643. ,MESSAGE_TYPE_CALL
  18644. ,guid
  18645. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  18646. json_object_put(StopTransaction);
  18647. // Check File "TempStopTransaction" Exist
  18648. if((access(TempStopTransaction,F_OK))!=-1)
  18649. {
  18650. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  18651. fclose(fopen(TempStopTransaction, "w"));
  18652. }
  18653. else
  18654. {
  18655. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  18656. FILE *log = fopen(TempStopTransaction, "w+");
  18657. if(log == NULL)
  18658. {
  18659. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  18660. return ;
  18661. }
  18662. else
  18663. {
  18664. fclose(log);
  18665. }
  18666. }
  18667. //Add TempStopTransaction | Update TempStopTransaction
  18668. // open file for writing
  18669. FILE *outfile;
  18670. outfile = fopen (TempStopTransaction, "a");
  18671. //DEBUG_INFO("data = %s\n", queuedata);
  18672. fputs(queuedata, outfile);
  18673. fputs("\n", outfile);
  18674. fclose (outfile);
  18675. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18676. }
  18677. void checkTempStopTransaction(int gun_index)
  18678. {
  18679. FILE *fptr1;
  18680. char ch;
  18681. char str[QUEUE_MESSAGE_LENGTH]={0};
  18682. char guid[37]={0};
  18683. char tempdata[65]={0};
  18684. char connectorStr[2]={0};
  18685. char TempStopTransaction[256];
  18686. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  18687. fptr1 = fopen(TempStopTransaction, "r");
  18688. //TempStopTransaction格式: 槍號,StopTransaction封包
  18689. if (!fptr1)
  18690. {
  18691. //printf(" File not found or unable to open the input file!!\n");
  18692. return ;
  18693. }
  18694. ch=fgetc(fptr1);
  18695. //printf(" Now the content of the file %s is : \n",fname);
  18696. rewind(fptr1);
  18697. if(ch!=EOF)
  18698. {
  18699. // copy all contents to the temporary file except the specific line
  18700. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18701. {
  18702. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18703. if(str[0]=='\0')
  18704. {
  18705. break;
  18706. }
  18707. //TempStopTransaction格式: 槍號,StopTransaction封包
  18708. strncpy(connectorStr, str, 1);
  18709. if(atoi(connectorStr) != (gun_index+1))
  18710. {
  18711. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18712. fclose(fptr1);
  18713. return ;
  18714. }
  18715. //random_uuid(guid);
  18716. strncpy(guid, str+6, 36); //copy guid
  18717. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18718. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18719. {
  18720. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18721. }
  18722. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18723. OCPP_insert_transaction_msg(NO, str);
  18724. memset(str,0,ARRAY_SIZE(str));
  18725. }
  18726. }
  18727. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18728. fclose(fptr1);
  18729. remove(TempStopTransaction); // remove the original file
  18730. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18731. }
  18732. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18733. {
  18734. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18735. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18736. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18737. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18738. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18739. }
  18740. int GetWebSocketPingInterval(void)
  18741. {
  18742. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18743. }
  18744. int GetServerSign(void)
  18745. {
  18746. return server_sign;
  18747. }
  18748. uint8_t GetOcppSecurityProfile()
  18749. {
  18750. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18751. }
  18752. void GetOcppChargerBoxId(uint8_t *data)
  18753. {
  18754. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  18755. }
  18756. void GetOcppSecurityPassword(uint8_t *data)
  18757. {
  18758. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18759. }
  18760. void SetOcppVersion(uint8_t *version)
  18761. {
  18762. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18763. DEBUG_INFO("ocpp version: %s\n", version);
  18764. if(strstr((char*)version, "ocpp1.6") != NULL)
  18765. {
  18766. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18767. }
  18768. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18769. {
  18770. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18771. system("pkill OcppBackend");
  18772. }
  18773. }
  18774. void SetServerSign(int value)
  18775. {
  18776. server_sign = value;
  18777. }
  18778. int GetBootNotificationInterval(void)
  18779. {
  18780. return BootNotificationInterval;
  18781. }
  18782. int GetInternetConn(void)
  18783. {
  18784. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18785. }
  18786. int GetBackendConnectionTimeout(void)
  18787. {
  18788. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18789. }
  18790. int isConnectorInitMode(int gun_index)
  18791. {
  18792. int tempIndex = 0;
  18793. int result = TRUE;
  18794. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18795. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18796. {
  18797. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18798. {
  18799. tempIndex = ((gun_index==2) ? 1: 0);
  18800. }
  18801. else
  18802. {
  18803. tempIndex = gun_index;
  18804. }
  18805. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18806. {
  18807. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18808. {
  18809. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18810. } //end of the same index
  18811. }//end of for CHAdeMO_QUANTITY
  18812. }
  18813. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18814. {
  18815. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18816. {
  18817. tempIndex = ((gun_index==2) ? 1: 0);
  18818. }
  18819. else
  18820. {
  18821. tempIndex = gun_index;
  18822. }
  18823. for (int index = 0; index < CCS_QUANTITY; index++)
  18824. {
  18825. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18826. {
  18827. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18828. } //end of the same index
  18829. } // end of for CCS_QUANTITY
  18830. }
  18831. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18832. {
  18833. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18834. {
  18835. tempIndex = ((gun_index==2) ? 1: 0);
  18836. }
  18837. else
  18838. {
  18839. tempIndex = gun_index;
  18840. }
  18841. for (int index = 0; index < GB_QUANTITY; index++)
  18842. {
  18843. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18844. {
  18845. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18846. } //end of the same index
  18847. } // end of for GB_QUANTITY
  18848. }
  18849. else if(gunType[gun_index] == GUN_TYPE_DO)
  18850. {
  18851. tempIndex = gun_index;
  18852. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18853. {
  18854. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18855. {
  18856. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18857. } //end of the same index
  18858. }
  18859. }
  18860. else
  18861. {
  18862. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18863. {
  18864. tempIndex = 2;
  18865. }
  18866. else
  18867. {
  18868. tempIndex = gun_index;
  18869. }
  18870. for (int index = 0; index < AC_QUANTITY; index++)
  18871. {
  18872. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18873. {
  18874. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18875. }//end of the same index
  18876. }//end of for AC_QUANTITY
  18877. }
  18878. return result;
  18879. }
  18880. void refreshProcDogTimer()
  18881. {
  18882. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  18883. }
  18884. void InitialSystemValue(void)
  18885. {
  18886. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  18887. locallistVersion=0;
  18888. BootNotificationInterval = 0;
  18889. authorizeRetryTimes = 0;
  18890. GunStatusInterval = 10;
  18891. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18892. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18893. //Hear Beat
  18894. HeartBeatWithNOResponse = 0;
  18895. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18896. FirstHeartBeat = 0;
  18897. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18898. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18899. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18900. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18901. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18902. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18903. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18904. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18905. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18906. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18907. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18908. //Status && ConnectorPlugIn Setting
  18909. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18910. {
  18911. ChademoPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18912. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18913. }
  18914. for (int index = 0; index < CCS_QUANTITY; index++)
  18915. {
  18916. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18917. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18918. }
  18919. for (int index = 0; index < GB_QUANTITY; index++)
  18920. {
  18921. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18922. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18923. }
  18924. for (int index = 0; index < AC_QUANTITY; index++)
  18925. {
  18926. AcPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18927. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18928. }
  18929. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18930. {
  18931. DoPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18932. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18933. }
  18934. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18935. {
  18936. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18937. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18938. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18939. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18940. //memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18941. memset(&ShmOCPP16DataPH->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16DataPH->StatusNotification[gun_index].Status));
  18942. }
  18943. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18944. refreshStartTimer(&clientTime.Heartbeat);
  18945. sleep(1);
  18946. }
  18947. void LWS_Send(char *str)
  18948. {
  18949. //=====================================================
  18950. // Check InternetConn 0: disconnected, 1: connected
  18951. //====================================================
  18952. if(GetOcppConnStatus() == 0)
  18953. {
  18954. DEBUG_INFO("offline now !!!\n");
  18955. return;
  18956. }
  18957. // Only disable isWebsocketSendable operation initiated by charger
  18958. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18959. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18960. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18961. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18962. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18963. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18964. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18965. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18966. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18967. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18968. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18969. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18970. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18971. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18972. {
  18973. isWebsocketSendable = 0;
  18974. }
  18975. pthread_mutex_lock(&lock_send);
  18976. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18977. sprintf((char *)SendBuffer, "%s", str);
  18978. SendBufLen = strlen(str);
  18979. pthread_mutex_unlock(&lock_send);
  18980. lws_callback_on_writable(wsi_client);
  18981. //lws_service(context, 0);
  18982. //sleep(1);
  18983. }
  18984. void LWS_SendNow(char *str)
  18985. {
  18986. //=====================================================
  18987. // Check InternetConn 0: disconnected, 1: connected
  18988. //====================================================
  18989. if(GetOcppConnStatus() == 0)
  18990. {
  18991. DEBUG_INFO("offline now !!!\n");
  18992. return;
  18993. }
  18994. // Only disable isWebsocketSendable operation initiated by charger
  18995. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18996. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18997. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18998. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18999. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19000. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19001. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19002. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  19003. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19004. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  19005. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19006. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19007. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19008. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  19009. {
  19010. isWebsocketSendable = 0;
  19011. }
  19012. pthread_mutex_lock(&lock_send);
  19013. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19014. sprintf((char *)SendBuffer, "%s", str);
  19015. SendBufLen = strlen(str);
  19016. pthread_mutex_unlock(&lock_send);
  19017. lws_callback_on_writable(wsi_client);
  19018. lws_service(context, 0);
  19019. //sleep(1);
  19020. }