MessageHandler.c 957 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737
  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. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4979. }
  4980. }
  4981. }
  4982. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4983. {
  4984. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4985. {
  4986. tempIndex = ((gun_index==2) ? 1: 0);
  4987. }
  4988. else
  4989. {
  4990. tempIndex = gun_index;
  4991. }
  4992. for (int index = 0; index < CCS_QUANTITY; index++)
  4993. {
  4994. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4995. {
  4996. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4997. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4998. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4999. }
  5000. }
  5001. }
  5002. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5003. {
  5004. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5005. {
  5006. tempIndex = ((gun_index==2) ? 1: 0);
  5007. }
  5008. else
  5009. {
  5010. tempIndex = gun_index;
  5011. }
  5012. for (int index = 0; index < GB_QUANTITY; index++)
  5013. {
  5014. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5015. {
  5016. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5017. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  5018. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5019. }
  5020. }
  5021. }
  5022. else if(gunType[gun_index] == GUN_TYPE_DO)
  5023. {
  5024. tempIndex = gun_index;
  5025. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5026. {
  5027. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5028. {
  5029. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5030. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5031. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5032. }
  5033. }
  5034. }
  5035. else
  5036. {
  5037. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5038. {
  5039. tempIndex = 2;
  5040. }
  5041. else
  5042. {
  5043. tempIndex = gun_index;
  5044. }
  5045. for (int index = 0; index < AC_QUANTITY; index++)
  5046. {
  5047. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5048. {
  5049. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5050. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5051. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5052. }
  5053. }
  5054. }
  5055. random_uuid(guid);
  5056. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5057. {
  5058. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5059. , gun_index +1
  5060. , MESSAGE_TYPE_CALL
  5061. , guid
  5062. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  5063. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  5064. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  5065. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  5066. }
  5067. else
  5068. {
  5069. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5070. , gun_index +1
  5071. , MESSAGE_TYPE_CALL
  5072. , guid
  5073. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  5074. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  5075. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  5076. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  5077. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  5078. }
  5079. #if 1
  5080. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5081. 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*/)
  5082. {
  5083. result = PASS;
  5084. }
  5085. #endif
  5086. strcpy(queuedata, message);
  5087. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5088. OCPP_insert_transaction_msg(YES, queuedata);
  5089. return result;
  5090. }
  5091. int sendStatusNotificationRequest(int gun_index)
  5092. {
  5093. mtrace();
  5094. int result = FAIL;
  5095. char message[600]={0};
  5096. char guid[37];
  5097. int currentStatus = 0;
  5098. struct timeval tmnow;
  5099. struct tm *tm;
  5100. char buf[28];//, usec_buf[6];
  5101. char tempdata[65]={0};
  5102. int tempIndex = 0;
  5103. uint8_t isStateChanged = TRUE;
  5104. uint8_t isContentIllegal = TRUE;
  5105. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5106. gettimeofday(&tmnow, NULL);
  5107. time_t t;
  5108. t = time(NULL);
  5109. /*UTC time and date*/
  5110. tm = gmtime(&t);
  5111. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5112. #if 0 // remove temporally
  5113. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5114. strcat(buf,".");
  5115. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5116. strcat(buf,usec_buf);
  5117. #endif
  5118. //printf("%s",buf);
  5119. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5120. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5121. // it's option
  5122. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  5123. /*
  5124. enum _SYSTEM_STATUS
  5125. {
  5126. S_BOOTING = 0,
  5127. S_IDLE, = 1
  5128. S_AUTHORIZING, =2
  5129. S_REASSIGN_CHECK, =3
  5130. S_REASSIGN, =4
  5131. S_PRECHARGE, =5
  5132. S_PREPARING_FOR_EV, =6
  5133. S_PREPARING_FOR_EVSE, =7
  5134. S_CHARGING, =8
  5135. S_TERMINATING, =9
  5136. S_COMPLETE, =10
  5137. S_ALARM, =11
  5138. S_FAULT =12
  5139. }
  5140. */
  5141. //check Transaction active
  5142. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5143. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5144. {
  5145. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5146. {
  5147. tempIndex = ((gun_index==2) ? 1: 0);
  5148. }
  5149. else
  5150. {
  5151. tempIndex = gun_index;
  5152. }
  5153. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5154. {
  5155. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5156. {
  5157. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5158. {
  5159. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5160. {
  5161. currentStatus = Preparing; //OCPP Status: Preparing
  5162. }
  5163. else
  5164. {
  5165. currentStatus = Available; //OCPP Status: Available
  5166. }
  5167. }
  5168. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5169. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5170. ) //S_PRECHARGE
  5171. {
  5172. currentStatus = Preparing; //OCPP Status: Preparing
  5173. }
  5174. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5175. {
  5176. currentStatus = Charging; //OCPP Status: Charging
  5177. }
  5178. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5179. {
  5180. currentStatus = Finishing; //OCPP Status: Finishing
  5181. }
  5182. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5183. {
  5184. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5185. }
  5186. 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
  5187. {
  5188. currentStatus = Unavailable; //OCPP Status: Unavailable
  5189. }
  5190. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5191. {
  5192. currentStatus = Faulted; //OCPP Status: Faulted
  5193. }
  5194. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5195. {
  5196. currentStatus = Reserved; //OCPP Status: Reserved
  5197. }
  5198. } //end of the same index
  5199. }//end of for CHAdeMO_QUANTITY
  5200. }
  5201. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5202. {
  5203. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5204. {
  5205. tempIndex = ((gun_index==2) ? 1: 0);
  5206. }
  5207. else
  5208. {
  5209. tempIndex = gun_index;
  5210. }
  5211. for (int index = 0; index < CCS_QUANTITY; index++)
  5212. {
  5213. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5214. {
  5215. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5216. {
  5217. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5218. {
  5219. currentStatus = Preparing; //OCPP Status: Preparing
  5220. }
  5221. else
  5222. {
  5223. currentStatus = Available; //OCPP Status: Available
  5224. }
  5225. }
  5226. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5227. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5228. ) //S_PRECHARGE
  5229. {
  5230. currentStatus = Preparing; //OCPP Status: Preparing
  5231. }
  5232. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5233. {
  5234. currentStatus = Charging; //OCPP Status: Charging
  5235. }
  5236. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5237. {
  5238. currentStatus = Finishing; //OCPP Status: Finishing
  5239. }
  5240. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5241. {
  5242. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5243. }
  5244. 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
  5245. {
  5246. currentStatus = Unavailable; //OCPP Status : Unavailable
  5247. }
  5248. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5249. {
  5250. currentStatus = Faulted; //OCPP Status: Faulted
  5251. }
  5252. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5253. {
  5254. currentStatus = Reserved; //OCPP Status: Reserved
  5255. }
  5256. } //end of the same index
  5257. } // end of for CCS_QUANTITY
  5258. }
  5259. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5260. {
  5261. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5262. {
  5263. tempIndex = ((gun_index==2) ? 1: 0);
  5264. }
  5265. else
  5266. {
  5267. tempIndex = gun_index;
  5268. }
  5269. for (int index = 0; index < GB_QUANTITY; index++)
  5270. {
  5271. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5272. {
  5273. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5274. {
  5275. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5276. {
  5277. currentStatus = Preparing; //OCPP Status: Preparing
  5278. }
  5279. else
  5280. {
  5281. currentStatus = Available; //OCPP Status: Available
  5282. }
  5283. }
  5284. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5285. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5286. ) //S_PRECHARGE
  5287. {
  5288. currentStatus = Preparing; //OCPP Status: Preparing
  5289. }
  5290. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5291. {
  5292. currentStatus = Charging; //OCPP Status: Charging
  5293. }
  5294. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5295. {
  5296. currentStatus = Finishing; //OCPP Status: Finishing
  5297. }
  5298. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5299. {
  5300. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5301. }
  5302. 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
  5303. {
  5304. currentStatus = Unavailable; //OCPP Status: Unavailable
  5305. }
  5306. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5307. {
  5308. currentStatus = Faulted; //OCPP Status: Faulted
  5309. }
  5310. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5311. {
  5312. currentStatus = Reserved; //OCPP Status: Reserved
  5313. }
  5314. } //end of the same index
  5315. } // end of for GB_QUANTITY
  5316. }
  5317. else if(gunType[gun_index] == GUN_TYPE_DO)
  5318. {
  5319. tempIndex = gun_index;
  5320. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5321. {
  5322. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5323. {
  5324. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5325. {
  5326. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5327. {
  5328. currentStatus = Preparing; //OCPP Status: Preparing
  5329. }
  5330. else
  5331. {
  5332. currentStatus = Available; //OCPP Status: Available
  5333. }
  5334. }
  5335. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5336. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5337. ) //S_PRECHARGE
  5338. {
  5339. currentStatus = Preparing; //OCPP Status: Preparing
  5340. }
  5341. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5342. {
  5343. currentStatus = Charging; //OCPP Status: Charging
  5344. }
  5345. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5346. {
  5347. currentStatus = Finishing; //OCPP Status: Finishing
  5348. }
  5349. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5350. {
  5351. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5352. }
  5353. 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
  5354. {
  5355. currentStatus = Unavailable; //OCPP Status: Unavailable
  5356. }
  5357. 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
  5358. {
  5359. currentStatus = Faulted; //OCPP Status: Faulted
  5360. }
  5361. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5362. {
  5363. currentStatus = Reserved; //OCPP Status: Reserved
  5364. }
  5365. } //end of the same index
  5366. }
  5367. }
  5368. else
  5369. {
  5370. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5371. {
  5372. tempIndex = 2;
  5373. }
  5374. else
  5375. {
  5376. tempIndex = gun_index;
  5377. }
  5378. for (int index = 0; index < AC_QUANTITY; index++)
  5379. {
  5380. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5381. {
  5382. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5383. {
  5384. 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))
  5385. {
  5386. currentStatus = Preparing; //OCPP Status: Preparing
  5387. }
  5388. else
  5389. {
  5390. currentStatus = Available; //OCPP Status: Available
  5391. }
  5392. }
  5393. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5394. {
  5395. currentStatus = Preparing; //OCPP Status: Preparing
  5396. }
  5397. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5398. {
  5399. currentStatus = Charging; //OCPP Status: Charging
  5400. }
  5401. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5402. {
  5403. currentStatus = Finishing; //OCPP Status: Finishing
  5404. }
  5405. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5406. {
  5407. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5408. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5409. else
  5410. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5411. }
  5412. 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
  5413. {
  5414. currentStatus = Unavailable; //OCPP Status: Unavailable
  5415. }
  5416. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5417. {
  5418. currentStatus = Faulted; //OCPP Status: Faulted
  5419. }
  5420. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5421. {
  5422. currentStatus = Reserved; //OCPP Status: Reserved
  5423. }
  5424. }//end of the same index
  5425. }//end of for AC_QUANTITY
  5426. }
  5427. //it's option
  5428. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5429. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5430. (strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5431. {
  5432. isStateChanged = FALSE;
  5433. }
  5434. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5435. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  5436. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5437. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5438. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  5439. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  5440. isContentIllegal = TRUE;
  5441. for(int index = 0; index < ARRAY_SIZE(ChargePointErrorCodeStr); index++)
  5442. {
  5443. if(strcmp((char *)ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[index])==0)
  5444. {
  5445. isContentIllegal = FALSE;
  5446. break;
  5447. }
  5448. }
  5449. if(isContentIllegal)
  5450. {
  5451. //DEBUG_WARN("Detect illegal ErrorCode: %s \n",(char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  5452. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[6]);
  5453. }
  5454. random_uuid(guid);
  5455. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5456. , MESSAGE_TYPE_CALL
  5457. , guid
  5458. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  5459. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  5460. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  5461. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  5462. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  5463. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  5464. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  5465. if((server_sign == TRUE) && isStateChanged)
  5466. {
  5467. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5468. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5469. LWS_Send(message);
  5470. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5471. 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*/)
  5472. {
  5473. //DEBUG_ERROR("statusNotification mapitem pass");
  5474. result = PASS;
  5475. }
  5476. }
  5477. else
  5478. {
  5479. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5480. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5481. result = PASS;
  5482. }
  5483. return result;
  5484. }
  5485. int sendStopTransactionRequest(int gun_index)
  5486. {
  5487. mtrace();
  5488. int result = FAIL;
  5489. //char message[1500]={0};
  5490. char guid[37]={0};
  5491. char tempdata[65]={0};
  5492. int tempIndex = 0;
  5493. char TempStopTransaction[256];
  5494. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  5495. //int idx_sample=0;
  5496. DEBUG_INFO("sendStopTransactionRequest \n");
  5497. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5498. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  5499. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5500. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5501. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5502. {
  5503. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5504. {
  5505. tempIndex = ((gun_index==2) ? 1: 0);
  5506. }
  5507. else
  5508. {
  5509. tempIndex = gun_index;
  5510. }
  5511. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5512. {
  5513. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5514. {
  5515. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5516. }
  5517. }// END OF CHAdeMO_QUANTITY
  5518. }
  5519. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5520. {
  5521. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5522. {
  5523. tempIndex = ((gun_index==2) ? 1: 0);
  5524. }
  5525. else
  5526. {
  5527. tempIndex = gun_index;
  5528. }
  5529. for (int index = 0; index < CCS_QUANTITY; index++)
  5530. {
  5531. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5532. {
  5533. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5534. }
  5535. }// END OF CCS_QUANTITY
  5536. }
  5537. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5538. {
  5539. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5540. {
  5541. tempIndex = ((gun_index==2) ? 1: 0);
  5542. }
  5543. else
  5544. {
  5545. tempIndex = gun_index;
  5546. }
  5547. for (int index = 0; index < GB_QUANTITY; index++)
  5548. {
  5549. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5550. {
  5551. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5552. }
  5553. }// END OF GB_QUANTITY
  5554. }
  5555. else if(gunType[gun_index] == GUN_TYPE_DO)
  5556. {
  5557. tempIndex = gun_index;
  5558. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5559. {
  5560. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5561. {
  5562. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5563. }
  5564. }// END OF GB_QUANTITY
  5565. }
  5566. else
  5567. {
  5568. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5569. {
  5570. tempIndex = 2;
  5571. }
  5572. else
  5573. {
  5574. tempIndex = gun_index;
  5575. }
  5576. for (int index = 0; index < AC_QUANTITY; index++)
  5577. {
  5578. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5579. {
  5580. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5581. }
  5582. }// END OF AC_QUANTITY
  5583. }
  5584. //====================================== Stop Transaction Time =====================================================
  5585. struct timeval tmnow;
  5586. struct tm *tm;
  5587. char buf[28];//, usec_buf[6];
  5588. gettimeofday(&tmnow, NULL);
  5589. time_t t;
  5590. t = time(NULL);
  5591. /*UTC time and date*/
  5592. tm = gmtime(&t);
  5593. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5594. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  5595. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  5596. random_uuid(guid);
  5597. /***********************************transactionData******************************************************/
  5598. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5599. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5600. //=================================
  5601. // Transaction_Begin
  5602. //=================================
  5603. //=================================
  5604. // Transaction_End
  5605. //=================================
  5606. // ================================= Current.Import L1 ===============================================
  5607. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5608. {
  5609. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5610. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5611. {
  5612. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5613. {
  5614. tempIndex = ((gun_index==2) ? 1: 0);
  5615. }
  5616. else
  5617. {
  5618. tempIndex = gun_index;
  5619. }
  5620. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5621. {
  5622. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5623. {
  5624. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5625. }
  5626. }// End of for CHAdeMO_QUANTITY
  5627. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5628. }
  5629. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5630. {
  5631. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5632. {
  5633. tempIndex = ((gun_index==2) ? 1: 0);
  5634. }
  5635. else
  5636. {
  5637. tempIndex = gun_index;
  5638. }
  5639. for (int index = 0; index < CCS_QUANTITY; index++)
  5640. {
  5641. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5642. {
  5643. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5644. }
  5645. }// End of for CCS_QUANTITY
  5646. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5647. }
  5648. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5649. {
  5650. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5651. {
  5652. tempIndex = ((gun_index==2) ? 1: 0);
  5653. }
  5654. else
  5655. {
  5656. tempIndex = gun_index;
  5657. }
  5658. for (int index = 0; index < GB_QUANTITY; index++)
  5659. {
  5660. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5661. {
  5662. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5663. }
  5664. }// End of for GB_QUANTITY
  5665. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5666. }
  5667. else if(gunType[gun_index] == GUN_TYPE_DO)
  5668. {
  5669. tempIndex = gun_index;
  5670. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5671. {
  5672. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5673. {
  5674. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5675. }
  5676. }
  5677. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5678. }
  5679. else
  5680. {
  5681. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5682. {
  5683. tempIndex = 2;
  5684. }
  5685. else
  5686. {
  5687. tempIndex = gun_index;
  5688. }
  5689. for (int index = 0; index < AC_QUANTITY; index++)
  5690. {
  5691. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5692. {
  5693. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5694. }
  5695. }// End of for AC_QUANTITY
  5696. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5697. }
  5698. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5699. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5700. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5701. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5702. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5703. }
  5704. // ================================= Energy.Active.Import.Interval ==============================================
  5705. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5706. {
  5707. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5708. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5709. {
  5710. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5711. {
  5712. tempIndex = ((gun_index==2) ? 1: 0);
  5713. }
  5714. else
  5715. {
  5716. tempIndex = gun_index;
  5717. }
  5718. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5719. {
  5720. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5721. {
  5722. 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
  5723. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  5724. }
  5725. }// END OF CHAdeMO_QUANTITY
  5726. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5727. }
  5728. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5729. {
  5730. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5731. {
  5732. tempIndex = ((gun_index==2) ? 1: 0);
  5733. }
  5734. else
  5735. {
  5736. tempIndex = gun_index;
  5737. }
  5738. for (int index = 0; index < CCS_QUANTITY; index++)
  5739. {
  5740. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5741. {
  5742. 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
  5743. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5744. }
  5745. }// END OF CCS_QUANTITY
  5746. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5747. }
  5748. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5749. {
  5750. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5751. {
  5752. tempIndex = ((gun_index==2) ? 1: 0);
  5753. }
  5754. else
  5755. {
  5756. tempIndex = gun_index;
  5757. }
  5758. for (int index = 0; index < GB_QUANTITY; index++)
  5759. {
  5760. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5761. {
  5762. 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
  5763. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5764. }
  5765. }// END OF GB_QUANTITY
  5766. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5767. }
  5768. else if(gunType[gun_index] == GUN_TYPE_DO)
  5769. {
  5770. tempIndex = gun_index;
  5771. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5772. {
  5773. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5774. {
  5775. 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
  5776. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5777. }
  5778. }
  5779. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5780. }
  5781. else
  5782. {
  5783. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5784. {
  5785. tempIndex = 2;
  5786. }
  5787. else
  5788. {
  5789. tempIndex = gun_index;
  5790. }
  5791. for (int index = 0; index < AC_QUANTITY; index++)
  5792. {
  5793. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5794. {
  5795. 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
  5796. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5797. }
  5798. }// END OF AC_QUANTITY
  5799. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5800. }
  5801. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5802. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5803. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5804. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5805. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5806. }
  5807. //=================================== Power.Active.Import ==================================================
  5808. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5809. {
  5810. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5811. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5812. {
  5813. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5814. {
  5815. tempIndex = ((gun_index==2) ? 1: 0);
  5816. }
  5817. else
  5818. {
  5819. tempIndex = gun_index;
  5820. }
  5821. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5822. {
  5823. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5824. {
  5825. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5826. }
  5827. } // End for CHAdeMO_QUANTITY
  5828. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5829. }
  5830. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5831. {
  5832. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5833. {
  5834. tempIndex = ((gun_index==2) ? 1: 0);
  5835. }
  5836. else
  5837. {
  5838. tempIndex = gun_index;
  5839. }
  5840. for (int index = 0; index < CCS_QUANTITY; index++)
  5841. {
  5842. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5843. {
  5844. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5845. }
  5846. } // END for CCS_QUANTITY
  5847. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5848. }
  5849. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5850. {
  5851. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5852. {
  5853. tempIndex = ((gun_index==2) ? 1: 0);
  5854. }
  5855. else
  5856. {
  5857. tempIndex = gun_index;
  5858. }
  5859. for (int index = 0; index < GB_QUANTITY; index++)
  5860. {
  5861. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5862. {
  5863. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5864. }
  5865. }// END for GB_QUANTITY
  5866. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5867. }
  5868. else if(gunType[gun_index] == GUN_TYPE_DO)
  5869. {
  5870. tempIndex = gun_index;
  5871. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5872. {
  5873. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5874. {
  5875. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5876. }
  5877. }
  5878. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5879. }
  5880. else
  5881. {
  5882. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5883. {
  5884. tempIndex = 2;
  5885. }
  5886. else
  5887. {
  5888. tempIndex = gun_index;
  5889. }
  5890. for (int index = 0; index < AC_QUANTITY; index++)
  5891. {
  5892. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5893. {
  5894. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5895. }
  5896. } // END for AC_QUANTITY
  5897. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5898. }
  5899. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5900. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5901. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5902. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5903. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5904. }
  5905. //============================ Voltage L1 ====================================
  5906. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5907. {
  5908. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5909. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5910. {
  5911. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5912. {
  5913. tempIndex = ((gun_index==2) ? 1: 0);
  5914. }
  5915. else
  5916. {
  5917. tempIndex = gun_index;
  5918. }
  5919. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5920. {
  5921. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5922. {
  5923. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5924. }
  5925. } // END OF FOR CHAdeMO_QUANTITY
  5926. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5927. }
  5928. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5929. {
  5930. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5931. {
  5932. tempIndex = ((gun_index==2) ? 1: 0);
  5933. }
  5934. else
  5935. {
  5936. tempIndex = gun_index;
  5937. }
  5938. for (int index = 0; index < CCS_QUANTITY; index++)
  5939. {
  5940. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5941. {
  5942. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5943. }
  5944. } // END OF FOR CCS_QUANTITY
  5945. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5946. }
  5947. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5948. {
  5949. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5950. {
  5951. tempIndex = ((gun_index==2) ? 1: 0);
  5952. }
  5953. else
  5954. {
  5955. tempIndex = gun_index;
  5956. }
  5957. for (int index = 0; index < GB_QUANTITY; index++)
  5958. {
  5959. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5960. {
  5961. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5962. }
  5963. } // END OF FOR GB_QUANTITY
  5964. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5965. }
  5966. else if(gunType[gun_index] == GUN_TYPE_DO)
  5967. {
  5968. tempIndex = gun_index;
  5969. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5970. {
  5971. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5972. {
  5973. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5974. }
  5975. }
  5976. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5977. }
  5978. else
  5979. {
  5980. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5981. {
  5982. tempIndex = 2;
  5983. }
  5984. else
  5985. {
  5986. tempIndex = gun_index;
  5987. }
  5988. for (int index = 0; index < AC_QUANTITY; index++)
  5989. {
  5990. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5991. {
  5992. 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
  5993. }
  5994. } // END OF FOR AC_QUANTITY
  5995. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5996. }
  5997. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5998. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5999. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  6000. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  6001. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6002. }
  6003. //====================== End SoC ================================
  6004. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6005. {
  6006. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6007. 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))
  6008. {
  6009. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6010. {
  6011. tempIndex = ((gun_index==2) ? 1: 0);
  6012. }
  6013. else
  6014. {
  6015. tempIndex = gun_index;
  6016. }
  6017. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6018. {
  6019. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6020. {
  6021. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6022. {
  6023. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  6024. }
  6025. }
  6026. }
  6027. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6028. {
  6029. for (int index = 0; index < CCS_QUANTITY; index++)
  6030. {
  6031. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6032. {
  6033. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  6034. }
  6035. }
  6036. }
  6037. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6038. {
  6039. for (int index = 0; index < GB_QUANTITY; index++)
  6040. {
  6041. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6042. {
  6043. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6044. }
  6045. }
  6046. }
  6047. else if(gunType[gun_index] == GUN_TYPE_DO)
  6048. {
  6049. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6050. {
  6051. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6052. {
  6053. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6054. }
  6055. }
  6056. }
  6057. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6058. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6059. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6060. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6061. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6062. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6063. } // END FOR DC CASE
  6064. }
  6065. // ================================= Current.Import L2 ===============================================
  6066. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6067. {
  6068. // AC 3 phse L2 current
  6069. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6070. {
  6071. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6072. {
  6073. tempIndex = 2;
  6074. }
  6075. else
  6076. {
  6077. tempIndex = gun_index;
  6078. }
  6079. for (int index = 0; index < AC_QUANTITY; index++)
  6080. {
  6081. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6082. {
  6083. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6084. }
  6085. }// End of for AC_QUANTITY
  6086. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6087. }
  6088. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6089. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6090. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6091. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6092. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6093. }
  6094. // ================================= Current.Import L3 ===============================================
  6095. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6096. {
  6097. // AC 3 phse L3 current
  6098. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6099. {
  6100. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6101. {
  6102. tempIndex = 2;
  6103. }
  6104. else
  6105. {
  6106. tempIndex = gun_index;
  6107. }
  6108. for (int index = 0; index < AC_QUANTITY; index++)
  6109. {
  6110. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6111. {
  6112. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6113. }
  6114. }// End of for AC_QUANTITY
  6115. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6116. }
  6117. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6118. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6119. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6120. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6121. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6122. }
  6123. //============================ Voltage L2 ====================================
  6124. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6125. {
  6126. // AC 3 phse L2 voltage
  6127. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6128. {
  6129. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6130. {
  6131. tempIndex = 2;
  6132. }
  6133. else
  6134. {
  6135. tempIndex = gun_index;
  6136. }
  6137. for (int index = 0; index < AC_QUANTITY; index++)
  6138. {
  6139. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6140. {
  6141. 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
  6142. }
  6143. } // END OF FOR AC_QUANTITY
  6144. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6145. }
  6146. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6147. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6148. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6149. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6150. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6151. }
  6152. //============================ Voltage L3 ====================================
  6153. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6154. {
  6155. // AC 3 phse L3 voltage
  6156. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6157. {
  6158. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6159. {
  6160. tempIndex = 2;
  6161. }
  6162. else
  6163. {
  6164. tempIndex = gun_index;
  6165. }
  6166. for (int index = 0; index < AC_QUANTITY; index++)
  6167. {
  6168. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6169. {
  6170. 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
  6171. }
  6172. } // END OF FOR AC_QUANTITY
  6173. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6174. }
  6175. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6176. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6177. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6178. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6179. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6180. }
  6181. //====================== Start SoC ================================
  6182. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6183. {
  6184. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6185. 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))
  6186. {
  6187. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6188. {
  6189. tempIndex = ((gun_index==2) ? 1: 0);
  6190. }
  6191. else
  6192. {
  6193. tempIndex = gun_index;
  6194. }
  6195. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6196. {
  6197. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6198. {
  6199. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6200. {
  6201. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6202. }
  6203. }
  6204. }
  6205. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6206. {
  6207. for (int index = 0; index < CCS_QUANTITY; index++)
  6208. {
  6209. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6210. {
  6211. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6212. }
  6213. }
  6214. }
  6215. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6216. {
  6217. for (int index = 0; index < GB_QUANTITY; index++)
  6218. {
  6219. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6220. {
  6221. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6222. }
  6223. }
  6224. }
  6225. else if(gunType[gun_index] == GUN_TYPE_DO)
  6226. {
  6227. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6228. {
  6229. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6230. {
  6231. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6232. }
  6233. }
  6234. }
  6235. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6236. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6237. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6238. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6239. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6240. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6241. } // END FOR DC CASE
  6242. }
  6243. //================================================ Message create ====================================================
  6244. json_object *StopTransaction = json_object_new_object();
  6245. json_object *transactionDatas = json_object_new_array();
  6246. json_object *sampledValues = json_object_new_array();
  6247. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  6248. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  6249. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  6250. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  6251. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  6252. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  6253. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  6254. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  6255. {
  6256. json_object *transactionData = json_object_new_object();
  6257. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6258. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6259. {
  6260. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6261. {
  6262. json_object *sampledValue = json_object_new_object();
  6263. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6264. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6265. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6266. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6267. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6268. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6269. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6270. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6271. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6272. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6273. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6274. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6275. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6276. json_object_array_add(sampledValues, sampledValue);
  6277. }
  6278. }
  6279. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6280. json_object_array_add(transactionDatas, transactionData);
  6281. }
  6282. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6283. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6284. ,MESSAGE_TYPE_CALL
  6285. ,guid
  6286. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6287. json_object_put(StopTransaction);
  6288. #if 1 // for TempStopTransaction
  6289. //Delete TempStopTransaction
  6290. if((access(TempStopTransaction,F_OK))!=-1)
  6291. {
  6292. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6293. }
  6294. #endif
  6295. #if 1
  6296. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6297. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6298. {
  6299. result = PASS;
  6300. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6301. }
  6302. #endif
  6303. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6304. OCPP_insert_transaction_msg(NO, queuedata);
  6305. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6306. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  6307. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  6308. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6309. {
  6310. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  6311. }
  6312. //for test
  6313. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6314. return result;
  6315. }
  6316. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6317. {
  6318. mtrace();
  6319. int result = FAIL;
  6320. char guid[37]={0};
  6321. char tempdata[65]={0};
  6322. int tempIndex = 0;
  6323. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6324. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6325. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6326. //set value
  6327. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6328. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6329. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  6330. -1);
  6331. random_uuid(guid);
  6332. //UTC Date time
  6333. struct timeval tmnow;
  6334. struct tm *tm;
  6335. char buf[28];//, usec_buf[6];
  6336. gettimeofday(&tmnow, NULL);
  6337. time_t t;
  6338. t = time(NULL);
  6339. /*UTC time and date*/
  6340. tm = gmtime(&t);
  6341. if(dataType == ReadingContext_Sample_Clock)
  6342. {
  6343. struct tm *tmTarget;
  6344. struct timeb tbTarget;
  6345. tbTarget.time = mktime(tm);
  6346. tbTarget.time -= (atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6347. tmTarget = gmtime(&tbTarget.time);
  6348. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6349. }
  6350. else
  6351. {
  6352. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6353. }
  6354. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6355. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6356. //********************************(1)Current.Import L1************************************************/
  6357. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6358. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6359. (dataType == ReadingContext_Trigger))
  6360. {
  6361. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6362. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6363. {
  6364. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6365. {
  6366. tempIndex = ((gun_index==2) ? 1: 0);
  6367. }
  6368. else
  6369. {
  6370. tempIndex = gun_index;
  6371. }
  6372. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6373. {
  6374. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6375. {
  6376. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6377. }
  6378. }
  6379. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6380. }
  6381. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6382. {
  6383. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6384. {
  6385. tempIndex = ((gun_index==2) ? 1: 0);
  6386. }
  6387. else
  6388. {
  6389. tempIndex = gun_index;
  6390. }
  6391. for (int index = 0; index < CCS_QUANTITY; index++)
  6392. {
  6393. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6394. {
  6395. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6396. }
  6397. }
  6398. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6399. }
  6400. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6401. {
  6402. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6403. {
  6404. tempIndex = ((gun_index==2) ? 1: 0);
  6405. }
  6406. else
  6407. {
  6408. tempIndex = gun_index;
  6409. }
  6410. for (int index = 0; index < GB_QUANTITY; index++)
  6411. {
  6412. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6413. {
  6414. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6415. }
  6416. }
  6417. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6418. }
  6419. else if(gunType[gun_index] == GUN_TYPE_DO)
  6420. {
  6421. tempIndex = gun_index;
  6422. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6423. {
  6424. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6425. {
  6426. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6427. }
  6428. }
  6429. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6430. }
  6431. else
  6432. {
  6433. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6434. {
  6435. tempIndex = 2;
  6436. }
  6437. else
  6438. {
  6439. tempIndex = gun_index;
  6440. }
  6441. for (int index = 0; index < AC_QUANTITY; index++)
  6442. {
  6443. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6444. {
  6445. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6446. }
  6447. }
  6448. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6449. }
  6450. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6451. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6452. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6453. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6454. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6455. }
  6456. //********************************(2)Energy.Active.Import.Register ************************************************/
  6457. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6458. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6459. (dataType == ReadingContext_Trigger))
  6460. {
  6461. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6462. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6463. {
  6464. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6465. {
  6466. tempIndex = ((gun_index==2) ? 1: 0);
  6467. }
  6468. else
  6469. {
  6470. tempIndex = gun_index;
  6471. }
  6472. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6473. {
  6474. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6475. {
  6476. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6477. }
  6478. }
  6479. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6480. }
  6481. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6482. {
  6483. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6484. {
  6485. tempIndex = ((gun_index==2) ? 1: 0);
  6486. }
  6487. else
  6488. {
  6489. tempIndex = gun_index;
  6490. }
  6491. for (int index = 0; index < CCS_QUANTITY; index++)
  6492. {
  6493. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6494. {
  6495. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6496. }
  6497. }
  6498. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6499. }
  6500. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6501. {
  6502. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6503. {
  6504. tempIndex = ((gun_index==2) ? 1: 0);
  6505. }
  6506. else
  6507. {
  6508. tempIndex = gun_index;
  6509. }
  6510. for (int index = 0; index < GB_QUANTITY; index++)
  6511. {
  6512. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6513. {
  6514. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6515. }
  6516. }
  6517. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6518. }
  6519. else if(gunType[gun_index] == GUN_TYPE_DO)
  6520. {
  6521. tempIndex = gun_index;
  6522. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6523. {
  6524. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6525. {
  6526. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6527. }
  6528. }
  6529. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6530. }
  6531. else
  6532. {
  6533. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6534. {
  6535. tempIndex = 2;
  6536. }
  6537. else
  6538. {
  6539. tempIndex = gun_index;
  6540. }
  6541. for (int index = 0; index < AC_QUANTITY; index++)
  6542. {
  6543. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6544. {
  6545. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6546. }
  6547. }
  6548. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6549. }
  6550. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6551. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6552. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6553. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6554. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6555. }
  6556. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6557. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6558. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6559. (dataType == ReadingContext_Trigger))
  6560. {
  6561. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6562. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6563. {
  6564. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6565. {
  6566. tempIndex = ((gun_index==2) ? 1: 0);
  6567. }
  6568. else
  6569. {
  6570. tempIndex = gun_index;
  6571. }
  6572. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6573. {
  6574. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6575. {
  6576. if(dataType == ReadingContext_Sample_Clock)
  6577. {
  6578. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6579. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6580. }
  6581. else if(dataType == ReadingContext_Sample_Periodic)
  6582. {
  6583. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6584. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6585. }
  6586. else
  6587. {
  6588. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6589. }
  6590. }
  6591. } // END OF FOR CHAdeMO_QUANTITY
  6592. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6593. }
  6594. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6595. {
  6596. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6597. {
  6598. tempIndex = ((gun_index==2) ? 1: 0);
  6599. }
  6600. else
  6601. {
  6602. tempIndex = gun_index;
  6603. }
  6604. for (int index = 0; index < CCS_QUANTITY; index++)
  6605. {
  6606. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6607. {
  6608. if(dataType == ReadingContext_Sample_Clock)
  6609. {
  6610. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6611. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6612. }
  6613. else if(dataType == ReadingContext_Sample_Periodic)
  6614. {
  6615. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6616. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6617. }
  6618. else
  6619. {
  6620. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6621. }
  6622. }
  6623. } // END OF CCS_QUANTITY
  6624. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6625. }
  6626. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6627. {
  6628. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6629. {
  6630. tempIndex = ((gun_index==2) ? 1: 0);
  6631. }
  6632. else
  6633. {
  6634. tempIndex = gun_index;
  6635. }
  6636. for (int index = 0; index < GB_QUANTITY; index++)
  6637. {
  6638. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6639. {
  6640. if(dataType == ReadingContext_Sample_Clock)
  6641. {
  6642. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6643. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6644. }
  6645. else if(dataType == ReadingContext_Sample_Periodic)
  6646. {
  6647. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6648. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6649. }
  6650. else
  6651. {
  6652. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6653. }
  6654. }
  6655. } // END OF GB_QUANTITY
  6656. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6657. }
  6658. else if(gunType[gun_index] == GUN_TYPE_DO)
  6659. {
  6660. tempIndex = gun_index;
  6661. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6662. {
  6663. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6664. {
  6665. if(dataType == ReadingContext_Sample_Clock)
  6666. {
  6667. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]));
  6668. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6669. }
  6670. else if(dataType == ReadingContext_Sample_Periodic)
  6671. {
  6672. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6673. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6674. }
  6675. else
  6676. {
  6677. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6678. }
  6679. }
  6680. }
  6681. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6682. }
  6683. else
  6684. {
  6685. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6686. {
  6687. tempIndex = 2;
  6688. }
  6689. else
  6690. {
  6691. tempIndex = gun_index;
  6692. }
  6693. for (int index = 0; index < AC_QUANTITY; index++)
  6694. {
  6695. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6696. {
  6697. if(dataType == ReadingContext_Sample_Clock)
  6698. {
  6699. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  6700. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6701. }
  6702. else if(dataType == ReadingContext_Sample_Periodic)
  6703. {
  6704. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  6705. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6706. }
  6707. else
  6708. {
  6709. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  6710. }
  6711. }
  6712. }
  6713. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6714. }
  6715. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6716. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6717. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6718. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6719. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6720. }
  6721. //********************************(4)Power.Active.Import************************************************/
  6722. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6723. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6724. (dataType == ReadingContext_Trigger))
  6725. {
  6726. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6727. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6728. {
  6729. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6730. {
  6731. tempIndex = ((gun_index==2) ? 1: 0);
  6732. }
  6733. else
  6734. {
  6735. tempIndex = gun_index;
  6736. }
  6737. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6738. {
  6739. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6740. {
  6741. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6742. }
  6743. } // END OF FOR
  6744. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6745. }
  6746. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6747. {
  6748. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6749. {
  6750. tempIndex = ((gun_index==2) ? 1: 0);
  6751. }
  6752. else
  6753. {
  6754. tempIndex = gun_index;
  6755. }
  6756. for (int index = 0; index < CCS_QUANTITY; index++)
  6757. {
  6758. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6759. {
  6760. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6761. }
  6762. }
  6763. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6764. }
  6765. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6766. {
  6767. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6768. {
  6769. tempIndex = ((gun_index==2) ? 1: 0);
  6770. }
  6771. else
  6772. {
  6773. tempIndex = gun_index;
  6774. }
  6775. for (int index = 0; index < GB_QUANTITY; index++)
  6776. {
  6777. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6778. {
  6779. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6780. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6781. }
  6782. }
  6783. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6784. }
  6785. else if(gunType[gun_index] == GUN_TYPE_DO)
  6786. {
  6787. tempIndex = gun_index;
  6788. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6789. {
  6790. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6791. {
  6792. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6793. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6794. }
  6795. }
  6796. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6797. }
  6798. else
  6799. {
  6800. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6801. {
  6802. tempIndex = 2;
  6803. }
  6804. else
  6805. {
  6806. tempIndex = gun_index;
  6807. }
  6808. for (int index = 0; index < AC_QUANTITY; index++)
  6809. {
  6810. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6811. {
  6812. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6813. }
  6814. }
  6815. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6816. }
  6817. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6818. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6819. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6820. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6821. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6822. }
  6823. //***********************************************(5)VOLTAGE L1******************************************************/
  6824. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6825. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6826. (dataType == ReadingContext_Trigger))
  6827. {
  6828. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6829. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6830. {
  6831. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6832. {
  6833. tempIndex = ((gun_index==2) ? 1: 0);
  6834. }
  6835. else
  6836. {
  6837. tempIndex = gun_index;
  6838. }
  6839. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6840. {
  6841. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6842. {
  6843. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6844. }
  6845. }
  6846. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6847. }
  6848. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6849. {
  6850. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6851. {
  6852. tempIndex = ((gun_index==2) ? 1: 0);
  6853. }
  6854. else
  6855. {
  6856. tempIndex = gun_index;
  6857. }
  6858. for (int index = 0; index < CCS_QUANTITY; index++)
  6859. {
  6860. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6861. {
  6862. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6863. }
  6864. }
  6865. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6866. }
  6867. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6868. {
  6869. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6870. {
  6871. tempIndex = ((gun_index==2) ? 1: 0);
  6872. }
  6873. else
  6874. {
  6875. tempIndex = gun_index;
  6876. }
  6877. for (int index = 0; index < GB_QUANTITY; index++)
  6878. {
  6879. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6880. {
  6881. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6882. }
  6883. }
  6884. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6885. }
  6886. else if(gunType[gun_index] == GUN_TYPE_DO)
  6887. {
  6888. tempIndex = gun_index;
  6889. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6890. {
  6891. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6892. {
  6893. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6894. }
  6895. }
  6896. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6897. }
  6898. else
  6899. {
  6900. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6901. {
  6902. tempIndex = 2;
  6903. }
  6904. else
  6905. {
  6906. tempIndex = gun_index;
  6907. }
  6908. for (int index = 0; index < AC_QUANTITY; index++)
  6909. {
  6910. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6911. {
  6912. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6913. }
  6914. }
  6915. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6916. }
  6917. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6918. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6919. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6920. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6921. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6922. }
  6923. //***********************************************(6)SOC******************************************************/
  6924. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6925. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6926. (dataType == ReadingContext_Trigger))
  6927. {
  6928. 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))
  6929. {
  6930. //idx_sample=5;
  6931. //sampledValue = NULL;
  6932. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6933. {
  6934. tempIndex = ((gun_index==2) ? 1: 0);
  6935. }
  6936. else
  6937. {
  6938. tempIndex = gun_index;
  6939. }
  6940. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6941. {
  6942. //tempIndex = ((gun_index==2) ? 1: 0);
  6943. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6944. {
  6945. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6946. {
  6947. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6948. }
  6949. }
  6950. }
  6951. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6952. {
  6953. //tempIndex = ((gun_index==2) ? 1: 0);
  6954. for (int index = 0; index < CCS_QUANTITY; index++)
  6955. {
  6956. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6957. {
  6958. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6959. }
  6960. }
  6961. }
  6962. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6963. {
  6964. //tempIndex = ((gun_index==2) ? 1: 0);
  6965. for (int index = 0; index < GB_QUANTITY; index++)
  6966. {
  6967. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6968. {
  6969. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6970. }
  6971. }
  6972. }
  6973. else if(gunType[gun_index] == GUN_TYPE_DO)
  6974. {
  6975. //tempIndex = ((gun_index==2) ? 1: 0);
  6976. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6977. {
  6978. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6979. {
  6980. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6981. }
  6982. }
  6983. }
  6984. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6985. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6986. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6987. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6988. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6989. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6990. }
  6991. }
  6992. //********************************(7)Current.Import L2************************************************/
  6993. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6994. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6995. (dataType == ReadingContext_Trigger))
  6996. {
  6997. // Only for AC 3 phase
  6998. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6999. {
  7000. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7001. {
  7002. tempIndex = 2;
  7003. }
  7004. else
  7005. {
  7006. tempIndex = gun_index;
  7007. }
  7008. for (int index = 0; index < AC_QUANTITY; index++)
  7009. {
  7010. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7011. {
  7012. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7013. }
  7014. }
  7015. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7016. }
  7017. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7018. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7019. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7020. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7021. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7022. }
  7023. //********************************(8)Current.Import L3************************************************/
  7024. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7025. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7026. (dataType == ReadingContext_Trigger))
  7027. {
  7028. // Only for AC 3 phase
  7029. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7030. {
  7031. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7032. {
  7033. tempIndex = 2;
  7034. }
  7035. else
  7036. {
  7037. tempIndex = gun_index;
  7038. }
  7039. for (int index = 0; index < AC_QUANTITY; index++)
  7040. {
  7041. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7042. {
  7043. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7044. }
  7045. }
  7046. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7047. }
  7048. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7049. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7050. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7051. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7052. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7053. }
  7054. //***********************************************(9)VOLTAGE L2******************************************************/
  7055. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7056. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7057. (dataType == ReadingContext_Trigger))
  7058. {
  7059. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7060. {
  7061. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7062. {
  7063. tempIndex = 2;
  7064. }
  7065. else
  7066. {
  7067. tempIndex = gun_index;
  7068. }
  7069. for (int index = 0; index < AC_QUANTITY; index++)
  7070. {
  7071. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7072. {
  7073. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7074. }
  7075. }
  7076. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7077. }
  7078. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7079. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7080. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7081. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7082. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7083. }
  7084. //***********************************************(10)VOLTAGE L3******************************************************/
  7085. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7086. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7087. (dataType == ReadingContext_Trigger))
  7088. {
  7089. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7090. {
  7091. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7092. {
  7093. tempIndex = 2;
  7094. }
  7095. else
  7096. {
  7097. tempIndex = gun_index;
  7098. }
  7099. for (int index = 0; index < AC_QUANTITY; index++)
  7100. {
  7101. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7102. {
  7103. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7104. }
  7105. }
  7106. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7107. }
  7108. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7109. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7110. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7111. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7112. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7113. }
  7114. //***********************************************(11)Current.Offered******************************************************/
  7115. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7116. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7117. (dataType == ReadingContext_Trigger))
  7118. {
  7119. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7120. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7121. {
  7122. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7123. {
  7124. tempIndex = ((gun_index==2) ? 1: 0);
  7125. }
  7126. else
  7127. {
  7128. tempIndex = gun_index;
  7129. }
  7130. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7131. {
  7132. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7133. {
  7134. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  7135. }
  7136. } // END OF FOR CHAdeMO_QUANTITY
  7137. }
  7138. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7139. {
  7140. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7141. {
  7142. tempIndex = ((gun_index==2) ? 1: 0);
  7143. }
  7144. else
  7145. {
  7146. tempIndex = gun_index;
  7147. }
  7148. for (int index = 0; index < CCS_QUANTITY; index++)
  7149. {
  7150. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7151. {
  7152. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  7153. }
  7154. } // END OF CCS_QUANTITY
  7155. }
  7156. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7157. {
  7158. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7159. {
  7160. tempIndex = ((gun_index==2) ? 1: 0);
  7161. }
  7162. else
  7163. {
  7164. tempIndex = gun_index;
  7165. }
  7166. for (int index = 0; index < GB_QUANTITY; index++)
  7167. {
  7168. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7169. {
  7170. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  7171. }
  7172. } // END OF GB_QUANTITY
  7173. }
  7174. else if(gunType[gun_index] == GUN_TYPE_DO)
  7175. {
  7176. tempIndex = gun_index;
  7177. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7178. {
  7179. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7180. {
  7181. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  7182. }
  7183. }
  7184. }
  7185. else
  7186. {
  7187. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7188. {
  7189. tempIndex = 2;
  7190. }
  7191. else
  7192. {
  7193. tempIndex = gun_index;
  7194. }
  7195. for (int index = 0; index < AC_QUANTITY; index++)
  7196. {
  7197. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7198. {
  7199. uint16_t currentOffer;
  7200. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7201. {
  7202. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7203. }
  7204. else
  7205. {
  7206. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7207. }
  7208. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7209. }
  7210. }
  7211. }
  7212. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7213. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7214. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7215. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7216. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7217. }
  7218. //***********************************************(12)Power.Offered******************************************************/
  7219. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7220. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7221. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7222. {
  7223. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7224. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7225. {
  7226. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7227. {
  7228. tempIndex = ((gun_index==2) ? 1: 0);
  7229. }
  7230. else
  7231. {
  7232. tempIndex = gun_index;
  7233. }
  7234. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7235. {
  7236. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7237. {
  7238. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  7239. }
  7240. } // END OF FOR CHAdeMO_QUANTITY
  7241. }
  7242. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7243. {
  7244. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7245. {
  7246. tempIndex = ((gun_index==2) ? 1: 0);
  7247. }
  7248. else
  7249. {
  7250. tempIndex = gun_index;
  7251. }
  7252. for (int index = 0; index < CCS_QUANTITY; index++)
  7253. {
  7254. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7255. {
  7256. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  7257. }
  7258. } // END OF CCS_QUANTITY
  7259. }
  7260. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7261. {
  7262. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7263. {
  7264. tempIndex = ((gun_index==2) ? 1: 0);
  7265. }
  7266. else
  7267. {
  7268. tempIndex = gun_index;
  7269. }
  7270. for (int index = 0; index < GB_QUANTITY; index++)
  7271. {
  7272. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7273. {
  7274. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  7275. }
  7276. } // END OF GB_QUANTITY
  7277. }
  7278. else if(gunType[gun_index] == GUN_TYPE_DO)
  7279. {
  7280. tempIndex = gun_index;
  7281. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7282. {
  7283. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7284. {
  7285. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  7286. }
  7287. }
  7288. }
  7289. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7290. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7291. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7292. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7293. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7294. }
  7295. // Message create ====================================================================================================
  7296. if(TRUE)
  7297. {
  7298. json_object *MeterValueReq = json_object_new_object();
  7299. json_object *MeterValues = json_object_new_array();
  7300. json_object *sampledValues = json_object_new_array();
  7301. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  7302. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  7303. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  7304. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  7305. {
  7306. json_object *MeterValue = json_object_new_object();
  7307. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7308. {
  7309. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7310. {
  7311. json_object *sampledValue = json_object_new_object();
  7312. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7313. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7314. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7315. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7316. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7317. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7318. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7319. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7320. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7321. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7322. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7323. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7324. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7325. json_object_array_add(sampledValues, sampledValue);
  7326. }
  7327. }
  7328. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7329. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7330. json_object_array_add(MeterValues, MeterValue);
  7331. }
  7332. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7333. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7334. ,gun_index + 1
  7335. ,MESSAGE_TYPE_CALL
  7336. ,guid
  7337. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7338. json_object_put(MeterValueReq);
  7339. }
  7340. // Put request guid to hash map
  7341. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7342. 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*/)
  7343. {
  7344. result = PASS;
  7345. //DEBUG_INFO("MeterValues mapitem pass\n");
  7346. }
  7347. if((dataType != ReadingContext_Trigger) &&
  7348. (dataType != ReadingContext_Sample_Clock) &&
  7349. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7350. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7351. else
  7352. {
  7353. if(FirstHeartBeat)
  7354. LWS_Send(queuedata +2);
  7355. }
  7356. return result;
  7357. }
  7358. int sendLogStatusNotificationRequest(char *status)
  7359. {
  7360. mtrace();
  7361. int result = PASS;
  7362. char message[4096]={0};
  7363. char guid[37]={0};
  7364. char tempdata[128]={0};
  7365. json_object *LogStatusNotification = json_object_new_object();
  7366. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7367. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  7368. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  7369. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  7370. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  7371. random_uuid(guid);
  7372. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7373. json_object_put(LogStatusNotification);
  7374. LWS_Send(message);
  7375. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7376. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7377. {
  7378. result = PASS;
  7379. }
  7380. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  7381. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  7382. return result;
  7383. }
  7384. int sendSecurityEventNotificationRequest()
  7385. {
  7386. mtrace();
  7387. int result = PASS;
  7388. char message[4096]={0};
  7389. char guid[37]={0};
  7390. char tempdata[128]={0};
  7391. json_object *SecurityEventNotification = json_object_new_object();
  7392. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7393. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  7394. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  7395. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  7396. random_uuid(guid);
  7397. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7398. json_object_put(SecurityEventNotification);
  7399. LWS_Send(message);
  7400. sprintf(tempdata, "SecurityEventNotification,0");
  7401. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7402. {
  7403. result = PASS;
  7404. }
  7405. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  7406. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  7407. return result;
  7408. }
  7409. int sendSignCertificateRequest()
  7410. {
  7411. mtrace();
  7412. int result = PASS;
  7413. char message[4096]={0};
  7414. char guid[37]={0};
  7415. char tempdata[128]={0};
  7416. json_object *SignCertificate = json_object_new_object();
  7417. DEBUG_INFO("sendSignCertificateRequest...\n");
  7418. // Read csr file content
  7419. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  7420. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  7421. char *line = NULL;
  7422. size_t len = 0;
  7423. while(getline(&line, &len, fp) != -1)
  7424. {
  7425. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7426. {
  7427. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  7428. }
  7429. }
  7430. fclose(fp);
  7431. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  7432. random_uuid(guid);
  7433. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7434. json_object_put(SignCertificate);
  7435. LWS_Send(message);
  7436. sprintf(tempdata, "SignCertificate,0");
  7437. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7438. {
  7439. result = PASS;
  7440. }
  7441. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  7442. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  7443. return result;
  7444. }
  7445. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7446. {
  7447. mtrace();
  7448. int result = PASS;
  7449. char message[110]={0};
  7450. char guid[37]={0};
  7451. char tempdata[65]={0};
  7452. json_object *FirmwareStatusNotification = json_object_new_object();
  7453. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7454. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7455. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  7456. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  7457. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  7458. random_uuid(guid);
  7459. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7460. json_object_put(FirmwareStatusNotification);
  7461. LWS_Send(message);
  7462. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7463. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7464. {
  7465. result = PASS;
  7466. }
  7467. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7468. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7469. return result;
  7470. }
  7471. //==========================================
  7472. // send confirm routine
  7473. //==========================================
  7474. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7475. {
  7476. mtrace();
  7477. int result = FAIL;
  7478. char message[100]={0};
  7479. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7480. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7481. LWS_Send(message);
  7482. result = TRUE;
  7483. return result;
  7484. }
  7485. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7486. {
  7487. mtrace();
  7488. int result = FAIL;
  7489. char message[100]={0};
  7490. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7491. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7492. LWS_Send(message);
  7493. result = TRUE;
  7494. return result;
  7495. }
  7496. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7497. {
  7498. mtrace();
  7499. int result = FAIL;
  7500. char message[100]={0};
  7501. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7502. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7503. LWS_Send(message);
  7504. result = TRUE;
  7505. return result;
  7506. }
  7507. int sendClearCacheConfirmation(char *uuid,char *payload)
  7508. {
  7509. mtrace();
  7510. int result = FAIL;
  7511. char message[500]={0};
  7512. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7513. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7514. LWS_Send(message);
  7515. return result;
  7516. }
  7517. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7518. {
  7519. mtrace();
  7520. int result = FAIL;
  7521. char message[500]={0};
  7522. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7523. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7524. LWS_Send(message);
  7525. return result;
  7526. }
  7527. int sendDataTransferConfirmation(char *uuid,char *payload)
  7528. {
  7529. mtrace();
  7530. char statusStr[20]={0};
  7531. char dataStr[10]={0};
  7532. char sstr[20]={0};
  7533. int c = 0;
  7534. char *loc;
  7535. int result = FAIL;
  7536. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7537. /**********************status**************************/
  7538. loc = strstr(payload, "status");
  7539. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7540. c = 0;
  7541. while (loc[3+strlen("status")+c] != '\"')
  7542. {
  7543. sstr[c] = loc[3+strlen("status")+c];
  7544. c++;
  7545. }
  7546. sstr[c] = '\0';
  7547. strcpy(statusStr, sstr);
  7548. /**********************data**************************/
  7549. loc = strstr(payload, "data");
  7550. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7551. c = 0;
  7552. while (loc[3+strlen("data")+c] != '\"')
  7553. {
  7554. sstr[c] = loc[3+strlen("data")+c];
  7555. c++;
  7556. }
  7557. sstr[c] = '\0';
  7558. strcpy(dataStr, sstr);
  7559. return result;
  7560. }
  7561. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7562. {
  7563. mtrace();
  7564. int result = FAIL;
  7565. char message[1000]={0};
  7566. int CompositeScheduleIndex = 0;
  7567. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7568. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7569. if(nPeriod == 0)
  7570. {
  7571. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7572. {
  7573. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7574. ,MESSAGE_TYPE_CALLRESULT
  7575. ,uuid
  7576. ,payload
  7577. ,connectorIdInt);
  7578. }
  7579. else
  7580. {
  7581. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  7582. ,MESSAGE_TYPE_CALLRESULT
  7583. ,uuid
  7584. ,payload
  7585. ,connectorIdInt
  7586. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7587. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7588. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7589. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7590. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7591. }
  7592. }
  7593. else
  7594. {
  7595. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7596. ,MESSAGE_TYPE_CALLRESULT
  7597. ,uuid
  7598. ,payload
  7599. ,connectorIdInt
  7600. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7601. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7602. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7603. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7604. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7605. {
  7606. if (idx_sample == 0)
  7607. {
  7608. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7609. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7610. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7611. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7612. }
  7613. else
  7614. {
  7615. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7616. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7617. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7618. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7619. }
  7620. }
  7621. sprintf(message + strlen(message), "]}}]");
  7622. }
  7623. LWS_Send(message);
  7624. result = TRUE;
  7625. return result;
  7626. }
  7627. int sendGetConfigurationConfirmation(char *uuid)
  7628. {
  7629. mtrace();
  7630. int result = FAIL;
  7631. int MaxKeySupported = 0;
  7632. int sentConfigurationNumber= 0;
  7633. int sentunConfigurationNumber= 0;
  7634. char message[1024*10]={0};
  7635. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7636. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7637. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  7638. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7639. ,MESSAGE_TYPE_CALLRESULT
  7640. ,uuid );
  7641. //configuration key
  7642. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7643. {
  7644. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7645. {
  7646. if (sentConfigurationNumber == 0)
  7647. {
  7648. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7649. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7650. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7651. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7652. }
  7653. else
  7654. {
  7655. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7656. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7657. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7658. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7659. }
  7660. sentConfigurationNumber = sentConfigurationNumber + 1;
  7661. }
  7662. }
  7663. sprintf(message + strlen(message), "]");
  7664. if(UnknownKeynum != 0)
  7665. {
  7666. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7667. //unkown key
  7668. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7669. {
  7670. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7671. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7672. if(sentunConfigurationNumber == 0)
  7673. {
  7674. sprintf(message + strlen(message), "\"%s\""
  7675. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7676. }
  7677. else
  7678. {
  7679. sprintf(message + strlen(message), ",\"%s\""
  7680. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7681. }
  7682. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7683. }
  7684. sprintf(message + strlen(message), "]");
  7685. }
  7686. sprintf(message + strlen(message), "}]");
  7687. LWS_Send(message);
  7688. return result;
  7689. }
  7690. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7691. {
  7692. mtrace();
  7693. int result = FAIL;
  7694. char message[400]={0};
  7695. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7696. if(strcmp(payload,"")==0)
  7697. {
  7698. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7699. }
  7700. else
  7701. {
  7702. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7703. }
  7704. LWS_Send(message);
  7705. result = TRUE;
  7706. return result;
  7707. }
  7708. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7709. {
  7710. mtrace();
  7711. int result = FAIL;
  7712. char message[80]={0};
  7713. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7714. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  7715. LWS_Send(message);
  7716. result = TRUE;
  7717. return result;
  7718. }
  7719. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7720. {
  7721. mtrace();
  7722. int result = FAIL;
  7723. char message[80]={0};
  7724. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7725. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7726. LWS_Send(message);
  7727. result = TRUE;
  7728. return result;
  7729. }
  7730. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7731. {
  7732. mtrace();
  7733. int result = FAIL;
  7734. char message[80]={0};
  7735. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7736. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7737. LWS_Send(message);
  7738. result = TRUE;
  7739. return result;
  7740. }
  7741. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7742. {
  7743. mtrace();
  7744. int result = FAIL;
  7745. char message[80]={0};
  7746. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7747. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7748. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7749. LWS_Send(message);
  7750. result = TRUE;
  7751. return result;
  7752. }
  7753. int sendResetConfirmation(char *uuid,char *payload)
  7754. {
  7755. mtrace();
  7756. int result = FAIL;
  7757. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7758. char message[80]={0};
  7759. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  7760. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7761. LWS_Send(message);
  7762. result = TRUE;
  7763. return result;
  7764. }
  7765. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7766. {
  7767. mtrace();
  7768. int result = FAIL;
  7769. char message[500]={0};
  7770. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7771. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7772. LWS_Send(message);
  7773. result = TRUE;
  7774. return result;
  7775. }
  7776. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7777. {
  7778. mtrace();
  7779. int result = FAIL;
  7780. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7781. char message[80]={0};
  7782. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7783. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7784. LWS_Send(message);
  7785. result = TRUE;
  7786. return result;
  7787. }
  7788. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7789. {
  7790. mtrace();
  7791. int result = FAIL;
  7792. char message[80]={0};
  7793. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7794. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7795. LWS_Send(message);
  7796. result = TRUE;
  7797. return result;
  7798. }
  7799. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7800. {
  7801. mtrace();
  7802. int result = FAIL;
  7803. char message[80]={0};
  7804. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7805. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7806. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7807. LWS_Send(message);
  7808. result = TRUE;
  7809. return result;
  7810. }
  7811. int sendUpdateFirmwareConfirmation(char *uuid)
  7812. {
  7813. mtrace();
  7814. int result = FAIL;
  7815. char message[60]={0};
  7816. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7817. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7818. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7819. LWS_Send(message);
  7820. result = TRUE;
  7821. return result;
  7822. }
  7823. int sendCertificateSignedConfirmation(char *uuid)
  7824. {
  7825. mtrace();
  7826. int result = PASS;
  7827. char message[4096]={0};
  7828. json_object *CertificateSigned = json_object_new_object();
  7829. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7830. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  7831. sprintf(message,"[%d,\"%s\",%s]"
  7832. ,MESSAGE_TYPE_CALLRESULT
  7833. ,uuid
  7834. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7835. json_object_put(CertificateSigned);
  7836. LWS_Send(message);
  7837. return result;
  7838. }
  7839. int sendDeleteCertificateConfirmation(char *uuid)
  7840. {
  7841. mtrace();
  7842. int result = PASS;
  7843. char message[4096]={0};
  7844. json_object *DeleteCertificate = json_object_new_object();
  7845. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7846. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  7847. sprintf(message,"[%d,\"%s\",%s]"
  7848. ,MESSAGE_TYPE_CALLRESULT
  7849. ,uuid
  7850. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7851. json_object_put(DeleteCertificate);
  7852. LWS_Send(message);
  7853. return result;
  7854. }
  7855. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7856. {
  7857. mtrace();
  7858. int result = PASS;
  7859. char message[4096]={0};
  7860. json_object *ExtendedTriggerMessage = json_object_new_object();
  7861. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7862. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7863. sprintf(message,"[%d,\"%s\",%s]"
  7864. ,MESSAGE_TYPE_CALLRESULT
  7865. ,uuid
  7866. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7867. json_object_put(ExtendedTriggerMessage);
  7868. LWS_Send(message);
  7869. return result;
  7870. }
  7871. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7872. {
  7873. mtrace();
  7874. int result = PASS;
  7875. char message[4096]={0};
  7876. json_object *GetInstalledCertificateIds = json_object_new_object();
  7877. json_object *certificateHashDataDatas = json_object_new_array();
  7878. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7879. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7880. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7881. {
  7882. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7883. {
  7884. json_object *certificateHashData = json_object_new_object();
  7885. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7886. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7887. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7888. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7889. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7890. }
  7891. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7892. }
  7893. else
  7894. {
  7895. json_object_put(certificateHashDataDatas);
  7896. }
  7897. sprintf(message,"[%d,\"%s\",%s]"
  7898. ,MESSAGE_TYPE_CALLRESULT
  7899. ,uuid
  7900. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7901. json_object_put(GetInstalledCertificateIds);
  7902. LWS_Send(message);
  7903. return result;
  7904. }
  7905. int sendGetLogConfirmation(char *uuid)
  7906. {
  7907. mtrace();
  7908. int result = PASS;
  7909. char message[4096]={0};
  7910. json_object *GetLog = json_object_new_object();
  7911. DEBUG_INFO("sendGetLogConfirmation...\n");
  7912. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7913. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7914. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7915. sprintf(message,"[%d,\"%s\",%s]"
  7916. ,MESSAGE_TYPE_CALLRESULT
  7917. ,uuid
  7918. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7919. json_object_put(GetLog);
  7920. LWS_Send(message);
  7921. return result;
  7922. }
  7923. int sendInstallCertificateConfirmation(char *uuid)
  7924. {
  7925. mtrace();
  7926. int result = PASS;
  7927. char message[4096]={0};
  7928. json_object *InstallCertificate = json_object_new_object();
  7929. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7930. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7931. sprintf(message,"[%d,\"%s\",%s]"
  7932. ,MESSAGE_TYPE_CALLRESULT
  7933. ,uuid
  7934. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7935. json_object_put(InstallCertificate);
  7936. LWS_Send(message);
  7937. return result;
  7938. }
  7939. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7940. {
  7941. mtrace();
  7942. int result = PASS;
  7943. char message[4096]={0};
  7944. json_object *SignedUpdateFirmware = json_object_new_object();
  7945. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7946. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7947. sprintf(message,"[%d,\"%s\",%s]"
  7948. ,MESSAGE_TYPE_CALLRESULT
  7949. ,uuid
  7950. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7951. json_object_put(SignedUpdateFirmware);
  7952. LWS_Send(message);
  7953. return result;
  7954. }
  7955. int sendUnknownConfirmation(char *uuid)
  7956. {
  7957. mtrace();
  7958. int result = PASS;
  7959. char message[256]={0};
  7960. DEBUG_INFO("sendUnknownConfirmation...\n");
  7961. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7962. LWS_Send(message);
  7963. return result;
  7964. }
  7965. //==========================================
  7966. // Handle server request routine Start
  7967. //==========================================
  7968. int handleCancelReservationRequest(char *uuid, char *payload)
  7969. {
  7970. mtrace();
  7971. int result = FAIL;
  7972. int gunNO = 0;
  7973. int reservationIdInt = -1;
  7974. char comfirmstr[20];
  7975. DEBUG_INFO("handleCancelReservationRequest...\n");
  7976. json_object *CancelReservation;
  7977. CancelReservation = json_tokener_parse(payload);
  7978. if(!is_error(CancelReservation))
  7979. {
  7980. // Required data
  7981. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7982. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7983. }
  7984. json_object_put(CancelReservation);
  7985. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7986. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7987. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7988. if(reservationIdInt != -1)
  7989. {
  7990. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7991. //check Transaction active
  7992. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7993. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7994. {
  7995. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7996. {
  7997. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7998. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7999. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8000. {
  8001. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8002. }
  8003. else
  8004. {
  8005. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8006. }
  8007. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8008. goto end;
  8009. }
  8010. }
  8011. for (int index = 0; index < CCS_QUANTITY; index++)
  8012. {
  8013. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8014. {
  8015. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8016. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8017. if(gunType[2] == GUN_TYPE_CCS)
  8018. {
  8019. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8020. }
  8021. else
  8022. {
  8023. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8024. }
  8025. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8026. goto end;
  8027. }
  8028. }
  8029. for (int index = 0; index < GB_QUANTITY; index++)
  8030. {
  8031. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8032. {
  8033. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8034. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8035. if(gunType[2] == GUN_TYPE_GBT)
  8036. {
  8037. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8038. }
  8039. else
  8040. {
  8041. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8042. }
  8043. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8044. goto end;
  8045. }
  8046. }
  8047. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8048. {
  8049. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8050. {
  8051. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8052. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index].ResponseStatus, "%s", comfirmstr );
  8053. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8054. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8055. goto end;
  8056. }
  8057. }
  8058. for (int index = 0; index < AC_QUANTITY; index++)
  8059. {
  8060. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8061. {
  8062. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8063. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8064. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8065. {
  8066. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8067. }
  8068. else
  8069. {
  8070. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8071. }
  8072. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8073. goto end;
  8074. }
  8075. }
  8076. }
  8077. //The reservationId does NOT match the reservationId
  8078. sendCancelReservationConfirmation(uuid, comfirmstr);
  8079. end:
  8080. // Fill in ocpp packet uuid
  8081. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  8082. return result;
  8083. }
  8084. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8085. {
  8086. mtrace();
  8087. int result = FAIL;
  8088. int gunIndex = -1;
  8089. char typeStr[16]={0};
  8090. char comfirmstr[20];
  8091. int specificId = FALSE;
  8092. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8093. json_object *ChangeAvailability;
  8094. ChangeAvailability = json_tokener_parse(payload);
  8095. if(!is_error(ChangeAvailability))
  8096. {
  8097. // Required data
  8098. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8099. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8100. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8101. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8102. }
  8103. json_object_put(ChangeAvailability);
  8104. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8105. {
  8106. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8107. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8108. }
  8109. else if(gunIndex == 0)
  8110. {
  8111. for(int i=0; i < gunTotalNumber; i++)
  8112. {
  8113. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  8114. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  8115. }
  8116. }
  8117. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8118. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8119. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8120. {
  8121. specificId = TRUE;
  8122. }
  8123. if(specificId == FALSE)
  8124. goto end;
  8125. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8126. {
  8127. //----------------------gunIndex is 0 ------------------------------------------------//
  8128. if(gunIndex == 0)
  8129. {
  8130. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8131. {
  8132. for(int i=0; i < gunTotalNumber; i++)
  8133. {
  8134. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8135. {
  8136. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8137. {
  8138. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8139. {
  8140. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8141. goto end;
  8142. }
  8143. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8144. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8145. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8146. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8147. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8148. {
  8149. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8150. goto end;
  8151. }
  8152. }
  8153. }//END FOR CHAdeMO_QUANTITY
  8154. for (int index = 0; index < CCS_QUANTITY; index++)
  8155. {
  8156. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8157. {
  8158. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8159. {
  8160. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8161. goto end;
  8162. }
  8163. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8164. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8165. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8166. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8167. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8168. {
  8169. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8170. goto end;
  8171. }
  8172. }
  8173. }//END FOR CCS_QUANTITY
  8174. for (int index = 0; index < GB_QUANTITY; index++)
  8175. {
  8176. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8177. {
  8178. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8179. {
  8180. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8181. goto end;
  8182. }
  8183. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8184. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8185. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8186. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8187. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8188. {
  8189. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8190. goto end;
  8191. }
  8192. }
  8193. }// END FOR GB_QUANTITY
  8194. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8195. {
  8196. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8197. {
  8198. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8199. {
  8200. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8201. goto end;
  8202. }
  8203. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8204. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8205. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8206. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8207. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8208. {
  8209. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8210. goto end;
  8211. }
  8212. }
  8213. }// END FOR GENERAL_GUN_QUANTITY
  8214. for (int index = 0; index < AC_QUANTITY; index++)
  8215. {
  8216. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8217. {
  8218. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8219. {
  8220. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8221. goto end;
  8222. }
  8223. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8224. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8225. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8226. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8227. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8228. {
  8229. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8230. goto end;
  8231. }
  8232. }
  8233. }//END FOR AC_QUANTITY
  8234. }// END FOR gunTotalNumber
  8235. }
  8236. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8237. {
  8238. for(int i=0; i < gunTotalNumber; i++)
  8239. {
  8240. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8241. {
  8242. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8243. goto end;
  8244. }
  8245. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8246. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8247. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8248. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8249. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8250. {
  8251. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8252. goto end;
  8253. }
  8254. }
  8255. }
  8256. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8257. goto end;
  8258. }
  8259. //----------------------gunIndex is not 0 ------------------------------------------------//
  8260. //check Transaction active
  8261. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8262. {
  8263. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8264. {
  8265. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8266. {
  8267. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8268. goto end;
  8269. }
  8270. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8271. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8272. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8273. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8274. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8275. {
  8276. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8277. goto end;
  8278. }
  8279. else
  8280. {
  8281. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8282. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8283. goto end;
  8284. }
  8285. }
  8286. }//END FOR CHAdeMO_QUANTITY
  8287. for (int index = 0; index < CCS_QUANTITY; index++)
  8288. {
  8289. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8290. {
  8291. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8292. {
  8293. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8294. goto end;
  8295. }
  8296. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8297. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8298. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8299. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8300. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8301. {
  8302. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8303. goto end;
  8304. }
  8305. else
  8306. {
  8307. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8308. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8309. goto end;
  8310. }
  8311. }
  8312. }//END FOR CCS_QUANTITY
  8313. for (int index = 0; index < GB_QUANTITY; index++)
  8314. {
  8315. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8316. {
  8317. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8318. {
  8319. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8320. goto end;
  8321. }
  8322. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8323. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8324. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8325. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8326. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8327. {
  8328. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8329. goto end;
  8330. }
  8331. else
  8332. {
  8333. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8334. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8335. goto end;
  8336. }
  8337. }
  8338. }// END FOR GB_QUANTITY
  8339. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8340. {
  8341. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8342. {
  8343. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8344. {
  8345. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8346. goto end;
  8347. }
  8348. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8349. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8350. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8351. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8352. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8353. {
  8354. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8355. goto end;
  8356. }
  8357. else
  8358. {
  8359. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8360. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8361. goto end;
  8362. }
  8363. }
  8364. }// END FOR GENERAL_GUN_QUANTITY
  8365. for (int index = 0; index < AC_QUANTITY; index++)
  8366. {
  8367. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8368. {
  8369. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8370. {
  8371. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8372. goto end;
  8373. }
  8374. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8375. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8376. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8377. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8378. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8379. {
  8380. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8381. goto end;
  8382. }
  8383. else
  8384. {
  8385. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8386. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8387. goto end;
  8388. }
  8389. }
  8390. }//END FOR AC_QUANTITY
  8391. }//END FOR AvailabilityTypeStr[Inoperative]
  8392. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8393. {
  8394. //----------------------gunIndex is 0 ------------------------------------------------//
  8395. if(gunIndex == 0)
  8396. {
  8397. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8398. {
  8399. for(int i=0; i < gunTotalNumber; i++)
  8400. {
  8401. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8402. {
  8403. 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
  8404. {
  8405. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8406. goto end;
  8407. }
  8408. }//END FOR CHAdeMO_QUANTITY
  8409. for (int index = 0; index < CCS_QUANTITY; index++)
  8410. {
  8411. 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
  8412. {
  8413. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8414. goto end;
  8415. }
  8416. }//END FOR CCS_QUANTITY
  8417. for (int index = 0; index < GB_QUANTITY; index++)
  8418. {
  8419. 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
  8420. {
  8421. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8422. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8423. goto end;
  8424. }
  8425. }// END FOR GB_QUANTITY
  8426. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8427. {
  8428. 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
  8429. {
  8430. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8431. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8432. goto end;
  8433. }
  8434. }// END FOR GENERAL_GUN_QUANTITY
  8435. for (int index = 0; index < AC_QUANTITY; index++)
  8436. {
  8437. 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
  8438. {
  8439. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8440. goto end;
  8441. }
  8442. }//END FOR CHAdeMO_QUANTITY
  8443. }// END FOR gunTotalNumber
  8444. }
  8445. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8446. {
  8447. for(int i=0; i < gunTotalNumber; i++)
  8448. {
  8449. for (int index = 0; index < AC_QUANTITY; index++)
  8450. {
  8451. 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
  8452. {
  8453. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8454. goto end;
  8455. }
  8456. }//END FOR CHAdeMO_QUANTITY
  8457. } // END FOR gunTotalNumber
  8458. }
  8459. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8460. goto end;
  8461. }
  8462. //----------------------gunIndex is not 0 ------------------------------------------------//
  8463. //check Transaction active
  8464. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8465. {
  8466. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8467. {
  8468. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8469. goto end;
  8470. }
  8471. }//END FOR CHAdeMO_QUANTITY
  8472. for (int index = 0; index < CCS_QUANTITY; index++)
  8473. {
  8474. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8475. {
  8476. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8477. goto end;
  8478. }
  8479. }//END FOR CCS_QUANTITY
  8480. for (int index = 0; index < GB_QUANTITY; index++)
  8481. {
  8482. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8483. {
  8484. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8485. goto end;
  8486. }
  8487. }// END FOR GB_QUANTITY
  8488. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8489. {
  8490. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8491. {
  8492. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8493. goto end;
  8494. }
  8495. }// END FOR GENERAL_GUN_QUANTITY
  8496. for (int index = 0; index < AC_QUANTITY; index++)
  8497. {
  8498. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8499. {
  8500. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8501. goto end;
  8502. }
  8503. }//END FOR AC_QUANTITY
  8504. }//END FOR AvailabilityTypeStr[Operative]
  8505. end:
  8506. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8507. {
  8508. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8509. }
  8510. else
  8511. {
  8512. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8513. }
  8514. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8515. {
  8516. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8517. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8518. }
  8519. else if(gunIndex == 0)
  8520. {
  8521. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8522. {
  8523. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8524. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8525. }
  8526. }
  8527. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8528. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8529. return result;
  8530. }
  8531. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8532. {
  8533. mtrace();
  8534. int valueInvalid = NO;
  8535. int result = FAIL;
  8536. char keystr[40]={0};
  8537. char valuestr[501]={0}; //value should be limited in 500 bytes
  8538. char comfirmstr[20]={0};
  8539. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8540. json_object *ChangeConfiguration;
  8541. ChangeConfiguration = json_tokener_parse(payload);
  8542. if(!is_error(ChangeConfiguration))
  8543. {
  8544. // Required data
  8545. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8546. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8547. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8548. {
  8549. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8550. }
  8551. else
  8552. {
  8553. valueInvalid = YES;
  8554. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8555. }
  8556. }
  8557. json_object_put(ChangeConfiguration);
  8558. if((uuid==NULL) || (payload ==NULL) || (valueInvalid == YES))
  8559. {
  8560. DEBUG_ERROR("Payload is null or not accepted.\n");
  8561. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8562. }
  8563. else
  8564. {
  8565. int status = setKeyValue(keystr, valuestr);
  8566. switch(status)
  8567. {
  8568. case ConfigurationStatus_Accepted:
  8569. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8570. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  8571. StoreConfigurationTable();
  8572. break;
  8573. case RebootRequired:
  8574. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8575. StoreConfigurationTable();
  8576. break;
  8577. case NotSupported:
  8578. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8579. break;
  8580. case ConfigurationStatus_Rejected:
  8581. default:
  8582. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8583. break;
  8584. }
  8585. }
  8586. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8587. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  8588. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8589. {
  8590. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8591. SetOcppConnStatus(FALSE);
  8592. }
  8593. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8594. {
  8595. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8596. }
  8597. return result;
  8598. }
  8599. int handleClearCacheRequest(char *uuid, char *payload)
  8600. {
  8601. mtrace();
  8602. int result = FAIL;
  8603. char comfirmstr[20];
  8604. char rmFileCmd[100]={0};
  8605. struct stat stats;
  8606. DEBUG_INFO("handleClearCacheRequest...\n");
  8607. stat("/Storage/OCPP_PH", &stats);
  8608. // Check for directory existence
  8609. if (S_ISDIR(stats.st_mode) == 1)
  8610. {}
  8611. else
  8612. {
  8613. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8614. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  8615. system(rmFileCmd);
  8616. }
  8617. if(OCPP_cleanLocalCache())
  8618. {
  8619. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8620. }
  8621. else
  8622. {
  8623. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8624. }
  8625. sendClearCacheConfirmation(uuid, comfirmstr);
  8626. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8627. return result;
  8628. }
  8629. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8630. {
  8631. mtrace();
  8632. int result = FAIL;
  8633. int resultRename;
  8634. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8635. char chargingProfilePurposeStr[26]={0};
  8636. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8637. char tempchargingProfilePurposeStr[26]={0};
  8638. char str[100]={0};
  8639. char fname[200]={0};
  8640. char comfirmstr[20]={0};
  8641. char word[1600]={0};
  8642. int clearflag = FALSE;
  8643. int chargingProfileIdIsNULL = FALSE;
  8644. int connectorIsNULL = FALSE;
  8645. int chargingProfilePurposeIsNULL = FALSE;
  8646. int stackLevelIsNULL = FALSE;
  8647. //int GotoEnd = FALSE;
  8648. FILE *fptr1, *fptr2;
  8649. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  8650. int n_chargingProfile=0;
  8651. int isEmptyFile = FALSE;
  8652. char sLineWord[1600]={0};
  8653. char chargingProfiles[10][100]={0};
  8654. int ChargeProfileCount = 0;
  8655. int ch;
  8656. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8657. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8658. json_object *ClearChargingProfile;
  8659. ClearChargingProfile = json_tokener_parse(payload);
  8660. if(!is_error(ClearChargingProfile))
  8661. {
  8662. // Optional data
  8663. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8664. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8665. else
  8666. chargingProfileIdIsNULL = TRUE;
  8667. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8668. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8669. else
  8670. connectorIsNULL = TRUE;
  8671. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8672. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8673. else
  8674. chargingProfilePurposeIsNULL = TRUE;
  8675. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8676. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8677. else
  8678. stackLevelIsNULL = TRUE;
  8679. }
  8680. json_object_put(ClearChargingProfile);
  8681. if(connectorIsNULL == FALSE)
  8682. {
  8683. switch(connectorIdInt)
  8684. {
  8685. case 0:
  8686. if(chargingProfilePurposeIsNULL == TRUE)
  8687. {
  8688. int l = 0;
  8689. strcpy(fname, ChargePointMaxProfile_JSON);
  8690. if((access(fname,F_OK))!=-1)
  8691. {
  8692. strcpy(chargingProfiles[l], fname);
  8693. l = l + 1;
  8694. }
  8695. strcpy(fname, TxDefaultProfile_0_JSON);
  8696. if((access(fname,F_OK))!=-1)
  8697. {
  8698. strcpy(chargingProfiles[l], fname);
  8699. l = l + 1;
  8700. }
  8701. ChargeProfileCount = l;
  8702. }
  8703. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8704. {
  8705. strcpy(fname, ChargePointMaxProfile_JSON);
  8706. if((access(fname,F_OK))!=-1)
  8707. {
  8708. strcpy(chargingProfiles[0], fname);
  8709. ChargeProfileCount = 1;
  8710. }
  8711. }
  8712. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8713. {
  8714. strcpy(fname, TxDefaultProfile_0_JSON);
  8715. if((access(fname,F_OK))!=-1)
  8716. {
  8717. strcpy(chargingProfiles[0], fname);
  8718. ChargeProfileCount = 1;
  8719. }
  8720. }
  8721. break;
  8722. default:
  8723. if(chargingProfilePurposeIsNULL == TRUE)
  8724. {
  8725. int m = 0;
  8726. memset(fname, 0, ARRAY_SIZE(fname));
  8727. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8728. if((access(fname,F_OK))!=-1)
  8729. {
  8730. strcpy(chargingProfiles[m], fname);
  8731. m = m + 1;
  8732. }
  8733. memset(fname, 0, ARRAY_SIZE(fname));
  8734. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8735. if((access(fname,F_OK))!=-1)
  8736. {
  8737. strcpy(chargingProfiles[m], fname);
  8738. m = m + 1;
  8739. }
  8740. ChargeProfileCount = m;
  8741. }
  8742. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8743. {
  8744. //strcpy(fname, TxDefaultProfile_1_JSON);
  8745. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8746. if((access(fname,F_OK))!=-1)
  8747. {
  8748. strcpy(chargingProfiles[0], fname);
  8749. ChargeProfileCount = 1;
  8750. }
  8751. }
  8752. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8753. {
  8754. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8755. if((access(fname,F_OK))!=-1)
  8756. {
  8757. strcpy(chargingProfiles[0], fname);
  8758. ChargeProfileCount = 1;
  8759. }
  8760. //strcpy(fname, TxProfile_1_JSON);
  8761. }
  8762. //strcpy(fname, ChargePointMaxProfile_JSON );
  8763. break;
  8764. }
  8765. }
  8766. else // Check all Charging Profiles
  8767. {
  8768. int i = 0;
  8769. char fnametemp[200]={0};
  8770. ChargeProfileCount = 0;
  8771. //Check ChargePointMaxProfile.json exit
  8772. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  8773. {
  8774. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  8775. i = i + 1;
  8776. }
  8777. //Check TxDefaultProfile_0.json exit
  8778. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  8779. {
  8780. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  8781. i = i + 1;
  8782. }
  8783. //Check TxDefaultProfile_%d.json
  8784. for(int j=1; j <= gunTotalNumber; j++)
  8785. {
  8786. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8787. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  8788. if((access(fnametemp,F_OK))!=-1)
  8789. {
  8790. strcpy(chargingProfiles[i], fnametemp);
  8791. i = i + 1;
  8792. }
  8793. }
  8794. //Check TxProfile_%d.json
  8795. for(int j=1; j <= gunTotalNumber; j++)
  8796. {
  8797. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8798. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  8799. if((access(fnametemp,F_OK))!=-1)
  8800. {
  8801. strcpy(chargingProfiles[i], fnametemp);
  8802. i = i + 1;
  8803. }
  8804. }
  8805. ChargeProfileCount = i;
  8806. }// End connectorIsNULL is TRUE
  8807. if(ChargeProfileCount == 0)
  8808. {
  8809. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8810. goto end;
  8811. }
  8812. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8813. {
  8814. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8815. goto end;
  8816. }
  8817. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8818. {
  8819. memset(str, 0, ARRAY_SIZE(str));
  8820. // clear temp file
  8821. sprintf(str,"rm -f %s",temp);
  8822. system(str);
  8823. for(int k=0; k < ChargeProfileCount; k++)
  8824. {
  8825. memset(str, 0, ARRAY_SIZE(str));
  8826. //clear file in C
  8827. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8828. system(str);
  8829. }
  8830. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8831. goto end;
  8832. }
  8833. else if(connectorIsNULL == TRUE)
  8834. {
  8835. for(int k=0; k < ChargeProfileCount; k++)
  8836. {
  8837. fptr1 = fopen(chargingProfiles[k], "r");
  8838. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  8839. //Check Charging Profile Count
  8840. while(fscanf(fptr1, "%s", word) != EOF)
  8841. {
  8842. //DEBUG_INFO("word=%s\n",word);
  8843. if(strstr(word, "chargingProfileId")!= NULL)
  8844. {
  8845. //DEBUG_INFO("test chargingProfileId \n");
  8846. n_chargingProfile = n_chargingProfile + 1;
  8847. //DEBUG_INFO("chargingProfileId Found\n");
  8848. }
  8849. }
  8850. rewind(fptr1);
  8851. //search Charging Profile Element
  8852. //int i= 0;
  8853. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8854. {
  8855. json_object *tmpProfilee;
  8856. tmpProfilee = json_tokener_parse(sLineWord);
  8857. if(!is_error(tmpProfilee))
  8858. {
  8859. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8860. {
  8861. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8862. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8863. }
  8864. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8865. {
  8866. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8867. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8868. }
  8869. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8870. {
  8871. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8872. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8873. }
  8874. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8875. {
  8876. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8877. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8878. }
  8879. }
  8880. json_object_put(tmpProfilee);
  8881. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8882. {
  8883. //------- not write to fptr2-------//
  8884. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8885. //clearflag = TRUE;
  8886. }
  8887. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8888. {
  8889. //------- not write to fptr2-------//
  8890. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8891. }
  8892. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8893. {
  8894. //------- not write to fptr2-------//
  8895. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8896. }
  8897. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8898. {
  8899. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8900. }
  8901. else
  8902. {
  8903. fprintf(fptr2, sLineWord);//writing data into file
  8904. }
  8905. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8906. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8907. if(clearflag == TRUE)
  8908. {
  8909. fclose(fptr1);
  8910. fclose(fptr2);
  8911. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8912. system(str);
  8913. // clear temp file
  8914. sprintf(str,"rm -f %s",temp);
  8915. system(str);
  8916. }
  8917. else
  8918. {
  8919. fclose(fptr1);
  8920. fclose(fptr2);
  8921. memset(str, 0, ARRAY_SIZE(str));
  8922. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8923. system(str);
  8924. resultRename = rename(temp, chargingProfiles[k]);
  8925. if(resultRename == 0)
  8926. {
  8927. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8928. }
  8929. else
  8930. {
  8931. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8932. }
  8933. if(comfirmstr[0]== 0)
  8934. {
  8935. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8936. }
  8937. //Check chargingProfile is empty file
  8938. /*------ Read the file ----------------*/
  8939. fptr1=fopen(chargingProfiles[k],"r");
  8940. ch=fgetc(fptr1);
  8941. rewind(fptr1);
  8942. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8943. if(ch!=EOF)
  8944. {
  8945. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8946. {
  8947. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8948. if(sLineWord[0]=='\0')
  8949. {
  8950. isEmptyFile = TRUE;
  8951. break;
  8952. }
  8953. else
  8954. {
  8955. isEmptyFile = FALSE;
  8956. break;
  8957. }
  8958. }
  8959. }
  8960. else
  8961. isEmptyFile = TRUE;
  8962. fclose(fptr1);
  8963. if(isEmptyFile == TRUE)
  8964. {
  8965. memset(str, 0, ARRAY_SIZE(str));
  8966. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8967. system(str);
  8968. }
  8969. }
  8970. }// End of while(int k=0; k < ChargePointCount; k++)
  8971. }
  8972. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8973. {
  8974. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8975. for(int k=0; k < ChargeProfileCount; k++)
  8976. {
  8977. fptr1 = fopen(chargingProfiles[k], "r");
  8978. fptr2 = fopen(temp, "w+");
  8979. //Check Charging Profile Count
  8980. while(fscanf(fptr1, "%s", word) != EOF)
  8981. {
  8982. //DEBUG_INFO("word=%s\n",word);
  8983. if(strstr(word, "chargingProfileId")!= NULL)
  8984. {
  8985. n_chargingProfile = n_chargingProfile + 1;
  8986. }
  8987. }
  8988. rewind(fptr1);
  8989. //search Charging Profile Element
  8990. //int i= 0;
  8991. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8992. {
  8993. json_object *tmpProfilee;
  8994. tmpProfilee = json_tokener_parse(sLineWord);
  8995. if(!is_error(tmpProfilee))
  8996. {
  8997. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8998. {
  8999. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9000. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9001. }
  9002. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9003. {
  9004. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9005. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9006. }
  9007. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9008. {
  9009. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9010. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9011. }
  9012. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9013. {
  9014. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9015. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9016. }
  9017. }
  9018. json_object_put(tmpProfilee);
  9019. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9020. {
  9021. //------- not write to fptr2-------//
  9022. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9023. //clearflag = TRUE;
  9024. }
  9025. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9026. {
  9027. //------- not write to fptr2-------//
  9028. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9029. }
  9030. else if(stackLevelIsNULL == TRUE)
  9031. {
  9032. //Clear Whole File
  9033. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9034. clearflag = TRUE;
  9035. break;
  9036. }
  9037. else
  9038. {
  9039. fprintf(fptr2, sLineWord);//writing data into file
  9040. }
  9041. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9042. }
  9043. if(clearflag == TRUE)
  9044. {
  9045. fclose(fptr1);
  9046. fclose(fptr2);
  9047. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9048. system(str);
  9049. // clear temp file
  9050. sprintf(str,"rm -f %s",temp);
  9051. system(str);
  9052. }
  9053. else
  9054. {
  9055. fclose(fptr1);
  9056. fclose(fptr2);
  9057. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9058. system(str);
  9059. resultRename = rename(temp, chargingProfiles[k]);
  9060. if(resultRename == 0)
  9061. {
  9062. DEBUG_INFO("File ChargingProfile renamed successfully");
  9063. }
  9064. else
  9065. {
  9066. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9067. }
  9068. if(comfirmstr[0]== 0)
  9069. {
  9070. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9071. }
  9072. //Check chargingProfile is empty file
  9073. /*------ Read the file ----------------*/
  9074. fptr1=fopen(chargingProfiles[k],"r");
  9075. ch=fgetc(fptr1);
  9076. rewind(fptr1);
  9077. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9078. if(ch!=EOF)
  9079. {
  9080. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9081. {
  9082. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9083. if(sLineWord[0]=='\0')
  9084. {
  9085. isEmptyFile = TRUE;
  9086. break;
  9087. }
  9088. else
  9089. {
  9090. isEmptyFile = FALSE;
  9091. break;
  9092. }
  9093. }
  9094. }
  9095. else
  9096. isEmptyFile = TRUE;
  9097. fclose(fptr1);
  9098. if(isEmptyFile == TRUE)
  9099. {
  9100. memset(str, 0, ARRAY_SIZE(str));
  9101. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9102. system(str);
  9103. }
  9104. /*------- End of reading ---------------*/
  9105. }
  9106. } // while(int k=0; k < ChargeProfileCount; k++)
  9107. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9108. end:
  9109. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9110. {
  9111. if(connectorIdInt == 0)
  9112. {
  9113. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9114. {
  9115. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  9116. }
  9117. }
  9118. else
  9119. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  9120. }
  9121. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9122. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9123. return result;
  9124. }
  9125. void createFirmwareVersionByDataTransfer(void)
  9126. {
  9127. json_object *FirmwareDataTransfer = json_object_new_object();
  9128. // AC & DC model
  9129. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9130. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9131. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9132. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9133. // DC model
  9134. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9135. {
  9136. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9137. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9138. (gunType[3] != GUN_TYPE_UNKNOWN))
  9139. {
  9140. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9141. }
  9142. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9143. {
  9144. // DS DM DW
  9145. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9146. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9147. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9148. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9149. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9150. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9151. }
  9152. else
  9153. {
  9154. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9155. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9156. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9157. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9158. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9159. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9160. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9161. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9162. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9163. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9164. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9165. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9166. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9167. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9168. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9169. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9170. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9171. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9172. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9173. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9174. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9175. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9176. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9177. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9178. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9179. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9180. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9181. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9182. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9183. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9184. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9185. }
  9186. }
  9187. // 4G model
  9188. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9189. {
  9190. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9191. }
  9192. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9193. json_object_put(FirmwareDataTransfer);
  9194. }
  9195. int handleDataTransferRequest(char *uuid, char *payload)
  9196. {
  9197. mtrace();
  9198. json_object *response = json_object_new_object();
  9199. int result = FAIL;
  9200. char tempvendorId[255]={0};
  9201. char tempmessageId[50]={0};
  9202. char tempdata[1024]={0};
  9203. char message[2048]={0};
  9204. DEBUG_INFO("handleDataTransferRequest...\n");
  9205. if((uuid != NULL) && (payload != NULL))
  9206. {
  9207. json_object *DataTransfer;
  9208. DataTransfer = json_tokener_parse(payload);
  9209. if(!is_error(DataTransfer))
  9210. {
  9211. // Required data
  9212. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9213. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9214. // Optional data
  9215. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9216. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9217. if(json_object_object_get(DataTransfer, "data") != NULL)
  9218. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9219. result = PASS;
  9220. }
  9221. json_object_put(DataTransfer);
  9222. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9223. {
  9224. // Send all moudle firmware version on EVSE
  9225. createFirmwareVersionByDataTransfer();
  9226. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9227. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData));
  9228. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9229. json_object_put(response);
  9230. }
  9231. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9232. {
  9233. system("/usr/bin/run_tmate_restart.sh &");
  9234. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9235. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9236. json_object_put(response);
  9237. }
  9238. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9239. {
  9240. json_object *data;
  9241. data = json_tokener_parse(tempdata);
  9242. if(!is_error(data))
  9243. {
  9244. 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))
  9245. {
  9246. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9247. memset(&ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9248. if(json_object_object_get(data, "SOC") != NULL)
  9249. {
  9250. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9251. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9252. }
  9253. if(json_object_object_get(data, "Energy") != NULL)
  9254. {
  9255. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9256. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9257. }
  9258. if(json_object_object_get(data, "Duration") != NULL)
  9259. {
  9260. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9261. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9262. }
  9263. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9264. }
  9265. else
  9266. {
  9267. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9268. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9269. }
  9270. }
  9271. else
  9272. {
  9273. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9274. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9275. }
  9276. json_object_put(data);
  9277. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9278. json_object_put(response);
  9279. }
  9280. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9281. {
  9282. json_object *data;
  9283. data = json_tokener_parse(tempdata);
  9284. if(!is_error(data))
  9285. {
  9286. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9287. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9288. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9289. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9290. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9291. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9292. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9293. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9294. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9295. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9296. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9297. }
  9298. else
  9299. {
  9300. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9301. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9302. }
  9303. json_object_put(data);
  9304. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9305. json_object_put(response);
  9306. }
  9307. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9308. {
  9309. json_object *data;
  9310. data = json_tokener_parse(tempdata);
  9311. if(!is_error(data))
  9312. {
  9313. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9314. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9315. if(json_object_object_get(data, "idToken") != NULL)
  9316. {
  9317. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9318. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9319. }
  9320. else
  9321. {
  9322. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9323. json_object_object_add(response, "data", json_object_new_string("idToken not found."));
  9324. }
  9325. if(json_object_object_get(data, "price") != NULL) //v1.0
  9326. {
  9327. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9328. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9329. }
  9330. else if(json_object_object_get(data, "priceText") != NULL) //v2.0
  9331. {
  9332. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  9333. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  9334. }
  9335. else
  9336. {
  9337. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9338. json_object_object_add(response, "data", json_object_new_string("price or priceText not found."));
  9339. }
  9340. }
  9341. else
  9342. {
  9343. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9344. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9345. }
  9346. json_object_put(data);
  9347. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9348. json_object_put(response);
  9349. }
  9350. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9351. {
  9352. json_object *data;
  9353. data = json_tokener_parse(tempdata);
  9354. if(!is_error(data))
  9355. {
  9356. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9357. if(json_object_object_get(data, "txId") != NULL)
  9358. {
  9359. // California pricing V1.0
  9360. DEBUG_INFO("California pricing V1.0\n");
  9361. DEBUG_INFO("txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9362. sprintf((char*)dmsVersion, "1.0");
  9363. for(int idx = 0;idx<gunTotalNumber;idx++)
  9364. {
  9365. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9366. {
  9367. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9368. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9369. if(json_object_object_get(data, "description") != NULL)
  9370. {
  9371. // California pricing V1.0
  9372. DEBUG_INFO("California pricing V1.0\n");
  9373. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9374. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9375. }
  9376. }
  9377. }
  9378. }
  9379. else if(json_object_object_get(data, "transactionId") != NULL)
  9380. {
  9381. // California pricing V2.0
  9382. DEBUG_INFO("California pricing V2.0\n");
  9383. DEBUG_INFO("transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9384. sprintf((char*)dmsVersion, "2.0");
  9385. for(int idx=0;idx<gunTotalNumber;idx++)
  9386. {
  9387. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9388. {
  9389. if(json_object_object_get(data, "timestamp") != NULL)
  9390. {
  9391. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9392. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9393. }
  9394. else
  9395. {
  9396. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9397. json_object_object_add(response, "data", json_object_new_string("timestamp not found."));
  9398. }
  9399. if(json_object_object_get(data, "meterValue") != NULL)
  9400. {
  9401. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9402. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9403. }
  9404. else
  9405. {
  9406. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9407. json_object_object_add(response, "data", json_object_new_string("meterValue not found."));
  9408. }
  9409. if(json_object_object_get(data, "cost") != NULL)
  9410. {
  9411. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9412. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9413. }
  9414. else
  9415. {
  9416. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9417. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  9418. }
  9419. if(json_object_object_get(data, "state") != NULL)
  9420. {
  9421. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9422. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9423. }
  9424. else
  9425. {
  9426. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9427. json_object_object_add(response, "data", json_object_new_string("state not found."));
  9428. }
  9429. if(json_object_object_get(data, "chargingPrice") != NULL)
  9430. {
  9431. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9432. {
  9433. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9434. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9435. }
  9436. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9437. {
  9438. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9439. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9440. }
  9441. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9442. {
  9443. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9444. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9445. }
  9446. }
  9447. else
  9448. {
  9449. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9450. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9451. }
  9452. if(json_object_object_get(data, "idlePrice") != NULL)
  9453. {
  9454. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9455. {
  9456. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9457. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9458. }
  9459. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9460. {
  9461. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9462. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9463. }
  9464. }
  9465. if(json_object_object_get(data, "nextPeriod") != NULL)
  9466. {
  9467. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9468. {
  9469. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9470. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9471. }
  9472. else
  9473. {
  9474. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9475. json_object_object_add(response, "data", json_object_new_string("atTime not found."));
  9476. }
  9477. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9478. {
  9479. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9480. {
  9481. 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")));
  9482. 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"));
  9483. }
  9484. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9485. {
  9486. 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")));
  9487. 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"));
  9488. }
  9489. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9490. {
  9491. 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")));
  9492. 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"));
  9493. }
  9494. }
  9495. else
  9496. {
  9497. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9498. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9499. }
  9500. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9501. {
  9502. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9503. {
  9504. 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")));
  9505. 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"));
  9506. }
  9507. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9508. {
  9509. 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")));
  9510. 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"));
  9511. }
  9512. }
  9513. }
  9514. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9515. {
  9516. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9517. {
  9518. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9519. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9520. }
  9521. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9522. {
  9523. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9524. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9525. }
  9526. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9527. {
  9528. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9529. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9530. }
  9531. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus") != NULL)
  9532. {
  9533. DEBUG_INFO("triggerMeterValue-atCPStatus: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  9534. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atCPStatus, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  9535. }
  9536. }
  9537. }
  9538. }
  9539. }
  9540. else
  9541. {
  9542. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9543. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  9544. }
  9545. }
  9546. else
  9547. {
  9548. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9549. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9550. }
  9551. json_object_put(data);
  9552. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9553. json_object_put(response);
  9554. }
  9555. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9556. {
  9557. json_object *data;
  9558. data = json_tokener_parse(tempdata);
  9559. if(!is_error(data))
  9560. {
  9561. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9562. if(json_object_object_get(data, "txId") != NULL)
  9563. {
  9564. DEBUG_INFO("v1.0 txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9565. for(int idx = 0;idx<gunTotalNumber;idx++)
  9566. {
  9567. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9568. {
  9569. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9570. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9571. if(json_object_object_get(data, "description") != NULL)
  9572. {
  9573. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9574. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9575. }
  9576. else
  9577. {
  9578. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9579. json_object_object_add(response, "data", json_object_new_string("description not found."));
  9580. }
  9581. }
  9582. }
  9583. }
  9584. else if(json_object_object_get(data, "transactionId") != NULL)
  9585. {
  9586. DEBUG_INFO("v2.0 transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9587. for(int idx = 0;idx<gunTotalNumber;idx++)
  9588. {
  9589. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9590. {
  9591. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9592. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  9593. if(json_object_object_get(data, "cost") != NULL)
  9594. {
  9595. DEBUG_INFO("cost: %s\n", json_object_get_string(json_object_object_get(data, "cost")));
  9596. ShmOCPP16DataPH->Cost.FinalCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9597. }
  9598. else
  9599. {
  9600. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9601. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  9602. }
  9603. if(json_object_object_get(data, "priceText") != NULL)
  9604. {
  9605. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  9606. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].priceText, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  9607. }
  9608. else
  9609. {
  9610. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9611. json_object_object_add(response, "data", json_object_new_string("priceText not found."));
  9612. }
  9613. if(json_object_object_get(data, "qrCodeText") != NULL)
  9614. {
  9615. DEBUG_INFO(": %s\n", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  9616. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].qrCodeText, "%s", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  9617. }
  9618. }
  9619. }
  9620. }
  9621. else
  9622. {
  9623. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9624. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  9625. }
  9626. }
  9627. else
  9628. {
  9629. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9630. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9631. }
  9632. json_object_put(data);
  9633. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9634. json_object_put(response);
  9635. }
  9636. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9637. {
  9638. json_object *data;
  9639. data = json_tokener_parse(tempdata);
  9640. if(!is_error(data))
  9641. {
  9642. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9643. if(json_object_object_get(data, "Content_Type") != NULL)
  9644. {
  9645. 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))
  9646. {
  9647. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9648. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9649. {
  9650. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9651. }
  9652. }
  9653. else
  9654. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9655. }
  9656. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9657. }
  9658. else
  9659. {
  9660. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9661. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9662. }
  9663. json_object_put(data);
  9664. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9665. json_object_put(response);
  9666. }
  9667. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9668. {
  9669. json_object *data;
  9670. data = json_tokener_parse(tempdata);
  9671. if(!is_error(data))
  9672. {
  9673. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9674. if(json_object_object_get(data, "ConnectorId") != NULL)
  9675. {
  9676. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9677. }
  9678. if(json_object_object_get(data, "SerialNo") != NULL)
  9679. {
  9680. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9681. }
  9682. if(json_object_object_get(data, "Page_Index") != NULL)
  9683. {
  9684. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9685. }
  9686. if(json_object_object_get(data, "Duration") != NULL)
  9687. {
  9688. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9689. }
  9690. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9691. }
  9692. else
  9693. {
  9694. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9695. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9696. }
  9697. json_object_put(data);
  9698. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9699. json_object_put(response);
  9700. }
  9701. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9702. {
  9703. json_object *data;
  9704. data = json_tokener_parse(tempdata);
  9705. if(!is_error(data))
  9706. {
  9707. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9708. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9709. {
  9710. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9711. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9712. else
  9713. {
  9714. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9715. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9716. }
  9717. }
  9718. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9719. {
  9720. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9721. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9722. else
  9723. {
  9724. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9725. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9726. }
  9727. }
  9728. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9729. {
  9730. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9731. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9732. else
  9733. {
  9734. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9735. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9736. }
  9737. }
  9738. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9739. {
  9740. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9741. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9742. else
  9743. {
  9744. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9745. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9746. }
  9747. }
  9748. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9749. {
  9750. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9751. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9752. else
  9753. {
  9754. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9755. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9756. }
  9757. }
  9758. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9759. {
  9760. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9761. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9762. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9763. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9764. else
  9765. {
  9766. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9767. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9768. }
  9769. }
  9770. if(json_object_object_get(data, "isAuthentication") != NULL)
  9771. {
  9772. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9773. {
  9774. case 0:
  9775. case 1:
  9776. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9777. break;
  9778. default:
  9779. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9780. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9781. break;
  9782. }
  9783. }
  9784. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9785. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9786. }
  9787. else
  9788. {
  9789. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9790. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9791. }
  9792. json_object_put(data);
  9793. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9794. json_object_put(response);
  9795. }
  9796. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9797. {
  9798. json_object *data;
  9799. data = json_tokener_parse(tempdata);
  9800. if(!is_error(data))
  9801. {
  9802. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9803. if(json_object_object_get(data, "stationName") != NULL)
  9804. {
  9805. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9806. }
  9807. else
  9808. {
  9809. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9810. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9811. }
  9812. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9813. {
  9814. ShmOCPP16DataPH->TcciCustomData.ChargerInfoReq = 1;
  9815. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9816. ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name);
  9817. }
  9818. }
  9819. else
  9820. {
  9821. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9822. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9823. }
  9824. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9825. json_object_put(response);
  9826. }
  9827. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9828. {
  9829. json_object *data;
  9830. data = json_tokener_parse(tempdata);
  9831. if(!is_error(data))
  9832. {
  9833. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9834. if(json_object_object_get(data, "weatherId") != NULL)
  9835. {
  9836. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9837. }
  9838. else
  9839. {
  9840. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9841. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9842. }
  9843. if(json_object_object_get(data, "Temperature") != NULL)
  9844. {
  9845. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9846. }
  9847. else
  9848. {
  9849. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9850. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9851. }
  9852. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9853. {
  9854. ShmOCPP16DataPH->TcciCustomData.WeatherInfoReq = 1;
  9855. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9856. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId,
  9857. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature);
  9858. }
  9859. }
  9860. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9861. {
  9862. json_object *data;
  9863. data = json_tokener_parse(tempdata);
  9864. if(!is_error(data))
  9865. {
  9866. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9867. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9868. {
  9869. ShmOCPP16DataPH->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9870. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9871. }
  9872. else
  9873. {
  9874. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9875. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9876. }
  9877. }
  9878. else
  9879. {
  9880. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9881. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9882. }
  9883. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9884. json_object_put(response);
  9885. }
  9886. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  9887. {
  9888. json_object *data;
  9889. data = json_tokener_parse(tempdata);
  9890. if(!is_error(data))
  9891. {
  9892. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9893. {
  9894. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  9895. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9896. if(gun_index < gunTotalNumber)
  9897. {
  9898. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9899. {
  9900. json_object *responsedata = json_object_new_object();
  9901. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId));
  9902. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  9903. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16DataPH->TcciCustomData.SerialNo[gun_index]));
  9904. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp));
  9905. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  9906. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  9907. }
  9908. else
  9909. {
  9910. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9911. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  9912. }
  9913. }
  9914. else
  9915. {
  9916. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9917. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  9918. }
  9919. }
  9920. else
  9921. {
  9922. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9923. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9924. }
  9925. }
  9926. else
  9927. {
  9928. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9929. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9930. }
  9931. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9932. json_object_put(response);
  9933. }
  9934. else
  9935. {
  9936. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9937. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9938. }
  9939. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9940. json_object_put(response);
  9941. }
  9942. else
  9943. {
  9944. // Can not find valid message id
  9945. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9946. }
  9947. }
  9948. else
  9949. {
  9950. // Payload is null
  9951. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9952. }
  9953. LWS_Send(message);
  9954. return result;
  9955. }
  9956. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9957. {
  9958. mtrace();
  9959. int result = FAIL;
  9960. int connectorIdInt, durationInt;
  9961. char chargingRateUnitStr[4]={0};
  9962. char comfirmstr[20];
  9963. int confirmPeriods = 0;
  9964. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9965. json_object *GetCompositeSchedule;
  9966. GetCompositeSchedule = json_tokener_parse(payload);
  9967. if(!is_error(GetCompositeSchedule))
  9968. {
  9969. // Required data
  9970. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9971. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9972. else
  9973. connectorIdInt = -1;
  9974. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9975. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9976. else
  9977. durationInt = 86400;
  9978. // Optional data
  9979. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9980. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9981. }
  9982. json_object_put(GetCompositeSchedule);
  9983. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9984. if((connectorIdInt == 0) ||
  9985. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9986. {
  9987. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9988. struct StructChargingProfile tmpProfile[1];
  9989. if(strstr(chargingRateUnitStr, "W") != NULL)
  9990. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9991. else
  9992. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9993. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9994. {
  9995. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9996. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9997. }
  9998. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9999. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  10000. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  10001. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10002. {
  10003. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10004. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10005. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  10006. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  10007. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  10008. {
  10009. confirmPeriods = idx;
  10010. break;
  10011. }
  10012. }
  10013. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  10014. {
  10015. confirmPeriods += 1;
  10016. }
  10017. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  10018. }
  10019. else
  10020. {
  10021. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  10022. }
  10023. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  10024. return result;
  10025. }
  10026. int handleGetConfigurationRequest(char *uuid, char *payload)
  10027. {
  10028. mtrace();
  10029. int result = FAIL;
  10030. int MaxKeySupported = 0;
  10031. int n_keys = 0;
  10032. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  10033. DEBUG_INFO("handleGetConfigurationRequest...\n");
  10034. json_object *GetConfiguration;
  10035. GetConfiguration = json_tokener_parse(payload);
  10036. if(!is_error(GetConfiguration))
  10037. {
  10038. // Optional data
  10039. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10040. {
  10041. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10042. {
  10043. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10044. n_keys = idx + 1;
  10045. }
  10046. }
  10047. }
  10048. json_object_put(GetConfiguration);
  10049. UnknownKeynum = 0;
  10050. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10051. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10052. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10053. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10054. if(n_keys != 0)
  10055. {
  10056. for(int i=0;i<n_keys;i++)
  10057. {
  10058. getKeyValue(requestKey[i]);
  10059. }
  10060. }
  10061. else
  10062. {
  10063. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10064. getKeyValue("");
  10065. }
  10066. processUnkownKey();
  10067. sendGetConfigurationConfirmation(uuid);
  10068. return result;
  10069. }
  10070. static char fnamePlusPath[100]={0};
  10071. static char fnamePWithNoPath[60]={0};
  10072. void checkUploadLog(void)
  10073. {
  10074. FILE *fp;
  10075. /* Open the command for reading. */
  10076. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10077. if (fp == NULL) {
  10078. DEBUG_WARN("Failed to run command\n" );
  10079. exit(1);
  10080. }
  10081. int ftppathlen = 0;
  10082. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10083. int i = 0;
  10084. /* Read the output a line at a time - output it. */
  10085. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10086. if(i==0)
  10087. {
  10088. ftppathlen = strlen(fnamePlusPath);
  10089. DEBUG_INFO("%s\n", fnamePlusPath);
  10090. fnamePlusPath[ftppathlen]='\0';
  10091. break;
  10092. }
  10093. i= i+1;
  10094. }
  10095. /* close */
  10096. pclose(fp);
  10097. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10098. {
  10099. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10100. {
  10101. fnamePlusPath[k]='\0';
  10102. }
  10103. }
  10104. i=1;
  10105. //char fname[60]={0};
  10106. while(i < ftppathlen)
  10107. {
  10108. int len=ftppathlen-i;
  10109. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10110. {
  10111. DEBUG_INFO("compare '/' all right\n");
  10112. break;
  10113. }
  10114. i=i+1;
  10115. }
  10116. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  10117. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  10118. fnamePWithNoPath[i+1] = '\0';
  10119. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  10120. {
  10121. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  10122. {
  10123. fnamePWithNoPath[j]='\0';
  10124. }
  10125. }
  10126. FILE* fp1 = fopen(fnamePlusPath, "r");
  10127. if (fp1)
  10128. {
  10129. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  10130. // file exists
  10131. fclose(fp1);
  10132. }
  10133. else
  10134. {
  10135. // file doesn't exist
  10136. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  10137. }
  10138. }
  10139. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  10140. {
  10141. mtrace();
  10142. int result = FAIL;
  10143. time_t CurrentTime;
  10144. struct tm *tm;
  10145. pthread_t th_Status;
  10146. CurrentTime = time(NULL);
  10147. tm = localtime(&CurrentTime);
  10148. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  10149. 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);
  10150. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  10151. if(!interLock.isGetDiagnosticGoing)
  10152. {
  10153. interLock.isGetDiagnosticGoing = 1;
  10154. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  10155. sleep(1);
  10156. }
  10157. else
  10158. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  10159. return result;
  10160. }
  10161. void* GetDiagnosticsProcess(void* data)
  10162. {
  10163. pthread_detach(pthread_self());
  10164. mtrace();
  10165. int retriesInt=0, retryIntervalInt=0;
  10166. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  10167. 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};
  10168. int port=0;
  10169. int isSuccess = FALSE;
  10170. char ftpbuf[200]={0};
  10171. char cmdBuf[2048];
  10172. struct tm *tmNow;
  10173. time_t CurrentTime;
  10174. struct tm tmStart;
  10175. struct tm tmStop;
  10176. CurrentTime = time(NULL);
  10177. tmNow=localtime(&CurrentTime);
  10178. uint16_t targetYear, targetMonth;
  10179. json_object *GetDiagnostics;
  10180. DEBUG_INFO("GetDiagnosticsProcess...\n");
  10181. GetDiagnostics = json_tokener_parse(data);
  10182. if(!is_error(GetDiagnostics))
  10183. {
  10184. // Required data
  10185. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  10186. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  10187. // Optional data
  10188. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  10189. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  10190. else
  10191. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  10192. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  10193. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  10194. else
  10195. retryIntervalInt = 30;
  10196. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  10197. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  10198. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  10199. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  10200. }
  10201. json_object_put(GetDiagnostics);
  10202. // Pack log to compress file
  10203. 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) &&
  10204. (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))
  10205. {
  10206. // Pack system log
  10207. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10208. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10209. targetYear = tmStart.tm_year;
  10210. targetMonth = tmStart.tm_mon;
  10211. do
  10212. {
  10213. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10214. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  10215. if(targetMonth+1>=13)
  10216. {
  10217. targetYear += 1;
  10218. targetMonth = 1;
  10219. }
  10220. else
  10221. {
  10222. targetMonth += 1;
  10223. }
  10224. }while((targetYear < (tmNow->tm_year+1900)) ||
  10225. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10226. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  10227. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  10228. system(cmdBuf);
  10229. // Pack charging & event log
  10230. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10231. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  10232. targetYear = tmStart.tm_year;
  10233. targetMonth = tmStart.tm_mon;
  10234. do
  10235. {
  10236. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10237. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  10238. if(targetMonth+1>=13)
  10239. {
  10240. targetYear += 1;
  10241. targetMonth = 1;
  10242. }
  10243. else
  10244. {
  10245. targetMonth += 1;
  10246. }
  10247. }while((targetYear < (tmNow->tm_year+1900)) ||
  10248. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10249. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10250. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10251. system(cmdBuf);
  10252. // Combine log file
  10253. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10254. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10255. }
  10256. else
  10257. {
  10258. system("exec /root/logPackTools 'log' 6");
  10259. }
  10260. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  10261. system(cmdBuf);
  10262. checkUploadLog();
  10263. //****************location*******************/
  10264. if(strcmp(locationstr,"")==0)
  10265. {
  10266. DEBUG_INFO("location is <Empty>!\n");
  10267. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10268. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10269. goto end;
  10270. }
  10271. memset(protocol, 0, ARRAY_SIZE(protocol));
  10272. memset(user, 0, ARRAY_SIZE(user) );
  10273. memset(password, 0, ARRAY_SIZE(password));
  10274. memset(host, 0, ARRAY_SIZE(host));
  10275. memset(path, 0, ARRAY_SIZE(path));
  10276. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10277. memset(host1, 0, ARRAY_SIZE(host1));
  10278. memset(path1, 0, ARRAY_SIZE(path1));
  10279. /*location: ftp://user:password@host:port/path*/
  10280. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10281. if((access(fnamePlusPath,F_OK))!=-1)
  10282. {
  10283. DEBUG_INFO("fnamePlusPath exist.\n");
  10284. }
  10285. else
  10286. {
  10287. DEBUG_INFO("fnamePlusPath not exist!\n");
  10288. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10289. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10290. goto end;
  10291. }
  10292. if(strchr(locationstr,'@')==NULL)
  10293. {
  10294. sscanf(locationstr,
  10295. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10296. protocol, host, &port, path);
  10297. strcpy(user,"anonymous");
  10298. strcpy(password,"");
  10299. }
  10300. else
  10301. {
  10302. //DEBUG_INFO("pch=%s\n", pch);
  10303. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10304. protocol, user, password, host, &port, path);
  10305. }
  10306. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10307. {
  10308. DEBUG_INFO("protocol is not ftp/http ! \n");
  10309. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10310. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10311. goto end;
  10312. }
  10313. if(strncmp(locationstr,"http", 4) == 0)
  10314. {
  10315. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10316. sprintf(ftppath,"/%s", path);
  10317. do
  10318. {
  10319. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10320. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10321. sleep(3);
  10322. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10323. if(!isSuccess)
  10324. {
  10325. DEBUG_INFO("Diagnostics fail.\n");
  10326. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10327. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10328. sleep(retryIntervalInt);
  10329. }
  10330. else
  10331. {
  10332. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10333. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10334. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10335. }
  10336. retriesInt--;
  10337. }while((isSuccess == 0)&&(retriesInt >= 0));
  10338. }
  10339. else
  10340. {
  10341. sscanf(host,"%[^/]%s",host1, path1);
  10342. if(strlen(path) > 0)
  10343. sprintf(ftppath,"/%s", path);
  10344. else
  10345. sprintf(ftppath,"/%s", path1);
  10346. int ftppathlen=strlen(ftppath);
  10347. int i=1;
  10348. char filenametemp[50];
  10349. while(i < ftppathlen)
  10350. {
  10351. int len=ftppathlen-i;
  10352. if(ftppath[len]== 47) // '/' ascll code: 47
  10353. {
  10354. DEBUG_INFO("find '/' all right\n");
  10355. break;
  10356. }
  10357. i=i+1;
  10358. }
  10359. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10360. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10361. filenametemp[i+1] = 0;
  10362. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10363. if(port == 0)
  10364. port = 21;
  10365. do
  10366. {
  10367. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10368. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10369. sleep(3);
  10370. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10371. if(!isSuccess)
  10372. {
  10373. DEBUG_INFO("Diagnostics fail.\n");
  10374. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10375. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10376. sleep(retryIntervalInt);
  10377. }
  10378. else
  10379. {
  10380. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10381. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10382. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10383. }
  10384. retriesInt--;
  10385. }while((!isSuccess)&&(retriesInt >= 0));
  10386. }
  10387. end:
  10388. system("rm -f /mnt/*");
  10389. sleep(5);
  10390. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10391. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10392. interLock.isGetDiagnosticGoing = 0;
  10393. pthread_exit(NULL);
  10394. }
  10395. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10396. {
  10397. mtrace();
  10398. int result = FAIL;
  10399. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10400. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10401. {
  10402. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10403. locallistVersion = -1;
  10404. }
  10405. else
  10406. {
  10407. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10408. locallistVersion = 0;
  10409. OCPP_getListVerion();
  10410. }
  10411. //from db.OCPP_getListVerion
  10412. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10413. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  10414. sendGetLocalListVersionConfirmation(uuid,"");
  10415. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  10416. return result;
  10417. }
  10418. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10419. {
  10420. mtrace();
  10421. int result = FAIL;
  10422. int connectorIdInt=-1;
  10423. int tempIndex = 0;
  10424. int connectorIdIsNULL, chargingProfileIsNULL;
  10425. char comfirmstr[20]={0};
  10426. char cmdBuf[512];
  10427. json_object *RemoteStartTransaction;
  10428. FILE *fp;
  10429. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10430. if(server_pending == TRUE)
  10431. {
  10432. return 0;
  10433. }
  10434. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10435. RemoteStartTransaction = json_tokener_parse(payload);
  10436. if(!is_error(RemoteStartTransaction))
  10437. {
  10438. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10439. {
  10440. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10441. }
  10442. else
  10443. {
  10444. connectorIdIsNULL = TRUE;
  10445. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10446. {
  10447. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10448. {
  10449. connectorIdIsNULL = FALSE;
  10450. connectorIdInt = (gun_index+1);
  10451. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10452. break;
  10453. }
  10454. }
  10455. }
  10456. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10457. {
  10458. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10459. // Required data
  10460. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10461. // Optional data
  10462. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10463. {
  10464. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10465. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10466. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10467. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10468. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10469. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10470. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10471. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10472. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10473. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10474. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10475. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10476. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10477. {
  10478. 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")));
  10479. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10480. 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"));
  10481. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10482. 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"));
  10483. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10484. 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")));
  10485. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10486. {
  10487. 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++)
  10488. {
  10489. 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"));
  10490. 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"));
  10491. 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)
  10492. 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"));
  10493. }
  10494. }
  10495. }
  10496. }
  10497. else
  10498. {
  10499. chargingProfileIsNULL = TRUE;
  10500. }
  10501. }
  10502. }
  10503. else
  10504. {
  10505. connectorIdIsNULL = TRUE;
  10506. }
  10507. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10508. {
  10509. DEBUG_WARN("Connector id is NULL\n.");
  10510. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10511. goto end;
  10512. }
  10513. /*
  10514. enum _SYSTEM_STATUS
  10515. {
  10516. S_BOOTING = 0,
  10517. S_IDLE, = 1
  10518. S_AUTHORIZING, = 2
  10519. S_REASSIGN_CHECK, = 3
  10520. S_REASSIGN, = 4
  10521. S_PRECHARGE, = 5
  10522. S_PREPARING_FOR_EV, = 6
  10523. S_PREPARING_FOR_EVSE, = 7
  10524. S_CHARGING, = 8
  10525. S_TERMINATING, = 9
  10526. S_COMPLETE, = 10
  10527. S_ALARM, = 11
  10528. S_FAULT = 12
  10529. }
  10530. */
  10531. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10532. {
  10533. //check Transaction active
  10534. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10535. {
  10536. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10537. {
  10538. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10539. }
  10540. else
  10541. {
  10542. tempIndex = connectorIdInt -1;
  10543. }
  10544. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10545. {
  10546. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10547. {
  10548. 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 matches the idTag of Reservation!!!\n");
  10552. }
  10553. 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))
  10554. {
  10555. //Reserved
  10556. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10557. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10558. goto end;
  10559. }
  10560. else
  10561. {
  10562. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10563. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10564. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10565. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10566. {
  10567. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10568. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10569. goto end;
  10570. }
  10571. }//END FOR ELSE
  10572. }
  10573. }// END FOR CHAdeMO_QUANTITY
  10574. }
  10575. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10576. {
  10577. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10578. {
  10579. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10580. }
  10581. else
  10582. {
  10583. tempIndex = connectorIdInt -1;
  10584. }
  10585. for (int index = 0; index < CCS_QUANTITY; index++)
  10586. {
  10587. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10588. {
  10589. 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 matches the idTag of Reservation!!!\n");
  10593. }
  10594. 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))
  10595. {
  10596. //Reserved
  10597. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10598. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10599. goto end;
  10600. }
  10601. else
  10602. {
  10603. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10604. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10605. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10606. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10607. {
  10608. DEBUG_WARN("CCS connector not allow start\n.");
  10609. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10610. goto end;
  10611. }
  10612. }// END FOR ELSE
  10613. }
  10614. }// END FOR CCS_QUANTITY
  10615. }
  10616. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10617. {
  10618. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10619. {
  10620. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10621. }
  10622. else
  10623. {
  10624. tempIndex = connectorIdInt -1;
  10625. }
  10626. for (int index = 0; index < GB_QUANTITY; index++)
  10627. {
  10628. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10629. {
  10630. 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 matches the idTag of Reservation!!!\n");
  10634. }
  10635. 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))
  10636. {
  10637. //Reserved
  10638. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10639. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10640. goto end;
  10641. }
  10642. else
  10643. {
  10644. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10645. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10646. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10647. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10648. {
  10649. DEBUG_WARN("GB connector not allow start\n.");
  10650. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10651. goto end;
  10652. }
  10653. }// END FOR ELSE
  10654. }
  10655. } // END FOR GB_QUANTITY
  10656. }
  10657. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10658. {
  10659. tempIndex = connectorIdInt -1;
  10660. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10661. {
  10662. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10663. {
  10664. 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 matches the idTag of Reservation!!!\n");
  10668. }
  10669. 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))
  10670. {
  10671. //Reserved
  10672. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10673. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10674. goto end;
  10675. }
  10676. else
  10677. {
  10678. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10679. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10680. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10681. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10682. {
  10683. DEBUG_WARN("GB connector not allow start\n.");
  10684. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10685. goto end;
  10686. }
  10687. }// END FOR ELSE
  10688. }
  10689. } // END FOR GB_QUANTITY
  10690. }
  10691. else
  10692. {
  10693. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10694. {
  10695. tempIndex = 2;
  10696. }
  10697. else
  10698. {
  10699. tempIndex = connectorIdInt -1;
  10700. }
  10701. for (int index = 0; index < AC_QUANTITY; index++)
  10702. {
  10703. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10704. {
  10705. 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 matches the idTag of Reservation!!!\n");
  10709. }
  10710. 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))
  10711. {
  10712. //Reserved
  10713. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10714. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10715. goto end;
  10716. }
  10717. else
  10718. {
  10719. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10720. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10721. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10722. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10723. {
  10724. DEBUG_WARN("AC connector not allow start\n.");
  10725. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10726. goto end;
  10727. }
  10728. }//END FOR ELSE
  10729. }
  10730. }// END FOR AC_QUANTITY
  10731. }
  10732. if(chargingProfileIsNULL == FALSE)
  10733. {
  10734. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10735. {
  10736. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10737. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10738. //memset idTag
  10739. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10740. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10741. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10742. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10743. // Save profile to file
  10744. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10745. system(cmdBuf);
  10746. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10747. fp = fopen(cmdBuf, "w");
  10748. 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));
  10749. fclose(fp);
  10750. }
  10751. else
  10752. {
  10753. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10754. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10755. }
  10756. }
  10757. else
  10758. {
  10759. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10760. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10761. //memset idTag
  10762. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10763. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10764. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10765. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10766. }
  10767. }
  10768. else
  10769. {
  10770. DEBUG_WARN("Connector id over\n.");
  10771. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10772. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10773. }
  10774. end:
  10775. json_object_put(RemoteStartTransaction);
  10776. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10777. {
  10778. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10779. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10780. }
  10781. //OCPP send RemoteStartConfirmation by first.
  10782. sendRemoteStartConfirmation(uuid, comfirmstr);
  10783. return result;
  10784. }
  10785. int handleRemoteStartRequest(char *uuid, char *payload)
  10786. {
  10787. mtrace();
  10788. int result = PASS;
  10789. int connectorIdInt=-1;
  10790. int tempIndex = 0;
  10791. char comfirmstr[20]={0};
  10792. char cmdBuf[512];
  10793. json_object *RemoteStartTransaction;
  10794. FILE *fp;
  10795. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10796. if(server_pending == TRUE)
  10797. {
  10798. result = FAIL;
  10799. }
  10800. RemoteStartTransaction = json_tokener_parse(payload);
  10801. if(!is_error(RemoteStartTransaction))
  10802. {
  10803. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10804. {
  10805. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10806. }
  10807. else
  10808. {
  10809. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10810. {
  10811. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10812. {
  10813. connectorIdInt = (gun_index+1);
  10814. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10815. break;
  10816. }
  10817. }
  10818. }
  10819. if(connectorIdInt == 0)
  10820. {
  10821. DEBUG_WARN("Connector id shall not equal 0.\n");
  10822. result = FAIL;
  10823. }
  10824. else if(connectorIdInt == -1)
  10825. {
  10826. DEBUG_INFO("Connector id does not specific.\n");
  10827. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10828. {
  10829. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10830. // Required data
  10831. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10832. // Optional data
  10833. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10834. {
  10835. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10836. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10837. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10838. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10839. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10840. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10841. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10842. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10843. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10844. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10845. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10846. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10847. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10848. {
  10849. 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")));
  10850. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10851. 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"));
  10852. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10853. 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"));
  10854. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10855. 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")));
  10856. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10857. {
  10858. 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++)
  10859. {
  10860. 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"));
  10861. 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"));
  10862. 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)
  10863. 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"));
  10864. }
  10865. }
  10866. }
  10867. }
  10868. else
  10869. {
  10870. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10871. }
  10872. }
  10873. }
  10874. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10875. {
  10876. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10877. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10878. // Required data
  10879. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10880. // Optional data
  10881. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10882. {
  10883. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10884. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10885. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10886. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10887. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10888. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10889. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10890. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10891. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10892. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10893. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10894. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10895. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10896. {
  10897. 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")));
  10898. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10899. 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"));
  10900. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10901. 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"));
  10902. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10903. 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")));
  10904. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10905. {
  10906. 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++)
  10907. {
  10908. 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"));
  10909. 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"));
  10910. 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)
  10911. 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"));
  10912. }
  10913. }
  10914. }
  10915. }
  10916. else
  10917. {
  10918. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10919. }
  10920. }
  10921. else
  10922. {
  10923. DEBUG_WARN("Connector id is over maximun value.\n");
  10924. result = FAIL;
  10925. }
  10926. }
  10927. if(result == PASS)
  10928. {
  10929. if(connectorIdInt > 0)
  10930. {
  10931. //check Transaction active
  10932. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10933. {
  10934. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10935. {
  10936. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10937. }
  10938. else
  10939. {
  10940. tempIndex = connectorIdInt -1;
  10941. }
  10942. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10943. {
  10944. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10945. {
  10946. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10947. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10948. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10949. {
  10950. //Reserved
  10951. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10952. }
  10953. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10954. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10955. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10956. {
  10957. //Reserved
  10958. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10959. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10960. goto end;
  10961. }
  10962. else
  10963. {
  10964. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10965. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10966. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10967. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10968. {
  10969. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10970. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10971. goto end;
  10972. }
  10973. }//END FOR ELSE
  10974. }
  10975. }// END FOR CHAdeMO_QUANTITY
  10976. }
  10977. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10978. {
  10979. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10980. {
  10981. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10982. }
  10983. else
  10984. {
  10985. tempIndex = connectorIdInt -1;
  10986. }
  10987. for (int index = 0; index < CCS_QUANTITY; index++)
  10988. {
  10989. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10990. {
  10991. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10992. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10993. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10994. {
  10995. //Reserved
  10996. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10997. }
  10998. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10999. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11000. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11001. {
  11002. //Reserved
  11003. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  11004. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11005. goto end;
  11006. }
  11007. else
  11008. {
  11009. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11010. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11011. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11012. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11013. {
  11014. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11015. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11016. goto end;
  11017. }
  11018. }// END FOR ELSE
  11019. }
  11020. }// END FOR CCS_QUANTITY
  11021. }
  11022. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11023. {
  11024. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11025. {
  11026. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11027. }
  11028. else
  11029. {
  11030. tempIndex = connectorIdInt -1;
  11031. }
  11032. for (int index = 0; index < GB_QUANTITY; index++)
  11033. {
  11034. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11035. {
  11036. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11037. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11038. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11039. {
  11040. //Reserved
  11041. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11042. }
  11043. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11044. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11045. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11046. {
  11047. //Reserved
  11048. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11049. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11050. goto end;
  11051. }
  11052. else
  11053. {
  11054. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11055. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11056. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11057. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11058. {
  11059. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11060. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11061. goto end;
  11062. }
  11063. }// END FOR ELSE
  11064. }
  11065. } // END FOR GB_QUANTITY
  11066. }
  11067. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11068. {
  11069. tempIndex = connectorIdInt -1;
  11070. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11071. {
  11072. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11073. {
  11074. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11075. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11076. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11077. {
  11078. //Reserved
  11079. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11080. }
  11081. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11082. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11083. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11084. {
  11085. //Reserved
  11086. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11087. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11088. goto end;
  11089. }
  11090. else
  11091. {
  11092. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11093. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11094. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11095. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11096. {
  11097. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11098. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11099. goto end;
  11100. }
  11101. }// END FOR ELSE
  11102. }
  11103. } // END FOR GB_QUANTITY
  11104. }
  11105. else
  11106. {
  11107. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11108. {
  11109. tempIndex = 2;
  11110. }
  11111. else
  11112. {
  11113. tempIndex = connectorIdInt -1;
  11114. }
  11115. for (int index = 0; index < AC_QUANTITY; index++)
  11116. {
  11117. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11118. {
  11119. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11120. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11121. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11122. {
  11123. //Reserved
  11124. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11125. }
  11126. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11127. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11128. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11129. {
  11130. //Reserved
  11131. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11132. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11133. goto end;
  11134. }
  11135. else
  11136. {
  11137. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11138. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  11139. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  11140. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  11141. {
  11142. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11143. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11144. goto end;
  11145. }
  11146. }//END FOR ELSE
  11147. }
  11148. }// END FOR AC_QUANTITY
  11149. }
  11150. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11151. {
  11152. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11153. {
  11154. // Save profile to file
  11155. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  11156. system(cmdBuf);
  11157. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  11158. fp = fopen(cmdBuf, "w");
  11159. 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));
  11160. fclose(fp);
  11161. }
  11162. else
  11163. {
  11164. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11165. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11166. goto end;
  11167. }
  11168. }
  11169. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11170. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11171. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11172. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11173. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11174. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11175. }
  11176. else
  11177. {
  11178. uint8_t isHasIdleConnector = FALSE;
  11179. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11180. {
  11181. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11182. {
  11183. isHasIdleConnector = TRUE;
  11184. break;
  11185. }
  11186. }
  11187. if(isHasIdleConnector == TRUE)
  11188. {
  11189. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11190. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11191. {
  11192. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11193. {
  11194. // Save profile to file
  11195. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  11196. system(cmdBuf);
  11197. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  11198. fp = fopen(cmdBuf, "w");
  11199. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11200. fclose(fp);
  11201. refreshStartTimer(&clientTime.RemoteStartWait);
  11202. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  11203. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11204. }
  11205. else
  11206. {
  11207. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11208. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11209. }
  11210. }
  11211. else
  11212. {
  11213. refreshStartTimer(&clientTime.RemoteStartWait);
  11214. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  11215. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11216. }
  11217. }
  11218. else
  11219. {
  11220. DEBUG_INFO("There is not any connector is idle.\n");
  11221. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11222. }
  11223. }
  11224. }
  11225. else
  11226. {
  11227. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11228. }
  11229. end:
  11230. json_object_put(RemoteStartTransaction);
  11231. sendRemoteStartConfirmation(uuid, comfirmstr);
  11232. return result;
  11233. }
  11234. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11235. {
  11236. mtrace();
  11237. int result = FAIL;
  11238. int match = FALSE;
  11239. int GunNO = 0;
  11240. int tempIndex = 0;
  11241. int transactionIdInt=0;
  11242. int transactionIdIsNULL= TRUE;
  11243. char comfirmstr[20];
  11244. json_object *RemoteStopTransaction;
  11245. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11246. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11247. if(server_pending == TRUE)
  11248. {
  11249. return 0;
  11250. }
  11251. RemoteStopTransaction = json_tokener_parse(payload);
  11252. if(!is_error(RemoteStopTransaction))
  11253. {
  11254. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11255. {
  11256. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11257. transactionIdIsNULL = FALSE;
  11258. }
  11259. }
  11260. json_object_put(RemoteStopTransaction);
  11261. if(transactionIdIsNULL == FALSE)
  11262. {
  11263. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11264. {
  11265. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11266. {
  11267. //check Transaction active
  11268. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11269. {
  11270. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11271. {
  11272. tempIndex = ((gun_index==2) ? 1: 0);
  11273. }
  11274. else
  11275. {
  11276. tempIndex = gun_index;
  11277. }
  11278. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11279. {
  11280. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11281. {
  11282. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11283. {
  11284. match = TRUE;
  11285. GunNO = gun_index;
  11286. }
  11287. }
  11288. }// END FOR CHAdeMO_QUANTITY
  11289. }
  11290. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11291. {
  11292. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11293. {
  11294. tempIndex = ((gun_index==2) ? 1: 0);
  11295. }
  11296. else
  11297. {
  11298. tempIndex = gun_index;
  11299. }
  11300. for (int index = 0; index < CCS_QUANTITY; index++)
  11301. {
  11302. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11303. {
  11304. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11305. {
  11306. match = TRUE;
  11307. GunNO = gun_index;
  11308. }
  11309. }
  11310. }// END FOR CCS_QUANTITY
  11311. }
  11312. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11313. {
  11314. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11315. {
  11316. tempIndex = ((gun_index==2) ? 1: 0);
  11317. }
  11318. else
  11319. {
  11320. tempIndex = gun_index;
  11321. }
  11322. for (int index = 0; index < GB_QUANTITY; index++)
  11323. {
  11324. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11325. {
  11326. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11327. {
  11328. match = TRUE;
  11329. GunNO = gun_index;
  11330. }
  11331. }
  11332. }// END FOR GB_QUANTITY
  11333. }
  11334. else if(gunType[gun_index] == GUN_TYPE_DO)
  11335. {
  11336. tempIndex = gun_index;
  11337. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11338. {
  11339. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11340. {
  11341. 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
  11342. {
  11343. match = TRUE;
  11344. GunNO = gun_index;
  11345. }
  11346. }
  11347. }// END FOR GB_QUANTITY
  11348. }
  11349. else
  11350. {
  11351. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11352. {
  11353. tempIndex = 2;
  11354. }
  11355. else
  11356. {
  11357. tempIndex = gun_index;
  11358. }
  11359. for (int index = 0; index < AC_QUANTITY; index++)
  11360. {
  11361. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11362. {
  11363. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11364. {
  11365. match = TRUE;
  11366. GunNO = gun_index;
  11367. }
  11368. }
  11369. }// END FOR CHAdeMO_QUANTITY
  11370. } // END FOR AC ELSE
  11371. }// CHECK IF ResponseTransactionId == transactionIdInt
  11372. }//END FOR
  11373. if( match == TRUE)
  11374. {
  11375. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11376. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11377. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11378. }
  11379. else
  11380. {
  11381. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11382. }
  11383. }
  11384. else
  11385. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11386. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11387. return result;
  11388. }
  11389. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11390. {
  11391. mtrace();
  11392. int result = FAIL;
  11393. int connectorIdInt=0, reservationIdInt=0;
  11394. int tempIndex = 0;
  11395. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11396. char comfirmstr[20]={0};
  11397. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11398. int c = 0;
  11399. char *loc;
  11400. //char *ptr;
  11401. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11402. strcpy(sstrtemp, stringtrimspace(payload));
  11403. //***(1)connectorId ****/
  11404. c=0;
  11405. loc = strstr(sstrtemp, "connectorId");
  11406. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11407. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11408. {
  11409. sstr[c] = loc[strlen("connectorId")+2+c];
  11410. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11411. c++;
  11412. }
  11413. sstr[c] = '\0';
  11414. connectorIdInt = atoi(sstr);
  11415. //***(2)expiryDate ****/
  11416. loc = strstr(sstrtemp, "expiryDate");
  11417. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11418. c = 0;
  11419. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11420. {
  11421. sstr[c] = loc[3+strlen("expiryDate")+c];
  11422. c++;
  11423. }
  11424. sstr[c] = '\0';
  11425. strcpy(expiryDatestr, sstr);
  11426. //***(3)idTag ****/
  11427. loc = strstr(sstrtemp, "idTag");
  11428. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11429. c = 0;
  11430. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11431. {
  11432. sstr[c] = loc[3+strlen("idTag")+c];
  11433. c++;
  11434. }
  11435. sstr[c] = '\0';
  11436. strcpy(idTagstr, sstr);
  11437. //***(4)parentIdTag ****/
  11438. loc = strstr(sstrtemp, "parentIdTag");
  11439. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11440. c = 0;
  11441. if(loc == NULL)
  11442. {
  11443. strcpy(parentIdTagstr, "");
  11444. }
  11445. else
  11446. {
  11447. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11448. {
  11449. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11450. c++;
  11451. }
  11452. sstr[c] = '\0';
  11453. strcpy(parentIdTagstr, sstr);
  11454. }
  11455. //***(5)reservationId ****/
  11456. c=0;
  11457. loc = strstr(sstrtemp, "reservationId");
  11458. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11459. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11460. {
  11461. sstr[c] = loc[strlen("reservationId")+2+c];
  11462. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11463. c++;
  11464. }
  11465. sstr[c] = '\0';
  11466. reservationIdInt = atoi(sstr);
  11467. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11468. /*
  11469. enum SYSTEM_STATUS
  11470. {
  11471. SYS_MODE_BOOTING = 0,
  11472. SYS_MODE_IDLE = 1,
  11473. SYS_MODE_AUTHORIZING = 2,
  11474. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11475. SYS_MODE_REASSIGN = 4,
  11476. SYS_MODE_PREPARING = 5,
  11477. SYS_MODE_PREPARE_FOR_EV = 6,
  11478. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11479. SYS_MODE_CHARGING = 8,
  11480. SYS_MODE_TERMINATING = 9,
  11481. SYS_MODE_COMPLETE = 10,
  11482. SYS_MODE_ALARM = 11,
  11483. SYS_MODE_FAULT = 12,
  11484. SYS_MODE_RESERVATION = 13,
  11485. SYS_MODE_BOOKING = 14,
  11486. SYS_MODE_MAINTAIN = 15,
  11487. SYS_MODE_DEBUG = 16,
  11488. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11489. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11490. SYS_MODE_UPDATE = 19
  11491. };
  11492. */
  11493. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11494. {
  11495. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11496. goto end;
  11497. }
  11498. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11499. {
  11500. //check Transaction active
  11501. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11502. {
  11503. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11504. {
  11505. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11506. }
  11507. else
  11508. {
  11509. tempIndex = connectorIdInt -1;
  11510. }
  11511. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11512. {
  11513. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11514. {
  11515. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11516. {
  11517. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11518. {
  11519. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11520. {
  11521. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  11522. {
  11523. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11524. }
  11525. else
  11526. {
  11527. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11528. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11529. }
  11530. }
  11531. 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'))
  11532. {
  11533. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11534. }
  11535. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11536. {
  11537. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11538. }
  11539. else
  11540. {
  11541. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11542. }
  11543. }
  11544. 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
  11545. {
  11546. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11547. }
  11548. }
  11549. else
  11550. {
  11551. //replace reservation
  11552. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11553. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11554. }
  11555. }
  11556. } // END FOR CHAdeMO_QUANTITY
  11557. }
  11558. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11559. {
  11560. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11561. {
  11562. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11563. }
  11564. else
  11565. {
  11566. tempIndex = connectorIdInt -1;
  11567. }
  11568. for (int index = 0; index < CCS_QUANTITY; index++)
  11569. {
  11570. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11571. {
  11572. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11573. {
  11574. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11575. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11576. {
  11577. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11578. {
  11579. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  11580. {
  11581. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11582. }
  11583. else
  11584. {
  11585. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11586. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11587. }
  11588. }
  11589. 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'))
  11590. {
  11591. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11592. }
  11593. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11594. {
  11595. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11596. }
  11597. else
  11598. {
  11599. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11600. }
  11601. }
  11602. 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
  11603. {
  11604. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11605. }
  11606. }
  11607. else
  11608. {
  11609. //replace reservation
  11610. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11611. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11612. }
  11613. }
  11614. } // END FOR CCS_QUANTITY
  11615. }
  11616. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11617. {
  11618. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11619. {
  11620. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11621. }
  11622. else
  11623. {
  11624. tempIndex = connectorIdInt -1;
  11625. }
  11626. for (int index = 0; index < GB_QUANTITY; index++)
  11627. {
  11628. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11629. {
  11630. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11631. {
  11632. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11633. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11634. {
  11635. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11636. {
  11637. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  11638. {
  11639. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11640. }
  11641. else
  11642. {
  11643. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11644. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11645. }
  11646. }
  11647. 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'))
  11648. {
  11649. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11650. }
  11651. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11652. {
  11653. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11654. }
  11655. else
  11656. {
  11657. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11658. }
  11659. }
  11660. 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
  11661. {
  11662. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11663. }
  11664. }
  11665. else
  11666. {
  11667. //replace reservation
  11668. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11669. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11670. }
  11671. }
  11672. }// END FOR GB_QUANTITY
  11673. }
  11674. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11675. {
  11676. tempIndex = connectorIdInt -1;
  11677. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11678. {
  11679. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11680. {
  11681. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11682. {
  11683. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11684. 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
  11685. {
  11686. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11687. {
  11688. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  11689. {
  11690. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11691. }
  11692. else
  11693. {
  11694. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11695. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11696. }
  11697. }
  11698. 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'))
  11699. {
  11700. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11701. }
  11702. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11703. {
  11704. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11705. }
  11706. else
  11707. {
  11708. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11709. }
  11710. }
  11711. 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
  11712. {
  11713. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11714. }
  11715. }
  11716. else
  11717. {
  11718. //replace reservation
  11719. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11720. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11721. }
  11722. }
  11723. }// END FOR GB_QUANTITY
  11724. }
  11725. else
  11726. {
  11727. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11728. {
  11729. tempIndex = 2;
  11730. }
  11731. else
  11732. {
  11733. tempIndex = (connectorIdInt -1);
  11734. }
  11735. for (int index = 0; index < AC_QUANTITY; index++)
  11736. {
  11737. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11738. {
  11739. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11740. {
  11741. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11742. {
  11743. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11744. {
  11745. 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))
  11746. {
  11747. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11748. }
  11749. else
  11750. {
  11751. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11752. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11753. }
  11754. }
  11755. 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'))
  11756. {
  11757. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11758. }
  11759. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11760. {
  11761. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11762. }
  11763. else
  11764. {
  11765. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11766. }
  11767. }
  11768. 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
  11769. {
  11770. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11771. }
  11772. }
  11773. else
  11774. {
  11775. //replace reservation
  11776. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11777. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11778. }
  11779. }
  11780. } // END FOR AC_QUANTITY
  11781. }
  11782. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11783. }
  11784. else if(connectorIdInt == 0)
  11785. {
  11786. //check Transaction active
  11787. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11788. {
  11789. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11790. {
  11791. 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'))
  11792. {
  11793. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11794. goto end;
  11795. }
  11796. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11797. {
  11798. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11799. goto end;
  11800. }
  11801. 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
  11802. {
  11803. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11804. goto end;
  11805. }
  11806. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11807. {
  11808. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11809. goto end;
  11810. }
  11811. }
  11812. }// END FOR CHAdeMO_QUANTITY
  11813. for (int index = 0; index < CCS_QUANTITY; index++)
  11814. {
  11815. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11816. {
  11817. 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'))
  11818. {
  11819. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11820. goto end;
  11821. }
  11822. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11823. {
  11824. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11825. goto end;
  11826. }
  11827. 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
  11828. {
  11829. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11830. goto end;
  11831. }
  11832. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11833. {
  11834. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11835. goto end;
  11836. }
  11837. }
  11838. } // END FOR CCS_QUANTITY
  11839. for (int index = 0; index < GB_QUANTITY; index++)
  11840. {
  11841. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11842. {
  11843. 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'))
  11844. {
  11845. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11846. goto end;
  11847. }
  11848. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11849. {
  11850. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11851. goto end;
  11852. }
  11853. 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
  11854. {
  11855. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11856. goto end;
  11857. }
  11858. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11859. {
  11860. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11861. goto end;
  11862. }
  11863. }
  11864. } // END FOR GB_QUANTITY
  11865. for (int index = 0; index < AC_QUANTITY; index++)
  11866. {
  11867. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11868. {
  11869. 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'))
  11870. {
  11871. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11872. goto end;
  11873. }
  11874. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11875. {
  11876. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11877. goto end;
  11878. }
  11879. 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
  11880. {
  11881. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11882. goto end;
  11883. }
  11884. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11885. {
  11886. 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))
  11887. {
  11888. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11889. goto end;
  11890. }
  11891. }
  11892. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11893. {
  11894. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11895. goto end;
  11896. }
  11897. }
  11898. }// END FOR AC_QUANTITY
  11899. //The connectorId is 0
  11900. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  11901. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11902. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11903. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  11904. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11905. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  11906. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11907. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  11908. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  11909. result = TRUE;
  11910. return result;
  11911. }
  11912. else
  11913. {
  11914. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11915. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11916. }
  11917. if(strcmp(comfirmstr,"Accepted") == 0)
  11918. {
  11919. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11920. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11921. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11922. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11923. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11924. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11925. result = TRUE;
  11926. return result;
  11927. }
  11928. end:
  11929. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11930. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11931. return result;
  11932. }
  11933. int handleResetRequest(char *uuid, char *payload)
  11934. {
  11935. mtrace();
  11936. int result = FAIL;
  11937. char sstr[10]={0},sstrtemp[30]={ 0 };
  11938. char typestr[10]={0};
  11939. char comfirmstr[20]={0};
  11940. int c = 0;
  11941. char *loc;
  11942. DEBUG_INFO("handleResetRequest...\n");
  11943. strcpy(sstrtemp, stringtrimspace(payload));
  11944. loc = strstr(sstrtemp, "type");
  11945. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11946. c = 0;
  11947. while (loc[3+strlen("type")+c] != '\"')
  11948. {
  11949. sstr[c] = loc[3+strlen("type")+c];
  11950. c++;
  11951. }
  11952. sstr[c] = '\0';
  11953. strcpy(typestr,sstr);
  11954. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11955. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11956. {
  11957. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11958. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11959. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11960. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11961. }
  11962. else
  11963. {
  11964. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11965. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11966. result = PASS;
  11967. }
  11968. sendResetConfirmation(uuid, comfirmstr);
  11969. return result;
  11970. }
  11971. int handleSendLocalListRequest(char *uuid, char *payload)
  11972. {
  11973. mtrace();
  11974. int result = FAIL;
  11975. char comfirmstr[20];
  11976. int checkState_Faulted = FALSE;
  11977. json_object *SendLocalList;
  11978. DEBUG_INFO("handleSendLocalListRequest...\n");
  11979. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11980. {
  11981. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11982. goto end;
  11983. }
  11984. //check Charge Point state
  11985. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11986. {
  11987. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11988. {
  11989. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11990. }
  11991. }
  11992. for (int index = 0; index < CCS_QUANTITY; index++)
  11993. {
  11994. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11995. {
  11996. checkState_Faulted = TRUE; //OCPP Status
  11997. }
  11998. }
  11999. for (int index = 0; index < GB_QUANTITY; index++)
  12000. {
  12001. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12002. {
  12003. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12004. }
  12005. }
  12006. //check Charge Point state
  12007. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12008. {
  12009. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12010. {
  12011. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12012. }
  12013. }
  12014. //check Charge Point state
  12015. for (int index = 0; index < AC_QUANTITY; index++)
  12016. {
  12017. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12018. {
  12019. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12020. }
  12021. }
  12022. if(checkState_Faulted == TRUE)
  12023. {
  12024. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12025. goto end;
  12026. }
  12027. // Parsing payload
  12028. SendLocalList = json_tokener_parse(payload);
  12029. if(!is_error(SendLocalList))
  12030. {
  12031. // Required data
  12032. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12033. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12034. // Optional data
  12035. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12036. {
  12037. //Check UpdateType
  12038. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12039. {
  12040. //Local list full update
  12041. DEBUG_INFO("Local list full update.\n");
  12042. locallistVersion = 0;
  12043. OCPP_getListVerion();
  12044. /*if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  12045. {
  12046. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12047. goto end;
  12048. }*/
  12049. OCPP_cleanLocalList();
  12050. }
  12051. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12052. {
  12053. //Local list different update
  12054. DEBUG_INFO("Local list different update.\n");
  12055. locallistVersion = 0;
  12056. OCPP_getListVerion();
  12057. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  12058. {
  12059. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12060. goto end;
  12061. }
  12062. }
  12063. else
  12064. {
  12065. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12066. goto end;
  12067. }
  12068. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12069. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12070. {
  12071. 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")));
  12072. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12073. {
  12074. 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")));
  12075. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12076. 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")));
  12077. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12078. 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")));
  12079. }
  12080. // Add to db
  12081. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12082. {
  12083. //Local list full update
  12084. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12085. idx,
  12086. ShmOCPP16DataPH->SendLocalList.ListVersion,
  12087. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  12088. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12089. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12090. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12091. // update list
  12092. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  12093. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  12094. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12095. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12096. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12097. }
  12098. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12099. {
  12100. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12101. idx,
  12102. ShmOCPP16DataPH->SendLocalList.ListVersion,
  12103. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  12104. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12105. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12106. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12107. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  12108. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  12109. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12110. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12111. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12112. }
  12113. }
  12114. }
  12115. else
  12116. {
  12117. //Check UpdateType
  12118. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12119. {
  12120. //Local list full update
  12121. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12122. OCPP_cleanLocalList();
  12123. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12124. goto end;
  12125. }
  12126. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12127. {
  12128. //Local list different update
  12129. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12130. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12131. goto end;
  12132. }
  12133. }
  12134. result = PASS;
  12135. }
  12136. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12137. end:
  12138. json_object_put(SendLocalList);
  12139. sendSendLocalListConfirmation(uuid, comfirmstr);
  12140. return result;
  12141. }
  12142. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12143. {
  12144. mtrace();
  12145. int result = FAIL;
  12146. struct StructSetChargingProfile SetProfileReq = {0};
  12147. int tempchargingProfileIdInt;
  12148. int tempstackLevelInt;
  12149. int chargingSchedulePeriodCount = 0;
  12150. char comfirmstr[20]={0};
  12151. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  12152. char rmFileCmd[128]={0};
  12153. int profileQuantity = 0;
  12154. int replaceableProfileCnt = 0;
  12155. json_object *SetChargingProfile;
  12156. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12157. SetChargingProfile = json_tokener_parse(payload);
  12158. if(!is_error(SetChargingProfile))
  12159. {
  12160. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12161. {
  12162. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12163. }
  12164. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12165. {
  12166. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12167. {
  12168. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12169. }
  12170. else
  12171. {
  12172. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12173. DEBUG_WARN("Cannot find chargingProfileId field.");
  12174. goto end;
  12175. }
  12176. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12177. {
  12178. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12179. }
  12180. else
  12181. {
  12182. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12183. DEBUG_WARN("Cannot find stackLevel field.");
  12184. goto end;
  12185. }
  12186. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12187. {
  12188. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12189. }
  12190. else
  12191. {
  12192. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12193. DEBUG_WARN("Cannot find chargingProfilePurpose field.");
  12194. goto end;
  12195. }
  12196. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12197. {
  12198. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12199. }
  12200. else
  12201. {
  12202. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12203. DEBUG_WARN("Cannot find chargingProfileKind field.");
  12204. goto end;
  12205. }
  12206. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12207. {
  12208. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12209. }
  12210. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12211. {
  12212. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12213. }
  12214. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12215. {
  12216. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12217. }
  12218. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12219. {
  12220. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12221. }
  12222. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12223. {
  12224. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12225. {
  12226. 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")));
  12227. }
  12228. else
  12229. {
  12230. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12231. DEBUG_WARN("Cannot find chargingRateUnit field.");
  12232. goto end;
  12233. }
  12234. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12235. {
  12236. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12237. }
  12238. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12239. {
  12240. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12241. }
  12242. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12243. {
  12244. 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")));
  12245. }
  12246. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12247. {
  12248. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12249. if(chargingSchedulePeriodCount <= 10)
  12250. {
  12251. 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++)
  12252. {
  12253. 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)
  12254. {
  12255. 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"));
  12256. }
  12257. else
  12258. {
  12259. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12260. DEBUG_WARN("Cannot find startPeriod field.");
  12261. goto end;
  12262. }
  12263. 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)
  12264. {
  12265. 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"));
  12266. }
  12267. else
  12268. {
  12269. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12270. DEBUG_WARN("Cannot find limit field.");
  12271. goto end;
  12272. }
  12273. 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)
  12274. {
  12275. 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"));
  12276. }
  12277. }
  12278. }
  12279. }
  12280. else
  12281. {
  12282. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12283. DEBUG_WARN("Cannot find chargingSchedulePeriod field.");
  12284. goto end;
  12285. }
  12286. }
  12287. else
  12288. {
  12289. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12290. DEBUG_WARN("Cannot find chargingSchedule field.");
  12291. goto end;
  12292. }
  12293. }
  12294. }
  12295. // Profile periods quantity check
  12296. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12297. {
  12298. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12299. goto end;
  12300. }
  12301. // Check invalid limit
  12302. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  12303. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  12304. {
  12305. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12306. {
  12307. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12308. {
  12309. 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)))) ||
  12310. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12311. {
  12312. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12313. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12314. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12315. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12316. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12317. goto end;
  12318. }
  12319. }
  12320. }
  12321. else
  12322. {
  12323. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12324. {
  12325. 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) ||
  12326. (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)))
  12327. {
  12328. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12329. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12330. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12331. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12332. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12333. goto end;
  12334. }
  12335. }
  12336. }
  12337. }
  12338. // Profile purpose info check
  12339. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12340. {
  12341. FILE *fp;
  12342. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12343. if(SetProfileReq.ConnectorId != 0)
  12344. {
  12345. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12346. goto end;
  12347. }
  12348. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12349. if (!fp)
  12350. {
  12351. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12352. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12353. }
  12354. else
  12355. {
  12356. char *line = NULL;
  12357. size_t len = 0;
  12358. while(getline(&line, &len, fp) != -1)
  12359. {
  12360. json_object *obj = NULL;
  12361. obj = json_tokener_parse(line);
  12362. if(is_error(obj))
  12363. {
  12364. DEBUG_ERROR("Parse txProfile from file error.\n");
  12365. }
  12366. else
  12367. {
  12368. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12369. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12370. {
  12371. profileQuantity += 1;
  12372. }
  12373. else
  12374. replaceableProfileCnt += 1;
  12375. }
  12376. }
  12377. }
  12378. fclose(fp);
  12379. }
  12380. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12381. {
  12382. FILE *fp;
  12383. char filename[128]={0};
  12384. int tmpProfileQuantity;
  12385. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12386. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12387. {
  12388. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12389. goto end;
  12390. }
  12391. if(SetProfileReq.ConnectorId == 0)
  12392. {
  12393. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12394. {
  12395. tmpProfileQuantity = 0;
  12396. memset(filename, 0, ARRAY_SIZE(filename));
  12397. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12398. fp = fopen(filename, "r");
  12399. if (!fp)
  12400. {
  12401. DEBUG_INFO("%s does not create.\n", filename);
  12402. fp = fopen(filename, "w+");
  12403. }
  12404. else
  12405. {
  12406. char *line = NULL;
  12407. size_t len = 0;
  12408. while(getline(&line, &len, fp) != -1)
  12409. {
  12410. json_object *obj = NULL;
  12411. obj = json_tokener_parse(line);
  12412. if(is_error(obj))
  12413. {
  12414. DEBUG_ERROR("Parse txProfile from file error.\n");
  12415. }
  12416. else
  12417. {
  12418. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12419. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12420. {
  12421. tmpProfileQuantity += 1;
  12422. }
  12423. else
  12424. replaceableProfileCnt += 1;
  12425. }
  12426. }
  12427. }
  12428. fclose(fp);
  12429. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12430. }
  12431. }
  12432. else
  12433. {
  12434. memset(filename, 0, ARRAY_SIZE(filename));
  12435. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12436. fp = fopen(filename, "r");
  12437. if (!fp)
  12438. {
  12439. DEBUG_INFO("%s does not create.\n", filename);
  12440. fp = fopen(filename, "w+");
  12441. }
  12442. else
  12443. {
  12444. char *line = NULL;
  12445. size_t len = 0;
  12446. while(getline(&line, &len, fp) != -1)
  12447. {
  12448. json_object *obj = NULL;
  12449. obj = json_tokener_parse(line);
  12450. if(is_error(obj))
  12451. {
  12452. DEBUG_ERROR("Parse txProfile from file error.\n");
  12453. }
  12454. else
  12455. {
  12456. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12457. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12458. {
  12459. profileQuantity += 1;
  12460. }
  12461. else
  12462. replaceableProfileCnt += 1;
  12463. }
  12464. }
  12465. }
  12466. fclose(fp);
  12467. }
  12468. }
  12469. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12470. {
  12471. int isMatchTransactiodId= FALSE;
  12472. FILE *fp;
  12473. char filename[128]={0};
  12474. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12475. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12476. if(SetProfileReq.ConnectorId == 0)
  12477. {
  12478. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12479. goto end;
  12480. }
  12481. int tempIndex = 0;
  12482. //check Transaction active
  12483. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12484. {
  12485. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12486. {
  12487. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12488. }
  12489. else
  12490. {
  12491. tempIndex = SetProfileReq.ConnectorId -1;
  12492. }
  12493. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12494. {
  12495. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12496. {
  12497. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12498. {
  12499. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12500. {
  12501. isMatchTransactiodId = TRUE;
  12502. break;
  12503. }
  12504. }
  12505. }
  12506. }
  12507. }
  12508. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12509. {
  12510. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12511. {
  12512. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12513. }
  12514. else
  12515. {
  12516. tempIndex = SetProfileReq.ConnectorId -1;
  12517. }
  12518. for (int index = 0; index < CCS_QUANTITY; index++)
  12519. {
  12520. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12521. {
  12522. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12523. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12524. {
  12525. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12526. {
  12527. isMatchTransactiodId = TRUE;
  12528. break;
  12529. }
  12530. }
  12531. }
  12532. }
  12533. }
  12534. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12535. {
  12536. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12537. {
  12538. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12539. }
  12540. else
  12541. {
  12542. tempIndex = SetProfileReq.ConnectorId -1;
  12543. }
  12544. for (int index = 0; index < GB_QUANTITY; index++)
  12545. {
  12546. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12547. {
  12548. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12549. {
  12550. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12551. {
  12552. isMatchTransactiodId = TRUE;
  12553. break;
  12554. }
  12555. }
  12556. }
  12557. }
  12558. }
  12559. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12560. {
  12561. tempIndex = SetProfileReq.ConnectorId -1;
  12562. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12563. {
  12564. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12565. {
  12566. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12567. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12568. {
  12569. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12570. {
  12571. isMatchTransactiodId = TRUE;
  12572. break;
  12573. }
  12574. }
  12575. }
  12576. }
  12577. }
  12578. else
  12579. {
  12580. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12581. {
  12582. tempIndex = 2;
  12583. }
  12584. else
  12585. {
  12586. tempIndex = (SetProfileReq.ConnectorId -1);
  12587. }
  12588. for (int index = 0; index < AC_QUANTITY; index++)
  12589. {
  12590. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12591. {
  12592. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12593. {
  12594. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12595. {
  12596. isMatchTransactiodId = TRUE;
  12597. break;
  12598. }
  12599. }
  12600. }
  12601. }
  12602. }
  12603. //check Transaction active
  12604. if(isMatchTransactiodId == FALSE)
  12605. {
  12606. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12607. goto end;
  12608. }
  12609. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12610. {
  12611. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12612. goto end;
  12613. }
  12614. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12615. fp = fopen(filename, "r");
  12616. if (!fp)
  12617. {
  12618. DEBUG_INFO("%s does not create.\n", filename);
  12619. fp = fopen(filename, "w+");
  12620. }
  12621. else
  12622. {
  12623. char *line = NULL;
  12624. size_t len = 0;
  12625. while(getline(&line, &len, fp) != -1)
  12626. {
  12627. json_object *obj = NULL;
  12628. obj = json_tokener_parse(line);
  12629. if(is_error(obj))
  12630. {
  12631. DEBUG_ERROR("Parse txProfile from file error.\n");
  12632. }
  12633. else
  12634. {
  12635. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12636. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12637. {
  12638. profileQuantity += 1;
  12639. }
  12640. else
  12641. replaceableProfileCnt += 1;
  12642. }
  12643. }
  12644. }
  12645. fclose(fp);
  12646. }
  12647. // Check ChargeProfileMaxStackLevel
  12648. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12649. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12650. {
  12651. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12652. goto end;
  12653. }
  12654. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12655. {
  12656. FILE *fp;
  12657. char dataLine[4096]={0};
  12658. char fnametemp[128]={0};
  12659. int tmpProfileQuantity;
  12660. //Check ChargePointMaxProfile.json exit
  12661. profileQuantity = 0;
  12662. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  12663. {
  12664. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  12665. //Check Charging Profile Count
  12666. tmpProfileQuantity = 0;
  12667. while(fscanf(fp, "%s", dataLine) != EOF)
  12668. {
  12669. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12670. {
  12671. profileQuantity += 1;
  12672. tmpProfileQuantity += 1;
  12673. }
  12674. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12675. }
  12676. fclose(fp);
  12677. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12678. }
  12679. //Check TxDefaultProfile_%d.json
  12680. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12681. {
  12682. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12683. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12684. if((access(fnametemp,F_OK))!=-1)
  12685. {
  12686. fp = fopen(fnametemp, "r");
  12687. //Check Charging Profile Count
  12688. tmpProfileQuantity = 0;
  12689. while(fscanf(fp, "%s", dataLine) != EOF)
  12690. {
  12691. //DEBUG_INFO("word=%s\n",word);
  12692. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12693. {
  12694. profileQuantity += 1;
  12695. tmpProfileQuantity += 1;
  12696. }
  12697. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12698. }
  12699. fclose(fp);
  12700. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12701. }
  12702. }
  12703. //Check TxProfile_%d.json
  12704. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12705. {
  12706. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12707. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  12708. if((access(fnametemp,F_OK))!=-1)
  12709. {
  12710. fp = fopen(fnametemp, "r");
  12711. //Check Charging Profile Count
  12712. tmpProfileQuantity = 0;
  12713. while(fscanf(fp, "%s", dataLine) != EOF)
  12714. {
  12715. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12716. {
  12717. profileQuantity += 1;
  12718. tmpProfileQuantity += 1;
  12719. }
  12720. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12721. }
  12722. fclose(fp);
  12723. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12724. }
  12725. }
  12726. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12727. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  12728. // To check total Profile quantity
  12729. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  12730. {
  12731. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12732. {
  12733. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12734. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12735. goto end;
  12736. }
  12737. }
  12738. else
  12739. {
  12740. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  12741. {
  12742. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  12743. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12744. goto end;
  12745. }
  12746. }
  12747. }
  12748. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12749. //**********************************Write to File********************************************************/
  12750. {
  12751. FILE *infile;
  12752. FILE *outfile;
  12753. char dataLine[4096]={0};
  12754. char filename[128]={0};
  12755. int chkChar=0;
  12756. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12757. {
  12758. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12759. {
  12760. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12761. }
  12762. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12763. {
  12764. if(SetProfileReq.ConnectorId==0)
  12765. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12766. else
  12767. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12768. }
  12769. else
  12770. {
  12771. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12772. }
  12773. infile = fopen (filename, "r");
  12774. outfile = fopen (tempfile, "w");
  12775. chkChar = fgetc(infile);
  12776. rewind(infile);
  12777. if(chkChar == EOF)
  12778. {
  12779. // Profile is empty
  12780. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12781. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12782. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12783. fclose(infile);
  12784. fclose(outfile);
  12785. sprintf(rmFileCmd,"rm -f %s",filename);
  12786. system(rmFileCmd);
  12787. rename(tempfile, filename);
  12788. }
  12789. else
  12790. {
  12791. // Profile is not empty
  12792. int ChargingProfileAdded = FALSE;
  12793. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12794. {
  12795. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12796. json_object *tmpChargingProfile;
  12797. tmpChargingProfile = json_tokener_parse(dataLine);
  12798. if(!is_error(SetChargingProfile))
  12799. {
  12800. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12801. {
  12802. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12803. {
  12804. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12805. }
  12806. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12807. {
  12808. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  12809. }
  12810. }
  12811. }
  12812. json_object_put(tmpChargingProfile);
  12813. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12814. {
  12815. if(ChargingProfileAdded == FALSE)
  12816. {
  12817. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12818. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12819. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12820. ChargingProfileAdded = TRUE;
  12821. }
  12822. }
  12823. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  12824. {
  12825. if(ChargingProfileAdded == FALSE)
  12826. {
  12827. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12828. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12829. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12830. ChargingProfileAdded = TRUE;
  12831. }
  12832. }
  12833. else
  12834. {
  12835. fprintf(outfile,"%s\n",dataLine);
  12836. if(ChargingProfileAdded == FALSE)
  12837. {
  12838. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12839. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12840. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12841. ChargingProfileAdded = TRUE;
  12842. }
  12843. }
  12844. } // end of while loop
  12845. fclose(infile);
  12846. fclose(outfile);
  12847. sprintf(rmFileCmd,"rm -f %s",filename);
  12848. system(rmFileCmd);
  12849. rename(tempfile, filename);
  12850. }
  12851. }
  12852. sleep(1);
  12853. result = TRUE;
  12854. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12855. }
  12856. end:
  12857. json_object_put(SetChargingProfile);
  12858. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12859. {
  12860. if(SetProfileReq.ConnectorId == 0)
  12861. {
  12862. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12863. {
  12864. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  12865. }
  12866. }
  12867. else
  12868. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12869. }
  12870. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12871. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12872. return result;
  12873. }
  12874. int handleTriggerMessageRequest(char *uuid, char *payload)
  12875. {
  12876. mtrace();
  12877. int result = FAIL;
  12878. int connectorIdIsNULL = FALSE;
  12879. int connectorIdInt =0;
  12880. char sstr[40]={0},sstrtemp[100]={ 0 };
  12881. char requestedMessagestr[40]={0};
  12882. char comfirmstr[20]={0};
  12883. int c = 0;
  12884. char *loc;
  12885. DEBUG_INFO("handleTriggerMessageRequest\n");
  12886. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12887. strcpy(sstrtemp, stringtrimspace(payload));
  12888. c = 0;
  12889. loc = strstr(sstrtemp, "requestedMessage");
  12890. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12891. {
  12892. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12893. c++;
  12894. }
  12895. sstr[c] = '\0';
  12896. strcpy(requestedMessagestr, sstr);
  12897. c = 0;
  12898. loc = strstr(sstrtemp, "connectorId");
  12899. if(loc == NULL)
  12900. {
  12901. connectorIdIsNULL = TRUE;
  12902. }
  12903. else
  12904. {
  12905. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12906. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12907. {
  12908. sstr[c] = loc[strlen("connectorId")+2+c];
  12909. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12910. c++;
  12911. }
  12912. sstr[c] = '\0';
  12913. connectorIdInt = atoi(sstr);
  12914. }
  12915. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12916. {
  12917. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12918. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12919. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12920. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12921. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12922. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12923. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12924. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12925. {
  12926. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12927. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12928. return TRUE;
  12929. }
  12930. else
  12931. {
  12932. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12933. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12934. }
  12935. }
  12936. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12937. {
  12938. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12939. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12940. return TRUE;
  12941. }
  12942. //==========================
  12943. // Trigger message
  12944. //==========================
  12945. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12946. {
  12947. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12948. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12949. {
  12950. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12951. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12952. }
  12953. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12954. }
  12955. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12956. {
  12957. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  12958. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12959. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12960. }
  12961. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12962. {
  12963. //sendBootNotificationRequest();
  12964. server_sign = FALSE;
  12965. }
  12966. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12967. {
  12968. refreshStartTimer(&clientTime.Heartbeat);
  12969. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12970. }
  12971. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12972. {
  12973. if(connectorIdIsNULL == FALSE)
  12974. {
  12975. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12976. {
  12977. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12978. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12979. }
  12980. }
  12981. else
  12982. {
  12983. for(int idx=0;idx< gunTotalNumber;idx++)
  12984. {
  12985. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12986. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12987. }
  12988. }
  12989. }
  12990. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12991. {
  12992. if(connectorIdIsNULL == FALSE)
  12993. {
  12994. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12995. {
  12996. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12997. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  12998. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12999. }
  13000. }
  13001. else
  13002. {
  13003. for(int idx=0;idx< gunTotalNumber;idx++)
  13004. {
  13005. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  13006. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13007. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13008. }
  13009. }
  13010. }
  13011. return result;
  13012. }
  13013. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13014. {
  13015. mtrace();
  13016. int result = FAIL;
  13017. int connectorIdInt =0;
  13018. char comfirmstr[20]={0};
  13019. int tempIndex = 0;
  13020. json_object *UnlockConnector;
  13021. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13022. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13023. UnlockConnector = json_tokener_parse(payload);
  13024. if(!is_error(UnlockConnector))
  13025. {
  13026. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13027. {
  13028. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13029. }
  13030. }
  13031. json_object_put(UnlockConnector);
  13032. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13033. if(gunTotalNumber == 0)
  13034. {
  13035. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13036. goto end;
  13037. }
  13038. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13039. {
  13040. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13041. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13042. goto end;
  13043. }
  13044. else
  13045. {
  13046. //check Transaction active
  13047. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13048. {
  13049. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13050. {
  13051. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13052. }
  13053. else
  13054. {
  13055. tempIndex = connectorIdInt -1;
  13056. }
  13057. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13058. {
  13059. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13060. {
  13061. //stop Transaction
  13062. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13063. }
  13064. }
  13065. }
  13066. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13067. {
  13068. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13069. {
  13070. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13071. }
  13072. else
  13073. {
  13074. tempIndex = connectorIdInt -1;
  13075. }
  13076. for (int index = 0; index < CCS_QUANTITY; index++)
  13077. {
  13078. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13079. {
  13080. //stop Transaction
  13081. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13082. }
  13083. }
  13084. }
  13085. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13086. {
  13087. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13088. {
  13089. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13090. }
  13091. else
  13092. {
  13093. tempIndex = connectorIdInt -1;
  13094. }
  13095. for (int index = 0; index < GB_QUANTITY; index++)
  13096. {
  13097. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13098. {
  13099. //stop Transaction
  13100. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13101. }
  13102. }
  13103. }
  13104. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13105. {
  13106. tempIndex = connectorIdInt -1;
  13107. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13108. {
  13109. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13110. {
  13111. //stop Transaction
  13112. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13113. }
  13114. }
  13115. }
  13116. else
  13117. {
  13118. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13119. {
  13120. tempIndex = 2;
  13121. }
  13122. else
  13123. {
  13124. tempIndex = connectorIdInt-1;
  13125. }
  13126. for (int index = 0; index < AC_QUANTITY; index++)
  13127. {
  13128. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  13129. {
  13130. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13131. }
  13132. }
  13133. }
  13134. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  13135. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  13136. result = TRUE;
  13137. return result;
  13138. }
  13139. end:
  13140. //json_object_put(obj); --- remove temporally
  13141. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  13142. return result;
  13143. }
  13144. static char UpdateFirmwarepayloadData[300]={0};
  13145. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13146. {
  13147. mtrace();
  13148. int result = FAIL;
  13149. pthread_t t;
  13150. sendUpdateFirmwareConfirmation(uuid);
  13151. memset(UpdateFirmwarepayloadData, 0, 300);
  13152. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  13153. if(!interLock.isUpdateFirmwareGoing)
  13154. {
  13155. interLock.isUpdateFirmwareGoing = 1;
  13156. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  13157. sleep(1);
  13158. }
  13159. else
  13160. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13161. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  13162. return result;
  13163. }
  13164. void *UpdateFirmwareProcess(void *data)
  13165. {
  13166. pthread_detach(pthread_self());
  13167. mtrace();
  13168. int retriesInt =0, retryIntervalInt=0;
  13169. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  13170. int port=0;
  13171. char locationstr[512]={0}, retrieveDatestr[36]={0};
  13172. int isSuccess = 0;
  13173. char ftpbuf[512];
  13174. char temp[100];
  13175. char * pch;
  13176. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13177. json_object *UpdateFirmware;
  13178. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  13179. if(!is_error(UpdateFirmware))
  13180. {
  13181. // Required data
  13182. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13183. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13184. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13185. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13186. // Optional data
  13187. if(json_object_object_get(UpdateFirmware, "retries"))
  13188. {
  13189. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13190. }
  13191. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13192. {
  13193. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13194. }
  13195. }
  13196. json_object_put(UpdateFirmware);
  13197. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13198. memset(path, 0, ARRAY_SIZE(path));
  13199. // Wait retrieveData
  13200. if(strlen(retrieveDatestr) > 10)
  13201. {
  13202. do
  13203. {
  13204. sleep(1);
  13205. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13206. }
  13207. // Ready to download
  13208. system("rm -f /mnt/*");
  13209. if(strncmp(locationstr,"http", 4) == 0)
  13210. {
  13211. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13212. sprintf(ftppath,"/%s", path);
  13213. DEBUG_INFO("locationstr: %s\n", locationstr);
  13214. DEBUG_INFO("protocol: %s\n",protocol);
  13215. DEBUG_INFO("host: %s\n",host);
  13216. DEBUG_INFO("path: %s\n",path);
  13217. DEBUG_INFO("ftppath: %s\n",ftppath);
  13218. int ftppathlen=strlen(ftppath);
  13219. int i=1;
  13220. char filenametemp[50];
  13221. while(i < ftppathlen)
  13222. {
  13223. int len=ftppathlen-i;
  13224. if(ftppath[len]== 47) // '/' ascll code: 47
  13225. {
  13226. DEBUG_INFO("compare '/' all right\n");
  13227. break;
  13228. }
  13229. i=i+1;
  13230. }
  13231. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13232. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13233. filenametemp[i+1] = 0;
  13234. do
  13235. {
  13236. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13237. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13238. sleep(1);
  13239. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13240. if(!isSuccess)
  13241. {
  13242. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13243. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13244. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13245. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13246. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13247. }
  13248. else
  13249. {
  13250. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13251. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13252. }
  13253. retriesInt--;
  13254. }while((isSuccess == 0)&&(retriesInt >= 0));
  13255. }
  13256. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  13257. {
  13258. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13259. memset(temp, 0, ARRAY_SIZE(temp));
  13260. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13261. strcpy(ftpbuf, locationstr);
  13262. int ftppathlen=strlen(ftpbuf);
  13263. int i=1;
  13264. char filenametemp[50];
  13265. while(i < ftppathlen)
  13266. {
  13267. int len=ftppathlen-i;
  13268. if(ftpbuf[len]== 47) // '/' ascii code: 47
  13269. {
  13270. DEBUG_INFO(" compare '/' all right\n");
  13271. break;
  13272. }
  13273. i=i+1;
  13274. }
  13275. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13276. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13277. filenametemp[i+1] = 0;
  13278. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13279. pch=strchr(temp,'@');
  13280. if(pch==NULL)
  13281. {
  13282. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13283. protocol, host, &port, path);
  13284. strcpy(user,"anonymous");
  13285. strcpy(password,"");
  13286. }
  13287. else
  13288. {
  13289. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  13290. protocol, user, host, &port, path);
  13291. }
  13292. sscanf(host,"%[^/]%s",host1, path1);
  13293. sprintf(ftppath,"%s:/%s", host,path);
  13294. if(port == 0)
  13295. {
  13296. port = 21;
  13297. }
  13298. do
  13299. {
  13300. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13301. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13302. sleep(1);
  13303. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, filenametemp, locationstr);
  13304. if(!isSuccess)
  13305. {
  13306. //BulldogUtil.sleepMs(interval*1000);
  13307. DEBUG_INFO("Update firmware request and download file fail.\n");
  13308. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13309. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13310. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13311. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13312. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13313. }
  13314. else
  13315. {
  13316. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13317. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13318. }
  13319. retriesInt--;
  13320. }while((!isSuccess)&&(retriesInt >= 0));
  13321. }
  13322. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13323. {
  13324. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13325. memset(temp, 0, ARRAY_SIZE(temp));
  13326. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13327. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13328. int ftppathlen=strlen(ftpbuf);
  13329. int i=1;
  13330. char filenametemp[50];
  13331. while(i < ftppathlen)
  13332. {
  13333. int len=ftppathlen-i;
  13334. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13335. {
  13336. DEBUG_INFO(" compare '/' all right\n");
  13337. break;
  13338. }
  13339. i=i+1;
  13340. }
  13341. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13342. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13343. filenametemp[i+1] = 0;
  13344. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13345. pch=strchr(temp,'@');
  13346. if(pch==NULL)
  13347. {
  13348. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13349. protocol, host, &port, path);
  13350. strcpy(user,"anonymous");
  13351. strcpy(password,"");
  13352. }
  13353. else
  13354. {
  13355. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13356. protocol, user, password, host, &port, path);
  13357. }
  13358. sscanf(host,"%[^/]%s",host1, path1);
  13359. sprintf(ftppath,"%s", path1);
  13360. //DEBUG_INFO("protocol =%s\n",protocol);
  13361. //DEBUG_INFO("user =%s\n",user);
  13362. //DEBUG_INFO("password =%s\n",password);
  13363. //DEBUG_INFO("host1 =%s\n",host1);
  13364. //DEBUG_INFO("port =%d\n",port);
  13365. //DEBUG_INFO("path1 =%s\n",path1);
  13366. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13367. //ftpFile(host, user, password, port, ftppath, fname);
  13368. //download firmware pthred
  13369. if(port == 0)
  13370. {
  13371. port = 21;
  13372. }
  13373. do
  13374. {
  13375. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13376. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13377. sleep(1);
  13378. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13379. if(!isSuccess)
  13380. {
  13381. //BulldogUtil.sleepMs(interval*1000);
  13382. DEBUG_INFO("Update firmware request and download file fail.\n");
  13383. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13384. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13385. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13386. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13387. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13388. }
  13389. else
  13390. {
  13391. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13392. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13393. }
  13394. retriesInt--;
  13395. }while((!isSuccess)&&(retriesInt >= 0));
  13396. }
  13397. else
  13398. {
  13399. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13400. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13401. sleep(1);
  13402. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13403. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13404. }
  13405. // OCPPPH only, must announce CSU upgrade firmware
  13406. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13407. interLock.isUpdateFirmwareGoing = 0;
  13408. pthread_exit(NULL);
  13409. }
  13410. int handleCertificateSignedRequest(char *uuid, char *payload)
  13411. {
  13412. mtrace();
  13413. int result = PASS;
  13414. json_object *CertificateSigned;
  13415. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13416. CertificateSigned = json_tokener_parse(payload);
  13417. if(!is_error(CertificateSigned))
  13418. {
  13419. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13420. }
  13421. json_object_put(CertificateSigned);
  13422. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  13423. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  13424. fclose(fp);
  13425. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13426. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  13427. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  13428. sendCertificateSignedConfirmation(uuid);
  13429. return result;
  13430. }
  13431. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13432. {
  13433. mtrace();
  13434. int result = PASS;
  13435. json_object *DeleteCertificate;
  13436. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13437. DeleteCertificate = json_tokener_parse(payload);
  13438. if(!is_error(DeleteCertificate))
  13439. {
  13440. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13441. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13442. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13443. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13444. }
  13445. json_object_put(DeleteCertificate);
  13446. /*
  13447. * TODO: Delete certificateSigned process
  13448. */
  13449. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  13450. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  13451. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  13452. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  13453. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  13454. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  13455. sendDeleteCertificateConfirmation(uuid);
  13456. return result;
  13457. }
  13458. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  13459. {
  13460. mtrace();
  13461. int result = PASS;
  13462. json_object *ExtendedTriggerMessage;
  13463. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  13464. ExtendedTriggerMessage = json_tokener_parse(payload);
  13465. if(!is_error(ExtendedTriggerMessage))
  13466. {
  13467. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  13468. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  13469. {
  13470. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  13471. }
  13472. else
  13473. {
  13474. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  13475. }
  13476. }
  13477. json_object_put(ExtendedTriggerMessage);
  13478. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  13479. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  13480. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13481. {
  13482. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13483. }
  13484. else
  13485. {
  13486. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13487. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13488. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13489. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13490. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13491. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13492. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13493. {
  13494. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13495. }
  13496. else
  13497. {
  13498. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13499. }
  13500. }
  13501. sendExtendedTriggerMessageConfirmation(uuid);
  13502. //==========================
  13503. // Trigger message
  13504. //==========================
  13505. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13506. {
  13507. //sendBootNotificationRequest();
  13508. server_sign = FALSE;
  13509. }
  13510. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13511. {
  13512. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  13513. }
  13514. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13515. {
  13516. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  13517. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13518. {
  13519. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13520. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13521. }
  13522. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13523. }
  13524. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13525. {
  13526. refreshStartTimer(&clientTime.Heartbeat);
  13527. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  13528. }
  13529. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13530. {
  13531. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13532. {
  13533. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13534. }
  13535. else
  13536. {
  13537. for(int idx=0;idx< gunTotalNumber;idx++)
  13538. {
  13539. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13540. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13541. }
  13542. }
  13543. }
  13544. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13545. {
  13546. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  13547. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  13548. {
  13549. 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\" &");
  13550. }
  13551. }
  13552. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13553. {
  13554. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13555. {
  13556. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13557. }
  13558. else
  13559. {
  13560. for(int idx=0;idx< gunTotalNumber;idx++)
  13561. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13562. }
  13563. }
  13564. return result;
  13565. }
  13566. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13567. {
  13568. mtrace();
  13569. int result = PASS;
  13570. json_object *GetInstalledCertificateIds;
  13571. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13572. GetInstalledCertificateIds = json_tokener_parse(payload);
  13573. if(!is_error(GetInstalledCertificateIds))
  13574. {
  13575. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13576. }
  13577. json_object_put(GetInstalledCertificateIds);
  13578. /*
  13579. * TODO: Return installed certificate process
  13580. */
  13581. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13582. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  13583. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13584. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  13585. sendGetInstalledCertificateIdsConfirmation(uuid);
  13586. return result;
  13587. }
  13588. int handleGetLogRequest(char *uuid, char *payload)
  13589. {
  13590. mtrace();
  13591. int result = PASS;
  13592. json_object *GetLog;
  13593. DEBUG_INFO("handleGetLogRequest...\n");
  13594. GetLog = json_tokener_parse(payload);
  13595. if(!is_error(GetLog))
  13596. {
  13597. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13598. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13599. if(json_object_object_get(GetLog, "retries") != NULL)
  13600. {
  13601. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13602. }
  13603. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13604. {
  13605. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13606. }
  13607. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13608. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13609. {
  13610. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13611. }
  13612. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13613. {
  13614. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13615. }
  13616. }
  13617. json_object_put(GetLog);
  13618. /*
  13619. * TODO: Upload log process
  13620. */
  13621. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  13622. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  13623. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  13624. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  13625. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  13626. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  13627. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  13628. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  13629. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  13630. sendGetLogConfirmation(uuid);
  13631. return result;
  13632. }
  13633. int handleInstallCertificateRequest(char *uuid, char *payload)
  13634. {
  13635. mtrace();
  13636. int result = PASS;
  13637. json_object *InstallCertificate;
  13638. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13639. InstallCertificate = json_tokener_parse(payload);
  13640. if(!is_error(InstallCertificate))
  13641. {
  13642. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13643. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13644. /*
  13645. * TODO: Install certificate process
  13646. */
  13647. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  13648. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  13649. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  13650. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  13651. sendInstallCertificateConfirmation(uuid);
  13652. }
  13653. json_object_put(InstallCertificate);
  13654. return result;
  13655. }
  13656. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13657. {
  13658. mtrace();
  13659. int result = PASS;
  13660. json_object *SignedUpdateFirmware;
  13661. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13662. SignedUpdateFirmware = json_tokener_parse(payload);
  13663. if(!is_error(SignedUpdateFirmware))
  13664. {
  13665. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13666. {
  13667. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13668. }
  13669. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13670. {
  13671. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13672. }
  13673. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13674. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13675. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13676. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13677. {
  13678. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13679. }
  13680. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13681. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13682. }
  13683. json_object_put(SignedUpdateFirmware);
  13684. /*
  13685. * TODO: Upgrade firmware process
  13686. */
  13687. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13688. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  13689. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  13690. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  13691. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  13692. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  13693. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  13694. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  13695. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  13696. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  13697. sendInstallCertificateConfirmation(uuid);
  13698. return result;
  13699. }
  13700. int handleUnknownRequest(char *uuid, char *payload)
  13701. {
  13702. mtrace();
  13703. int result = PASS;
  13704. DEBUG_INFO("handleUnknownRequest...\n");
  13705. sendUnknownConfirmation(uuid);
  13706. result = PASS;
  13707. return result;
  13708. }
  13709. //==========================================
  13710. // Handle server response routine
  13711. //==========================================
  13712. void handleAuthorizeResponse(char *payload, int gun_index)
  13713. {
  13714. mtrace();
  13715. char expiryDatestr[36]={0};
  13716. char parentIdTagstr[21]={0};
  13717. char statusstr[20]={0};
  13718. int expiryDateISNULL=FALSE;
  13719. int parentIdTagISNULL=FALSE;
  13720. DEBUG_INFO("handleAuthorizeResponse...\n");
  13721. json_object *Authorize;
  13722. Authorize = json_tokener_parse(payload);
  13723. if(!is_error(Authorize))
  13724. {
  13725. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13726. {
  13727. // Required data
  13728. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13729. // Optional data
  13730. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13731. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13732. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13733. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13734. }
  13735. }
  13736. json_object_put(Authorize);
  13737. if(expiryDateISNULL == FALSE)
  13738. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13739. if(parentIdTagISNULL == FALSE)
  13740. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13741. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  13742. //Update idTag information to authorization cache if supproted
  13743. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13744. {
  13745. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13746. }
  13747. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  13748. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13749. authorizeRetryTimes = 0;
  13750. }
  13751. void handleBootNotificationResponse(char *payload, int gun_index)
  13752. {
  13753. mtrace();
  13754. char statusStr[12]={0};
  13755. char currentTimeStr[30]={0};
  13756. int intervalInt = 0;
  13757. DEBUG_INFO("handleBootNotificationResponse...\n");
  13758. json_object *BootNotification;
  13759. BootNotification = json_tokener_parse(payload);
  13760. if(!is_error(BootNotification))
  13761. {
  13762. // Required data
  13763. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13764. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13765. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13766. }
  13767. json_object_put(BootNotification);
  13768. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13769. BootNotificationInterval = intervalInt;
  13770. //write back to ShmOCPP16DataPH->BootNotification
  13771. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  13772. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13773. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  13774. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13775. {
  13776. BootNotificationInterval = 0;
  13777. if((intervalInt == 0) || (intervalInt >= 10))
  13778. {
  13779. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13780. HeartBeatWaitTime = intervalInt;
  13781. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13782. }
  13783. server_sign = TRUE;
  13784. server_pending =FALSE;
  13785. }
  13786. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13787. {
  13788. server_pending = TRUE;
  13789. }
  13790. //syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  13791. srand(time(NULL));
  13792. refreshStartTimer(&clientTime.Heartbeat);
  13793. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13794. SetOcppConnStatus(TRUE);
  13795. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  13796. }
  13797. void handleDataTransferResponse(char *payload, int gun_index)
  13798. {
  13799. json_object *DataTransfer = json_tokener_parse(payload);
  13800. if(!is_error(DataTransfer))
  13801. {
  13802. // Required data
  13803. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13804. // Optional data
  13805. if(json_object_object_get(DataTransfer, "data") != NULL)
  13806. {
  13807. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13808. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13809. if(!is_error(Data))
  13810. {
  13811. if(json_object_object_get(Data, "msgId") != NULL)
  13812. {
  13813. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13814. {
  13815. 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")));
  13816. }
  13817. }
  13818. }
  13819. json_object_put(Data);
  13820. }
  13821. }
  13822. json_object_put(DataTransfer);
  13823. }
  13824. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13825. {
  13826. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13827. //struct json_object *obj;
  13828. // obj = json_tokener_parse(payload);
  13829. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13830. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13831. //No fields are defined.
  13832. }
  13833. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13834. {
  13835. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13836. //struct json_object *obj;
  13837. // obj = json_tokener_parse(payload);
  13838. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13839. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13840. //No fields are defined.
  13841. }
  13842. void handleHeartbeatResponse(char *payload, int gun_index)
  13843. {
  13844. mtrace();
  13845. DEBUG_INFO("handleHeartbeatResponse...\n");
  13846. json_object *Heartbeat;
  13847. Heartbeat = json_tokener_parse(payload);
  13848. if(!is_error(Heartbeat))
  13849. {
  13850. // Required data
  13851. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13852. }
  13853. json_object_put(Heartbeat);
  13854. if(FirstHeartBeat == 0)
  13855. {
  13856. FirstHeartBeat = 1;
  13857. DEBUG_INFO("FirstHeartBeat \n");
  13858. }
  13859. HeartBeatWithNOResponse = 0;
  13860. refreshStartTimer(&clientTime.Heartbeat);
  13861. //syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  13862. }
  13863. void handleMeterValuesResponse(char *payload, int gun_index)
  13864. {
  13865. mtrace();
  13866. DEBUG_INFO("handleMeterValuesResponse...\n");
  13867. isQueueSendable = 1;
  13868. }
  13869. void handleStartTransactionResponse(char *payload, int gun_index)
  13870. {
  13871. mtrace();
  13872. //int transactionIdInt = 0;
  13873. FILE *outfile;
  13874. char data[100]={0};
  13875. DEBUG_INFO("handleStartTransactionResponse...\n");
  13876. json_object *StartTransaction;
  13877. StartTransaction = json_tokener_parse(payload);
  13878. if(!is_error(StartTransaction))
  13879. {
  13880. // Required data
  13881. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13882. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13883. // Optional data
  13884. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13885. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13886. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13887. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13888. }
  13889. json_object_put(StartTransaction);
  13890. isQueueSendable = 1;
  13891. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13892. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13893. //-----------Start : write to the Queue TransactionId file -----------------//
  13894. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  13895. {}
  13896. else
  13897. {
  13898. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  13899. if(log == NULL)
  13900. {
  13901. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13902. return ;
  13903. }
  13904. else
  13905. {
  13906. fclose(log);
  13907. }
  13908. }
  13909. // open file for writing
  13910. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13911. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  13912. {
  13913. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  13914. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13915. fputs(data, outfile);
  13916. fclose (outfile);
  13917. }
  13918. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13919. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13920. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13921. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  13922. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13923. }
  13924. void handleStatusNotificationResponse(char *payload, int gun_index)
  13925. {
  13926. mtrace();
  13927. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13928. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13929. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13930. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13931. }
  13932. void handleStopTransactionnResponse(char *payload, int gun_index)
  13933. {
  13934. mtrace();
  13935. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13936. json_object *StopTransaction;
  13937. StopTransaction = json_tokener_parse(payload);
  13938. if(!is_error(StopTransaction))
  13939. {
  13940. // Optional data
  13941. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13942. {
  13943. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13944. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13945. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13946. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13947. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13948. }
  13949. }
  13950. json_object_put(StopTransaction);
  13951. isQueueSendable = 1;
  13952. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13953. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13954. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13955. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13956. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13957. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13958. }
  13959. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13960. {
  13961. mtrace();
  13962. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13963. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  13964. }
  13965. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13966. {
  13967. mtrace();
  13968. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13969. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  13970. }
  13971. void handleSignCertificateResponse(char *payload, int gun_index)
  13972. {
  13973. mtrace();
  13974. DEBUG_INFO("handleSignCertificateResponse...\n");
  13975. json_object *SignCertificate;
  13976. SignCertificate = json_tokener_parse(payload);
  13977. if(!is_error(SignCertificate))
  13978. {
  13979. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13980. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  13981. }
  13982. json_object_put(SignCertificate);
  13983. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  13984. }
  13985. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13986. {
  13987. mtrace();
  13988. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13989. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13990. }
  13991. //==========================================
  13992. // Handle Error routine
  13993. //==========================================
  13994. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13995. {
  13996. mtrace();
  13997. #ifdef SystemLogMessage
  13998. DEBUG_INFO("errorCode: %s\n", errorCode);
  13999. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  14000. DEBUG_INFO("errorDetails: %s\n", payload);
  14001. #endif
  14002. }
  14003. //===============================================
  14004. // Common routine
  14005. //===============================================
  14006. int initialConfigurationTable(void)
  14007. {
  14008. //clock_t start_t, end_t, total_t;
  14009. FILE *fp;
  14010. FILE *outfile;
  14011. char str[512]={0};
  14012. char sstr[256]={0};
  14013. int c = 0;
  14014. char *loc;
  14015. int confVersion = 15;
  14016. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  14017. //start_t = clock();
  14018. //printf("Starting of the program, start_t = %ld\n", start_t);
  14019. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  14020. // Check configuration file size is correct
  14021. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  14022. {
  14023. struct stat st;
  14024. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  14025. if(st.st_size < 3100)
  14026. {
  14027. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  14028. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  14029. }
  14030. }
  14031. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  14032. {
  14033. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  14034. if(outfile == NULL)
  14035. {
  14036. DEBUG_INFO("Error opening file\n");
  14037. return FALSE;
  14038. }
  14039. /*Core Profile*/
  14040. //AllowOfflineTxForUnknownId
  14041. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14042. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14043. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  14044. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14045. //AuthorizationCacheEnabled
  14046. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14047. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14048. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14049. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14050. //AuthorizeRemoteTxRequests
  14051. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14052. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14053. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  14054. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14055. //BlinkRepeat
  14056. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14057. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14058. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14059. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14060. //ClockAlignedDataInterval
  14061. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14062. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14063. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14064. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14065. //ConnectionTimeOut
  14066. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14067. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14068. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14069. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14070. //GetConfigurationMaxKeys
  14071. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14072. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14073. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  14074. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14075. // HeartbeatInterval
  14076. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14077. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14078. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  14079. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14080. // LightIntensity
  14081. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14082. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14083. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14084. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14085. // LocalAuthorizeOffline
  14086. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  14087. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14088. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14089. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14090. // LocalPreAuthorize
  14091. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  14092. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14093. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14094. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14095. // MaxEnergyOnInvalidId
  14096. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14097. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14098. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14099. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14100. // MeterValuesAlignedData
  14101. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14102. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14103. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14104. 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" );
  14105. else
  14106. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14107. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14108. // MeterValuesAlignedDataMaxLength
  14109. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14110. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14111. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14112. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  14113. else
  14114. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  14115. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14116. // MeterValuesSampledData
  14117. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14118. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14119. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14120. 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" );
  14121. else
  14122. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  14123. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14124. // MeterValuesSampledDataMaxLength
  14125. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14126. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14127. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14128. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  14129. else
  14130. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  14131. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14132. // MeterValueSampleInterval
  14133. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14134. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14135. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  14136. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14137. // MinimumStatusDuration
  14138. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14139. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14140. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  14141. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  14142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14143. // NumberOfConnectors
  14144. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14145. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14146. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14147. {
  14148. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14149. }
  14150. else
  14151. {
  14152. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14153. }
  14154. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14155. // ResetRetries
  14156. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14157. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14158. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14159. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14160. // ConnectorPhaseRotation
  14161. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14162. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14163. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14165. // ConnectorPhaseRotationMaxLength
  14166. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14167. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14168. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14169. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14170. // StopTransactionOnEVSideDisconnect
  14171. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14172. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14173. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14174. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14175. // StopTransactionOnInvalidId
  14176. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  14177. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14178. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14179. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14180. // StopTxnAlignedData
  14181. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  14182. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14183. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  14184. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14185. // StopTxnAlignedDataMaxLength
  14186. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14187. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14188. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14189. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14190. // StopTxnSampledData
  14191. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14192. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14193. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14194. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  14195. else
  14196. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  14197. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14198. // StopTxnSampledDataMaxLength
  14199. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14200. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14201. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14202. {
  14203. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  14204. }
  14205. else
  14206. {
  14207. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  14208. }
  14209. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14210. // SupportedFeatureProfiles
  14211. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14212. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14213. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14214. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14215. // SupportedFeatureProfilesMaxLength
  14216. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14217. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14218. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14219. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14220. // TransactionMessageAttempts
  14221. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14222. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14223. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14224. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14225. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14226. // TransactionMessageRetryInterval
  14227. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14228. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14229. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14230. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14231. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14232. // UnlockConnectorOnEVSideDisconnect
  14233. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14234. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14235. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14236. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14237. // WebSocketPingInterval
  14238. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14239. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14240. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14241. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14242. // QueueOffLineMeterValues
  14243. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  14244. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14245. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  14246. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14247. // AuthorizationKey
  14248. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14249. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14250. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword );
  14251. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14252. // SecurityProfile
  14253. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14254. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14255. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  14256. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14257. // DefaultPrice
  14258. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14259. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14260. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14261. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14262. // CustomDisplayCostAndPrice
  14263. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14264. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14265. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14266. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14267. // CustomIdleFeeAfterStop
  14268. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14269. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14270. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14271. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14272. // SystemUptimeSec
  14273. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14274. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14275. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14276. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14277. // FreeVend
  14278. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14279. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14280. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  14281. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14282. // FreeVendIdtag
  14283. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14284. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14285. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14286. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14287. // OcppServer
  14288. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14289. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14290. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14291. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14292. // MaintainServer
  14293. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14294. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14295. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  14296. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14297. // StatusNotificationPeriodically
  14298. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  14299. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14300. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14301. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14302. // StatusNotificationInterval
  14303. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14304. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14305. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14306. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14307. // isEnableLocalPowerSharing
  14308. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  14309. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  14310. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  14311. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  14312. // PowerSharingServerIP
  14313. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  14314. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  14315. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  14316. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  14317. // EVCCID_PREFIX
  14318. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  14319. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  14320. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  14321. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  14322. // OffLineMaxChargingPower
  14323. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  14324. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  14325. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "0" );
  14326. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  14327. // Configuration Version
  14328. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  14329. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14330. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  14331. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14332. //* Local Auth List Management Profile*/
  14333. #if 0
  14334. //For OCTT Test Case
  14335. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14336. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  14337. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14338. #endif
  14339. #if 1
  14340. //LocalAuthListEnabled
  14341. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14342. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14343. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14344. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14345. #endif
  14346. //LocalAuthListMaxLength
  14347. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14348. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14349. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14350. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14351. //SendLocalListMaxLength
  14352. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14353. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14354. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  14355. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14356. //ReserveConnectorZeroSupported
  14357. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14358. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14359. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14360. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14361. //* Smart Charging Profile */
  14362. //ChargeProfileMaxStackLevel
  14363. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14364. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14365. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  14366. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14367. // ChargingScheduleAllowedChargingRateUnit
  14368. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14369. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14370. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  14371. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14372. // ChargingScheduleMaxPeriods
  14373. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14374. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14375. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14376. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14377. // ConnectorSwitch3to1PhaseSupported
  14378. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14379. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14380. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  14381. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14382. // MaxChargingProfilesInstalled
  14383. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14384. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14385. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  14386. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14387. fclose(outfile);
  14388. }
  14389. else
  14390. {
  14391. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  14392. char keystr[60]={0};
  14393. char readonlystr[10]={0};
  14394. char valuestr[256]={0};
  14395. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  14396. if(fp == NULL) {
  14397. DEBUG_INFO("Error opening file");
  14398. return FALSE;
  14399. }
  14400. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  14401. {
  14402. //DEBUG_INFO("Get Configuration \n");
  14403. if(strlen(str) > 0)
  14404. {
  14405. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14406. //*************************key*********************************/
  14407. if(strstr(str, "key") != NULL)
  14408. {
  14409. loc = strstr(str, "key");
  14410. c = 0;
  14411. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14412. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14413. {
  14414. sstr[c] = loc[strlen("key")+3+c];
  14415. c++;
  14416. }
  14417. sstr[c] = '\0';
  14418. strcpy(keystr,sstr);
  14419. }
  14420. //*************************readonly*********************************/
  14421. if(strstr(str, "readonly") != NULL)
  14422. {
  14423. loc = strstr(str, "readonly");
  14424. c = 0;
  14425. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14426. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  14427. {
  14428. sstr[c] = loc[strlen("readonly")+2+c];
  14429. c++;
  14430. }
  14431. sstr[c] = '\0';
  14432. strcpy(readonlystr,sstr);
  14433. }
  14434. //*************************value*********************************/
  14435. if(strstr(str, "value") != NULL)
  14436. {
  14437. loc = strstr(str, "value");
  14438. c = 0;
  14439. memset(sstr ,0, ARRAY_SIZE(sstr) );
  14440. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  14441. {
  14442. sstr[c] = loc[strlen("value")+3+c];
  14443. c++;
  14444. }
  14445. sstr[c] = '\0';
  14446. strcpy(valuestr,sstr);
  14447. }
  14448. // DEBUG_INFO("keystr=%s\n",keystr);
  14449. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  14450. // DEBUG_INFO("valuestr=%s\n",valuestr);
  14451. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  14452. {
  14453. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14454. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14455. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  14456. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14457. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  14458. }
  14459. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  14460. {
  14461. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14462. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14463. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  14464. }
  14465. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  14466. {
  14467. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14468. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  14469. }
  14470. if(strcmp(keystr, "BlinkRepeat") == 0)
  14471. {
  14472. //Charger.BlinkRepeat = Integer.parseInt(value);
  14473. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14474. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  14475. }
  14476. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  14477. {
  14478. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14479. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  14480. }
  14481. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  14482. {
  14483. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14484. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  14485. }
  14486. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  14487. {
  14488. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14489. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  14490. }
  14491. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14492. {
  14493. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14494. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14495. HeartBeatWaitTime = atoi(valuestr);
  14496. }
  14497. if(strcmp(keystr, "LightIntensity") == 0)
  14498. {
  14499. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14500. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14501. }
  14502. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14503. {
  14504. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14505. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14506. }
  14507. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14508. {
  14509. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14510. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14511. }
  14512. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14513. {
  14514. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14515. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14516. }
  14517. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14518. {
  14519. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14520. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14521. }
  14522. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14523. {
  14524. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14525. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14526. }
  14527. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14528. {
  14529. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14530. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14531. }
  14532. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14533. {
  14534. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14535. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14536. }
  14537. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14538. {
  14539. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14540. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14541. }
  14542. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14543. {
  14544. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14545. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14546. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14547. }
  14548. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14549. {
  14550. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14551. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14552. }
  14553. if(strcmp(keystr, "ResetRetries") == 0)
  14554. {
  14555. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14556. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14557. }
  14558. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14559. {
  14560. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14561. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14562. }
  14563. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14564. {
  14565. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14566. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14567. }
  14568. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14569. {
  14570. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14571. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14572. }
  14573. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14574. {
  14575. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14576. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14577. }
  14578. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14579. {
  14580. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14581. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14582. }
  14583. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14584. {
  14585. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14586. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14587. }
  14588. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14589. {
  14590. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14591. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14592. }
  14593. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14594. {
  14595. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14596. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14597. }
  14598. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14599. {
  14600. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14601. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14602. }
  14603. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14604. {
  14605. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14606. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14607. }
  14608. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14609. {
  14610. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14611. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14612. TransactionMessageAttemptsValue = atoi(valuestr);
  14613. }
  14614. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14615. {
  14616. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14617. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14618. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14619. }
  14620. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14621. {
  14622. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14623. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14624. }
  14625. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14626. {
  14627. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14628. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14629. }
  14630. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14631. {
  14632. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14633. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14634. }
  14635. if(strcmp(keystr, "AuthorizationKey") == 0)
  14636. {
  14637. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14638. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14639. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword);
  14640. }
  14641. if(strcmp(keystr, "SecurityProfile") == 0)
  14642. {
  14643. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14644. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  14645. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  14646. }
  14647. if(strcmp(keystr, "DefaultPrice") == 0)
  14648. {
  14649. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14650. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14651. }
  14652. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14653. {
  14654. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14655. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14656. }
  14657. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14658. {
  14659. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14660. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14661. }
  14662. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14663. {
  14664. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14665. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  14666. }
  14667. if(strcmp(keystr, "FreeVend") == 0)
  14668. {
  14669. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14670. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14671. }
  14672. if(strcmp(keystr, "FreeVendIdtag") == 0)
  14673. {
  14674. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14675. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  14676. }
  14677. if(strcmp(keystr, "OcppServer") == 0)
  14678. {
  14679. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14680. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14681. }
  14682. if(strcmp(keystr, "MaintainServer") == 0)
  14683. {
  14684. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14685. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14686. }
  14687. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14688. {
  14689. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14690. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14691. }
  14692. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14693. {
  14694. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14695. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14696. }
  14697. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  14698. {
  14699. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14700. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  14701. }
  14702. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  14703. {
  14704. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14705. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  14706. }
  14707. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  14708. {
  14709. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14710. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  14711. }
  14712. if(strcmp(keystr, "OffLineMaxChargingPower") == 0)
  14713. {
  14714. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14715. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", valuestr);
  14716. }
  14717. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14718. {
  14719. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14720. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14721. }
  14722. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14723. {
  14724. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14725. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14726. }
  14727. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14728. {
  14729. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14730. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14731. }
  14732. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14733. {
  14734. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14735. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14736. }
  14737. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14738. {
  14739. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14740. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14741. }
  14742. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14743. {
  14744. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14745. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14746. }
  14747. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14748. {
  14749. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14750. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14751. }
  14752. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14753. {
  14754. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14755. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14756. }
  14757. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14758. {
  14759. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14760. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14761. }
  14762. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14763. {
  14764. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14765. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14766. }
  14767. }
  14768. }
  14769. fclose(fp);
  14770. }
  14771. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14772. {
  14773. return PASS;
  14774. }
  14775. else
  14776. {
  14777. return FAIL;
  14778. }
  14779. }
  14780. void StoreConfigurationTable(void)
  14781. {
  14782. FILE *outfile;
  14783. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  14784. if(outfile == NULL)
  14785. {
  14786. DEBUG_INFO("Error opening file");
  14787. return ;
  14788. }
  14789. /*Core Profile*/
  14790. //AllowOfflineTxForUnknownId
  14791. /*
  14792. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14793. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14794. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14795. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14796. */
  14797. //DEBUG_INFO("data=%s\n",data);
  14798. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14799. //AuthorizationCacheEnabled
  14800. /*
  14801. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14802. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14803. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14804. */
  14805. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14806. //AuthorizeRemoteTxRequests
  14807. /*
  14808. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14809. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14810. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14811. */
  14812. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14813. //BlinkRepeat
  14814. /*
  14815. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14816. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14817. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14818. */
  14819. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14820. //ClockAlignedDataInterval
  14821. /*
  14822. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14823. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14824. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14825. */
  14826. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14827. //ConnectionTimeOut
  14828. /*
  14829. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14830. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14831. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14832. */
  14833. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14834. //GetConfigurationMaxKeys
  14835. /*
  14836. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14837. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14838. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14839. */
  14840. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14841. // HeartbeatInterval
  14842. /*
  14843. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14844. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14845. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14846. */
  14847. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14848. // LightIntensity
  14849. /*
  14850. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14851. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14852. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14853. */
  14854. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14855. // LocalAuthorizeOffline
  14856. /*
  14857. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14858. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14859. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14860. */
  14861. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14862. // LocalPreAuthorize
  14863. /*
  14864. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14865. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14866. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14867. */
  14868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14869. // MaxEnergyOnInvalidId
  14870. /*
  14871. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14872. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14873. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14874. */
  14875. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14876. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14877. // MeterValuesAlignedData
  14878. /*
  14879. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14880. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14881. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14882. */
  14883. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14884. // MeterValuesAlignedDataMaxLength
  14885. /*
  14886. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14887. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14888. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14889. */
  14890. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14891. // MeterValuesSampledData
  14892. /*
  14893. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14894. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14895. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14896. */
  14897. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14898. // MeterValuesSampledDataMaxLength
  14899. /*
  14900. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14901. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14902. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14903. */
  14904. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14905. // MeterValueSampleInterval
  14906. /*
  14907. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14908. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14909. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14910. */
  14911. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14912. // MinimumStatusDuration
  14913. /*
  14914. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14915. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14916. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14917. */
  14918. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14919. // NumberOfConnectors
  14920. /*
  14921. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14922. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14923. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14924. {
  14925. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14926. }
  14927. else
  14928. {
  14929. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14930. }
  14931. */
  14932. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14933. // ResetRetries
  14934. /*
  14935. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14936. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14937. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14938. */
  14939. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14940. // ConnectorPhaseRotation
  14941. /*
  14942. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14943. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14944. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14945. */
  14946. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14947. // ConnectorPhaseRotationMaxLength
  14948. /*
  14949. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14950. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14951. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14952. */
  14953. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14954. // StopTransactionOnEVSideDisconnect
  14955. /*
  14956. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14957. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14958. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14959. */
  14960. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14961. // StopTransactionOnInvalidId
  14962. /*
  14963. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14964. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14965. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14966. */
  14967. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14968. // StopTxnAlignedData
  14969. /*
  14970. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14971. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14972. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14973. */
  14974. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14975. // StopTxnAlignedDataMaxLength
  14976. /*
  14977. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14978. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14979. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14980. */
  14981. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14982. // StopTxnSampledData
  14983. /*
  14984. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14985. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14986. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14987. */
  14988. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14989. // StopTxnSampledDataMaxLength
  14990. /*
  14991. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14992. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14993. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14994. */
  14995. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14996. // SupportedFeatureProfiles
  14997. /*
  14998. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14999. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  15000. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  15001. */
  15002. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  15003. // SupportedFeatureProfilesMaxLength
  15004. /*
  15005. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  15006. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  15007. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  15008. */
  15009. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  15010. // TransactionMessageAttempts
  15011. /*
  15012. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  15013. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  15014. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  15015. */
  15016. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15017. // TransactionMessageRetryInterval
  15018. /*
  15019. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  15020. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  15021. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  15022. */
  15023. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15024. // UnlockConnectorOnEVSideDisconnect
  15025. /*
  15026. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  15027. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  15028. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  15029. */
  15030. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15031. // WebSocketPingInterval
  15032. /*
  15033. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15034. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15035. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15036. */
  15037. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15038. // QueueOffLineMeterValues
  15039. /*
  15040. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  15041. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15042. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  15043. */
  15044. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15045. // AuthorizationKey
  15046. /*
  15047. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15048. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15049. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  15050. */
  15051. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15052. // SecurityProfile
  15053. /*
  15054. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15055. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15056. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  15057. */
  15058. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15059. // DefaultPrice
  15060. /*
  15061. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15062. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15063. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15064. */
  15065. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15066. // CustomDisplayCostAndPrice
  15067. /*
  15068. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15069. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15070. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15071. */
  15072. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15073. // CustomIdleFeeAfterStop
  15074. /*
  15075. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15076. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15077. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15078. */
  15079. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15080. // SystemUptimeSec
  15081. /*
  15082. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15083. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15084. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15085. */
  15086. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15087. // FreeVend
  15088. /*
  15089. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15090. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15091. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  15092. */
  15093. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15094. // FreeVendIdtag
  15095. /*
  15096. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15097. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15098. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15099. */
  15100. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15101. // OcppServer
  15102. /*
  15103. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15104. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15105. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  15106. */
  15107. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15108. // MaintainServer
  15109. /*
  15110. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15111. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15112. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  15113. */
  15114. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15115. // StatusNotificationPeriodically
  15116. /*
  15117. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  15118. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15119. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15120. */
  15121. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15122. // StatusNotificationInterval
  15123. /*
  15124. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15125. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15126. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15127. */
  15128. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15129. // isEnableLocalPowerSharing
  15130. /*
  15131. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  15132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  15133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  15134. */
  15135. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  15136. // PowerSharingServerIP
  15137. /*
  15138. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  15139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  15140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  15141. */
  15142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  15143. // EVCCID_PREFIX
  15144. /*
  15145. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  15146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  15147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  15148. */
  15149. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  15150. // OffLineMaxChargingPower
  15151. /*
  15152. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  15153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  15154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "" );
  15155. */
  15156. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  15157. // ConfigurationVersion
  15158. /*
  15159. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  15160. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15161. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  15162. */
  15163. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15164. //* Local Auth List Management Profile*/
  15165. //LocalAuthListEnabled
  15166. /*
  15167. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15168. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15169. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15170. */
  15171. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15172. //LocalAuthListMaxLength
  15173. /*
  15174. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15175. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15176. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  15177. */
  15178. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15179. //SendLocalListMaxLength
  15180. /*
  15181. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15182. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15183. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  15184. */
  15185. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15186. //ReserveConnectorZeroSupported
  15187. /*
  15188. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15189. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15190. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15191. */
  15192. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15193. //* Smart Charging Profile */
  15194. //ChargeProfileMaxStackLevel
  15195. /*
  15196. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  15197. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  15198. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  15199. */
  15200. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15201. // ChargingScheduleAllowedChargingRateUnit
  15202. /*
  15203. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  15204. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  15205. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  15206. */
  15207. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15208. // ChargingScheduleMaxPeriods
  15209. /*
  15210. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  15211. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  15212. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  15213. */
  15214. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15215. // ConnectorSwitch3to1PhaseSupported
  15216. /*
  15217. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  15218. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  15219. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  15220. */
  15221. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15222. // MaxChargingProfilesInstalled
  15223. /*
  15224. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  15225. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  15226. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  15227. */
  15228. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15229. fclose(outfile);
  15230. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15231. }
  15232. void getKeyValue(char *keyReq)
  15233. {
  15234. int isEmpty = FALSE;
  15235. int isKnowKey = FALSE;
  15236. DEBUG_INFO("keyReq = %s\n", keyReq);
  15237. if((keyReq == NULL) || (strlen(keyReq) == 0))
  15238. isEmpty = TRUE;
  15239. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  15240. {
  15241. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  15242. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  15243. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15244. {
  15245. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  15246. }
  15247. else
  15248. {
  15249. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  15250. }
  15251. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  15252. isKnowKey = TRUE;
  15253. }
  15254. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  15255. {
  15256. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  15257. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  15258. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15259. {
  15260. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  15261. }
  15262. else
  15263. {
  15264. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  15265. }
  15266. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  15267. isKnowKey = TRUE;
  15268. }
  15269. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  15270. {
  15271. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  15272. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  15273. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15274. {
  15275. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  15276. }
  15277. else
  15278. {
  15279. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  15280. }
  15281. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  15282. isKnowKey = TRUE;
  15283. }
  15284. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  15285. {
  15286. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  15287. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  15288. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15289. {
  15290. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  15291. }
  15292. else
  15293. {
  15294. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  15295. }
  15296. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  15297. isKnowKey = TRUE;
  15298. }
  15299. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  15300. {
  15301. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  15302. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  15303. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15304. {
  15305. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  15306. }
  15307. else
  15308. {
  15309. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  15310. }
  15311. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  15312. isKnowKey = TRUE;
  15313. }
  15314. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  15315. {
  15316. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  15317. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  15318. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15319. {
  15320. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  15321. }
  15322. else
  15323. {
  15324. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  15325. }
  15326. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  15327. isKnowKey = TRUE;
  15328. }
  15329. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  15330. {
  15331. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  15332. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  15333. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15334. {
  15335. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  15336. }
  15337. else
  15338. {
  15339. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  15340. }
  15341. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  15342. isKnowKey = TRUE;
  15343. }
  15344. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  15345. {
  15346. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  15347. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  15348. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15349. {
  15350. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  15351. }
  15352. else
  15353. {
  15354. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  15355. }
  15356. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  15357. isKnowKey = TRUE;
  15358. }
  15359. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  15360. {
  15361. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  15362. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  15363. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15364. {
  15365. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  15366. }
  15367. else
  15368. {
  15369. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  15370. }
  15371. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  15372. isKnowKey = TRUE;
  15373. }
  15374. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  15375. {
  15376. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  15377. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  15378. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15379. {
  15380. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  15381. }
  15382. else
  15383. {
  15384. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  15385. }
  15386. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  15387. isKnowKey = TRUE;
  15388. }
  15389. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  15390. {
  15391. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  15392. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  15393. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15394. {
  15395. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  15396. }
  15397. else
  15398. {
  15399. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  15400. }
  15401. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  15402. isKnowKey = TRUE;
  15403. }
  15404. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  15405. {
  15406. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  15407. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  15408. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15409. {
  15410. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15411. }
  15412. else
  15413. {
  15414. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15415. }
  15416. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  15417. isKnowKey = TRUE;
  15418. }
  15419. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  15420. {
  15421. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  15422. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  15423. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15424. {
  15425. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15426. }
  15427. else
  15428. {
  15429. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15430. }
  15431. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  15432. isKnowKey = TRUE;
  15433. }
  15434. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  15435. {
  15436. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  15437. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  15438. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15439. {
  15440. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15441. }
  15442. else
  15443. {
  15444. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15445. }
  15446. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  15447. isKnowKey = TRUE;
  15448. }
  15449. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  15450. {
  15451. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  15452. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  15453. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15454. {
  15455. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  15456. }
  15457. else
  15458. {
  15459. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  15460. }
  15461. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  15462. isKnowKey = TRUE;
  15463. }
  15464. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  15465. {
  15466. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  15467. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  15468. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15469. {
  15470. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15471. }
  15472. else
  15473. {
  15474. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15475. }
  15476. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  15477. isKnowKey = TRUE;
  15478. }
  15479. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  15480. {
  15481. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  15482. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  15483. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15484. {
  15485. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  15486. }
  15487. else
  15488. {
  15489. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  15490. }
  15491. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  15492. isKnowKey = TRUE;
  15493. }
  15494. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  15495. {
  15496. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  15497. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  15498. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15499. {
  15500. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  15501. }
  15502. else
  15503. {
  15504. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  15505. }
  15506. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  15507. isKnowKey = TRUE;
  15508. }
  15509. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  15510. {
  15511. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  15512. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  15513. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15514. {
  15515. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  15516. }
  15517. else
  15518. {
  15519. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  15520. }
  15521. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  15522. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  15523. isKnowKey = TRUE;
  15524. }
  15525. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  15526. {
  15527. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  15528. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  15529. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15530. {
  15531. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  15532. }
  15533. else
  15534. {
  15535. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  15536. }
  15537. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  15538. isKnowKey = TRUE;
  15539. }
  15540. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15541. {
  15542. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15543. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15544. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15545. {
  15546. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15547. }
  15548. else
  15549. {
  15550. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15551. }
  15552. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15553. isKnowKey = TRUE;
  15554. }
  15555. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15556. {
  15557. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15558. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15559. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15560. {
  15561. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15562. }
  15563. else
  15564. {
  15565. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15566. }
  15567. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15568. isKnowKey = TRUE;
  15569. }
  15570. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15571. {
  15572. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15573. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15574. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15575. {
  15576. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15577. }
  15578. else
  15579. {
  15580. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15581. }
  15582. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15583. isKnowKey = TRUE;
  15584. }
  15585. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15586. {
  15587. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15588. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15589. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15590. {
  15591. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15592. }
  15593. else
  15594. {
  15595. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15596. }
  15597. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15598. isKnowKey = TRUE;
  15599. }
  15600. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15601. {
  15602. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15603. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15604. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15605. {
  15606. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15607. }
  15608. else
  15609. {
  15610. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15611. }
  15612. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15613. isKnowKey = TRUE;
  15614. }
  15615. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15616. {
  15617. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15618. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15619. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15620. {
  15621. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15622. }
  15623. else
  15624. {
  15625. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15626. }
  15627. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15628. isKnowKey = TRUE;
  15629. }
  15630. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15631. {
  15632. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15633. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15634. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15635. {
  15636. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15637. }
  15638. else
  15639. {
  15640. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15641. }
  15642. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15643. isKnowKey = TRUE;
  15644. }
  15645. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15646. {
  15647. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15648. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15649. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15650. {
  15651. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15652. }
  15653. else
  15654. {
  15655. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15656. }
  15657. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15658. isKnowKey = TRUE;
  15659. }
  15660. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15661. {
  15662. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15663. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15664. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15665. {
  15666. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15667. }
  15668. else
  15669. {
  15670. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15671. }
  15672. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15673. isKnowKey = TRUE;
  15674. }
  15675. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15676. {
  15677. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15678. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15679. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15680. {
  15681. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15682. }
  15683. else
  15684. {
  15685. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15686. }
  15687. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15688. isKnowKey = TRUE;
  15689. }
  15690. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15691. {
  15692. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15693. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15694. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15695. {
  15696. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15697. }
  15698. else
  15699. {
  15700. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15701. }
  15702. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15703. isKnowKey = TRUE;
  15704. }
  15705. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15706. {
  15707. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15708. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15709. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15710. {
  15711. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15712. }
  15713. else
  15714. {
  15715. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15716. }
  15717. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15718. isKnowKey = TRUE;
  15719. }
  15720. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15721. {
  15722. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15723. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15724. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15725. {
  15726. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15727. }
  15728. else
  15729. {
  15730. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15731. }
  15732. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15733. isKnowKey = TRUE;
  15734. }
  15735. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15736. {
  15737. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15738. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15739. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15740. {
  15741. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15742. }
  15743. else
  15744. {
  15745. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15746. }
  15747. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15748. isKnowKey = TRUE;
  15749. }
  15750. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15751. {
  15752. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15753. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15754. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15755. {
  15756. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15757. }
  15758. else
  15759. {
  15760. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15761. }
  15762. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15763. isKnowKey = TRUE;
  15764. }
  15765. /*
  15766. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15767. {
  15768. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15769. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15770. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15771. {
  15772. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15773. }
  15774. else
  15775. {
  15776. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15777. }
  15778. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15779. isKnowKey = TRUE;
  15780. }*/
  15781. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15782. {
  15783. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15784. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15785. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15786. {
  15787. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15788. }
  15789. else
  15790. {
  15791. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15792. }
  15793. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15794. isKnowKey = TRUE;
  15795. }
  15796. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15797. {
  15798. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15799. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15800. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15801. {
  15802. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15803. }
  15804. else
  15805. {
  15806. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15807. }
  15808. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15809. isKnowKey = TRUE;
  15810. }
  15811. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15812. {
  15813. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15814. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15815. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15816. {
  15817. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15818. }
  15819. else
  15820. {
  15821. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15822. }
  15823. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15824. isKnowKey = TRUE;
  15825. }
  15826. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15827. {
  15828. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15829. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15830. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15831. {
  15832. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15833. }
  15834. else
  15835. {
  15836. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15837. }
  15838. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15839. isKnowKey = TRUE;
  15840. }
  15841. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15842. {
  15843. struct sysinfo s_info;
  15844. int error = sysinfo(&s_info);
  15845. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15846. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15847. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15848. {
  15849. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15850. }
  15851. else
  15852. {
  15853. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15854. }
  15855. if(error != 0)
  15856. {
  15857. DEBUG_WARN("System uptime get error: %d\n", error);
  15858. }
  15859. else
  15860. {
  15861. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15862. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15863. }
  15864. isKnowKey = TRUE;
  15865. }
  15866. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15867. {
  15868. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15869. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15870. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15871. {
  15872. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15873. }
  15874. else
  15875. {
  15876. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15877. }
  15878. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15879. isKnowKey = TRUE;
  15880. }
  15881. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  15882. {
  15883. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  15884. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  15885. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  15886. {
  15887. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  15888. }
  15889. else
  15890. {
  15891. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  15892. }
  15893. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15894. isKnowKey = TRUE;
  15895. }
  15896. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15897. {
  15898. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15899. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15900. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15901. {
  15902. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15903. }
  15904. else
  15905. {
  15906. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15907. }
  15908. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15909. isKnowKey = TRUE;
  15910. }
  15911. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15912. {
  15913. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15914. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15915. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15916. {
  15917. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15918. }
  15919. else
  15920. {
  15921. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15922. }
  15923. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15924. isKnowKey = TRUE;
  15925. }
  15926. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15927. {
  15928. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15929. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15930. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15931. {
  15932. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15933. }
  15934. else
  15935. {
  15936. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15937. }
  15938. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15939. isKnowKey = TRUE;
  15940. }
  15941. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15942. {
  15943. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15944. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15945. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15946. {
  15947. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15948. }
  15949. else
  15950. {
  15951. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15952. }
  15953. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15954. isKnowKey = TRUE;
  15955. }
  15956. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  15957. {
  15958. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  15959. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  15960. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  15961. {
  15962. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  15963. }
  15964. else
  15965. {
  15966. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  15967. }
  15968. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  15969. isKnowKey = TRUE;
  15970. }
  15971. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  15972. {
  15973. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  15974. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  15975. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  15976. {
  15977. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  15978. }
  15979. else
  15980. {
  15981. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  15982. }
  15983. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  15984. isKnowKey = TRUE;
  15985. }
  15986. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  15987. {
  15988. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  15989. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  15990. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  15991. {
  15992. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  15993. }
  15994. else
  15995. {
  15996. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  15997. }
  15998. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  15999. isKnowKey = TRUE;
  16000. }
  16001. if(isEmpty || strcmp(keyReq, "OffLineMaxChargingPower") == 0 )
  16002. {
  16003. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OffLineMaxChargingPower].Item, "OffLineMaxChargingPower");
  16004. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Key, "OffLineMaxChargingPower");
  16005. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  16006. {
  16007. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "0"/*"FALSE"*/);
  16008. }
  16009. else
  16010. {
  16011. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "1"/*"TRUE"*/);
  16012. }
  16013. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData );
  16014. isKnowKey = TRUE;
  16015. }
  16016. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  16017. {
  16018. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  16019. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  16020. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  16021. {
  16022. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  16023. }
  16024. else
  16025. {
  16026. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  16027. }
  16028. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  16029. isKnowKey = TRUE;
  16030. }
  16031. #if 1
  16032. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  16033. {
  16034. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  16035. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  16036. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16037. {
  16038. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  16039. }
  16040. else
  16041. {
  16042. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  16043. }
  16044. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  16045. isKnowKey = TRUE;
  16046. }
  16047. #endif
  16048. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  16049. {
  16050. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  16051. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  16052. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16053. {
  16054. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16055. }
  16056. else
  16057. {
  16058. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16059. }
  16060. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  16061. isKnowKey = TRUE;
  16062. }
  16063. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  16064. {
  16065. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  16066. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  16067. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16068. {
  16069. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  16070. }
  16071. else
  16072. {
  16073. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  16074. }
  16075. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  16076. isKnowKey = TRUE;
  16077. }
  16078. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  16079. {
  16080. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  16081. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  16082. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16083. {
  16084. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  16085. }
  16086. else
  16087. {
  16088. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  16089. }
  16090. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16091. isKnowKey = TRUE;
  16092. }
  16093. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  16094. {
  16095. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  16096. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  16097. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16098. {
  16099. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  16100. }
  16101. else
  16102. {
  16103. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  16104. }
  16105. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16106. isKnowKey = TRUE;
  16107. }
  16108. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  16109. {
  16110. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  16111. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  16112. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16113. {
  16114. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  16115. }
  16116. else
  16117. {
  16118. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  16119. }
  16120. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16121. isKnowKey = TRUE;
  16122. }
  16123. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  16124. {
  16125. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  16126. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  16127. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16128. {
  16129. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  16130. }
  16131. else
  16132. {
  16133. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  16134. }
  16135. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16136. isKnowKey = TRUE;
  16137. }
  16138. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  16139. {
  16140. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  16141. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  16142. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16143. {
  16144. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  16145. }
  16146. else
  16147. {
  16148. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  16149. }
  16150. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16151. isKnowKey = TRUE;
  16152. }
  16153. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  16154. {
  16155. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  16156. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  16157. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16158. {
  16159. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  16160. }
  16161. else
  16162. {
  16163. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  16164. }
  16165. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16166. isKnowKey = TRUE;
  16167. }
  16168. //=========================================================
  16169. if(!isEmpty && !isKnowKey)
  16170. {
  16171. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  16172. strcpy(unknownkey[UnknownKeynum], keyReq);
  16173. UnknownKeynum = UnknownKeynum + 1;
  16174. }
  16175. }
  16176. void processUnkownKey(void)
  16177. {
  16178. DEBUG_INFO("processUnkownKey...\n");
  16179. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  16180. for(int index=0; index < UnknownKeynum; index++)
  16181. {
  16182. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  16183. {
  16184. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  16185. }
  16186. }
  16187. }
  16188. int setKeyValue(char *key, char *value)
  16189. {
  16190. int isSuccess = NotSupported;
  16191. int check_ascii=0;
  16192. char str[501]={0};
  16193. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  16194. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  16195. {
  16196. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  16197. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16198. {
  16199. strcpy(str, (const char*)value);
  16200. for(int i = 0; str[i]; i++){
  16201. str[i] = tolower(str[i]);
  16202. }
  16203. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16204. isSuccess = ConfigurationStatus_Accepted;
  16205. }
  16206. else
  16207. {
  16208. isSuccess = ConfigurationStatus_Rejected;
  16209. }
  16210. }
  16211. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  16212. {
  16213. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  16214. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16215. {
  16216. strcpy(str, (const char*)value);
  16217. for(int i = 0; str[i]; i++){
  16218. str[i] = tolower(str[i]);
  16219. }
  16220. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16221. isSuccess = ConfigurationStatus_Accepted;
  16222. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  16223. }
  16224. else
  16225. {
  16226. isSuccess = ConfigurationStatus_Rejected;
  16227. }
  16228. }
  16229. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  16230. {
  16231. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16232. {
  16233. strcpy(str, (const char*)value);
  16234. for(int i = 0; str[i]; i++)
  16235. {
  16236. str[i] = tolower(str[i]);
  16237. }
  16238. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  16239. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16240. isSuccess = ConfigurationStatus_Accepted;
  16241. }
  16242. else
  16243. {
  16244. isSuccess = ConfigurationStatus_Rejected;
  16245. }
  16246. }
  16247. if(strcmp(key, "BlinkRepeat") == 0)
  16248. {
  16249. //Charger.BlinkRepeat = Integer.parseInt(value);
  16250. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16251. {
  16252. check_ascii = value[0];
  16253. if( (check_ascii < 48) || (check_ascii > 57) )
  16254. {
  16255. isSuccess = ConfigurationStatus_Rejected;
  16256. }
  16257. else
  16258. {
  16259. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  16260. isSuccess = ConfigurationStatus_Accepted;
  16261. }
  16262. }
  16263. else
  16264. {
  16265. isSuccess = ConfigurationStatus_Rejected;
  16266. }
  16267. }
  16268. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  16269. {
  16270. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16271. {
  16272. check_ascii = value[0];
  16273. if( (check_ascii < 48) || (check_ascii > 57) )
  16274. {
  16275. isSuccess = ConfigurationStatus_Rejected;
  16276. }
  16277. else
  16278. {
  16279. if((atoi(value) == 0) || (atoi(value) >= 5))
  16280. {
  16281. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  16282. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  16283. isSuccess = ConfigurationStatus_Accepted;
  16284. }
  16285. else
  16286. isSuccess = ConfigurationStatus_Rejected;
  16287. }
  16288. }
  16289. else
  16290. {
  16291. isSuccess = ConfigurationStatus_Rejected;
  16292. }
  16293. }
  16294. if(strcmp(key, "ConnectionTimeOut") == 0 )
  16295. {
  16296. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  16297. {
  16298. check_ascii = value[0];
  16299. if( (check_ascii < 48) || (check_ascii > 57) )
  16300. {
  16301. isSuccess = ConfigurationStatus_Rejected;
  16302. }
  16303. else
  16304. {
  16305. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  16306. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  16307. isSuccess = ConfigurationStatus_Accepted;
  16308. }
  16309. }
  16310. else
  16311. {
  16312. isSuccess = ConfigurationStatus_Rejected;
  16313. }
  16314. }
  16315. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  16316. {
  16317. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  16318. {
  16319. check_ascii = value[0];
  16320. if( (check_ascii < 48) || (check_ascii > 57) )
  16321. {
  16322. isSuccess = ConfigurationStatus_Rejected;
  16323. }
  16324. else
  16325. {
  16326. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16327. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  16328. isSuccess = ConfigurationStatus_Accepted;
  16329. }
  16330. }
  16331. else
  16332. {
  16333. isSuccess = ConfigurationStatus_Rejected;
  16334. }
  16335. }
  16336. if(strcmp(key, "HeartbeatInterval") == 0)
  16337. {
  16338. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  16339. {
  16340. check_ascii = value[0];
  16341. if( (check_ascii < 48) || (check_ascii > 57) )
  16342. {
  16343. isSuccess = ConfigurationStatus_Rejected;
  16344. }
  16345. else
  16346. {
  16347. if((atoi(value) == 0) || (atoi(value) >= 10))
  16348. {
  16349. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  16350. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  16351. HeartBeatWaitTime = atoi(value);
  16352. isSuccess = ConfigurationStatus_Accepted;
  16353. }
  16354. else
  16355. {
  16356. isSuccess = ConfigurationStatus_Rejected;
  16357. }
  16358. }
  16359. }
  16360. else
  16361. {
  16362. isSuccess = ConfigurationStatus_Rejected;
  16363. }
  16364. }
  16365. if(strcmp(key, "LightIntensity") == 0)
  16366. {
  16367. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16368. {
  16369. check_ascii = value[0];
  16370. if( (check_ascii < 48) || (check_ascii > 57) )
  16371. {
  16372. isSuccess = ConfigurationStatus_Rejected;
  16373. }
  16374. else
  16375. {
  16376. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  16377. isSuccess = ConfigurationStatus_Accepted;
  16378. }
  16379. }
  16380. else
  16381. {
  16382. isSuccess = ConfigurationStatus_Rejected;
  16383. }
  16384. }
  16385. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  16386. {
  16387. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  16388. {
  16389. strcpy(str, (const char*)value);
  16390. for(int i = 0; str[i]; i++)
  16391. {
  16392. str[i] = tolower(str[i]);
  16393. }
  16394. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16395. isSuccess = ConfigurationStatus_Accepted;
  16396. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16397. }
  16398. else
  16399. {
  16400. isSuccess = ConfigurationStatus_Rejected;
  16401. }
  16402. }
  16403. if(strcmp(key, "LocalPreAuthorize") == 0)
  16404. {
  16405. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16406. {
  16407. strcpy(str, (const char*)value);
  16408. for(int i = 0; str[i]; i++)
  16409. {
  16410. str[i] = tolower(str[i]);
  16411. }
  16412. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16413. isSuccess = ConfigurationStatus_Accepted;
  16414. }
  16415. else
  16416. {
  16417. isSuccess = ConfigurationStatus_Rejected;
  16418. }
  16419. }
  16420. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  16421. {
  16422. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  16423. {
  16424. check_ascii = value[0];
  16425. if( (check_ascii < 48) || (check_ascii > 57) )
  16426. {
  16427. isSuccess = ConfigurationStatus_Rejected;
  16428. }
  16429. else
  16430. {
  16431. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  16432. isSuccess = ConfigurationStatus_Accepted;
  16433. }
  16434. }
  16435. else
  16436. {
  16437. isSuccess = ConfigurationStatus_Rejected;
  16438. }
  16439. }
  16440. if(strcmp(key, "MeterValuesAlignedData") == 0)
  16441. {
  16442. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  16443. {
  16444. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  16445. isSuccess = ConfigurationStatus_Accepted;
  16446. }
  16447. else
  16448. {
  16449. isSuccess = ConfigurationStatus_Rejected;
  16450. }
  16451. }
  16452. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  16453. {
  16454. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  16455. {
  16456. check_ascii = value[0];
  16457. if( (check_ascii < 48) || (check_ascii > 57) )
  16458. {
  16459. isSuccess = ConfigurationStatus_Rejected;
  16460. }
  16461. else
  16462. {
  16463. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16464. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  16465. isSuccess = ConfigurationStatus_Accepted;
  16466. }
  16467. }
  16468. else
  16469. {
  16470. isSuccess = ConfigurationStatus_Rejected;
  16471. }
  16472. }
  16473. if(strcmp(key, "MeterValuesSampledData") == 0 )
  16474. {
  16475. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  16476. {
  16477. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  16478. isSuccess = ConfigurationStatus_Accepted;
  16479. }
  16480. else
  16481. {
  16482. isSuccess = ConfigurationStatus_Rejected;
  16483. }
  16484. }
  16485. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  16486. {
  16487. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  16488. {
  16489. check_ascii = value[0];
  16490. if( (check_ascii < 48) || (check_ascii > 57) )
  16491. {
  16492. isSuccess = ConfigurationStatus_Rejected;
  16493. }
  16494. else
  16495. {
  16496. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16497. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  16498. isSuccess = ConfigurationStatus_Accepted;
  16499. }
  16500. }
  16501. else
  16502. {
  16503. isSuccess = ConfigurationStatus_Rejected;
  16504. }
  16505. }
  16506. if(strcmp(key, "MeterValueSampleInterval") == 0)
  16507. {
  16508. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  16509. {
  16510. check_ascii = value[0];
  16511. if( (check_ascii < 48) || (check_ascii > 57) )
  16512. {
  16513. isSuccess = ConfigurationStatus_Rejected;
  16514. }
  16515. else
  16516. {
  16517. if((atoi(value) == 0) || (atoi(value) >= 3))
  16518. {
  16519. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  16520. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  16521. isSuccess = ConfigurationStatus_Accepted;
  16522. }
  16523. else
  16524. {
  16525. isSuccess = ConfigurationStatus_Rejected;
  16526. }
  16527. }
  16528. }
  16529. else
  16530. {
  16531. isSuccess = ConfigurationStatus_Rejected;
  16532. }
  16533. }
  16534. if(strcmp(key, "MinimumStatusDuration") == 0)
  16535. {
  16536. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  16537. {
  16538. check_ascii = value[0];
  16539. if( (check_ascii < 48) || (check_ascii > 57) )
  16540. {
  16541. isSuccess = ConfigurationStatus_Rejected;
  16542. }
  16543. else
  16544. {
  16545. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  16546. {
  16547. isSuccess = ConfigurationStatus_Rejected;
  16548. }
  16549. else
  16550. {
  16551. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  16552. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  16553. server_cycle_Status = atoi(value); //StatusNotification Cycle
  16554. isSuccess = ConfigurationStatus_Accepted;
  16555. }
  16556. }
  16557. }
  16558. else
  16559. {
  16560. isSuccess = ConfigurationStatus_Rejected;
  16561. }
  16562. }
  16563. if(strcmp(key, "NumberOfConnectors") == 0)
  16564. {
  16565. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  16566. {
  16567. check_ascii = value[0];
  16568. if( (check_ascii < 48) || (check_ascii > 57) )
  16569. {
  16570. isSuccess = ConfigurationStatus_Rejected;
  16571. }
  16572. else
  16573. {
  16574. //Charger.ResetRetries = Integer.parseInt(value);
  16575. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  16576. isSuccess = ConfigurationStatus_Accepted;
  16577. }
  16578. }
  16579. else
  16580. {
  16581. isSuccess = ConfigurationStatus_Rejected;
  16582. }
  16583. }
  16584. if(strcmp(key, "ResetRetries") == 0)
  16585. {
  16586. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  16587. {
  16588. check_ascii = value[0];
  16589. if( (check_ascii < 48) || (check_ascii > 57) )
  16590. {
  16591. isSuccess = ConfigurationStatus_Rejected;
  16592. }
  16593. else
  16594. {
  16595. //Charger.ResetRetries = Integer.parseInt(value);
  16596. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  16597. isSuccess = ConfigurationStatus_Accepted;
  16598. }
  16599. }
  16600. else
  16601. {
  16602. isSuccess = ConfigurationStatus_Rejected;
  16603. }
  16604. }
  16605. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16606. {
  16607. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16608. {
  16609. strcpy(str, (const char*)value);
  16610. for(int i = 0; str[i]; i++)
  16611. {
  16612. str[i] = tolower(str[i]);
  16613. }
  16614. if(strcmp(str, "notapplicable")== 0)
  16615. {
  16616. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16617. isSuccess = ConfigurationStatus_Accepted;
  16618. }
  16619. else if(strcmp(str, "unknown")== 0)
  16620. {
  16621. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16622. isSuccess = ConfigurationStatus_Accepted;
  16623. }
  16624. else if(strcmp(str, "rst")== 0)
  16625. {
  16626. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16627. isSuccess = ConfigurationStatus_Accepted;
  16628. }
  16629. else if(strcmp(str, "rts")== 0)
  16630. {
  16631. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16632. isSuccess = ConfigurationStatus_Accepted;
  16633. }
  16634. else if(strcmp(str, "srt")== 0)
  16635. {
  16636. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16637. isSuccess = ConfigurationStatus_Accepted;
  16638. }
  16639. else if(strcmp(str, "str")== 0)
  16640. {
  16641. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16642. isSuccess = ConfigurationStatus_Accepted;
  16643. }
  16644. else if(strcmp(str, "trs")== 0)
  16645. {
  16646. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16647. isSuccess = ConfigurationStatus_Accepted;
  16648. }
  16649. else if(strcmp(str, "tsr")== 0)
  16650. {
  16651. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16652. isSuccess = ConfigurationStatus_Accepted;
  16653. }
  16654. else
  16655. {
  16656. isSuccess = ConfigurationStatus_Rejected;
  16657. }
  16658. }
  16659. else
  16660. {
  16661. isSuccess = ConfigurationStatus_Rejected;
  16662. }
  16663. }
  16664. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16665. {
  16666. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16667. {
  16668. check_ascii = value[0];
  16669. if( (check_ascii < 48) || (check_ascii > 57) )
  16670. {
  16671. isSuccess = ConfigurationStatus_Rejected;
  16672. }
  16673. else
  16674. {
  16675. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16676. isSuccess = ConfigurationStatus_Accepted;
  16677. }
  16678. }
  16679. else
  16680. {
  16681. isSuccess = ConfigurationStatus_Rejected;
  16682. }
  16683. }
  16684. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16685. {
  16686. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16687. {
  16688. strcpy(str, (const char*)value);
  16689. for(int i = 0; str[i]; i++)
  16690. {
  16691. str[i] = tolower(str[i]);
  16692. }
  16693. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16694. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16695. isSuccess = ConfigurationStatus_Accepted;
  16696. }
  16697. else
  16698. {
  16699. isSuccess = ConfigurationStatus_Rejected;
  16700. }
  16701. }
  16702. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16703. {
  16704. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16705. {
  16706. strcpy(str, (const char*)value);
  16707. for(int i = 0; str[i]; i++)
  16708. {
  16709. str[i] = tolower(str[i]);
  16710. }
  16711. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16712. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16713. isSuccess = ConfigurationStatus_Accepted;
  16714. }
  16715. else
  16716. {
  16717. isSuccess = ConfigurationStatus_Rejected;
  16718. }
  16719. }
  16720. if(strcmp(key, "StopTxnAlignedData") == 0)
  16721. {
  16722. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16723. {
  16724. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16725. isSuccess = ConfigurationStatus_Accepted;
  16726. }
  16727. else
  16728. {
  16729. isSuccess = ConfigurationStatus_Rejected;
  16730. }
  16731. }
  16732. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16733. {
  16734. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16735. {
  16736. check_ascii = value[0];
  16737. if( (check_ascii < 48) || (check_ascii > 57) )
  16738. {
  16739. isSuccess = ConfigurationStatus_Rejected;
  16740. }
  16741. else
  16742. {
  16743. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16744. isSuccess = ConfigurationStatus_Accepted;
  16745. }
  16746. }
  16747. else
  16748. {
  16749. isSuccess = ConfigurationStatus_Rejected;
  16750. }
  16751. }
  16752. if(strcmp(key, "StopTxnSampledData") == 0)
  16753. {
  16754. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16755. {
  16756. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16757. isSuccess = ConfigurationStatus_Accepted;
  16758. }
  16759. else
  16760. {
  16761. isSuccess = ConfigurationStatus_Rejected;
  16762. }
  16763. }
  16764. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16765. {
  16766. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16767. {
  16768. check_ascii = value[0];
  16769. if( (check_ascii < 48) || (check_ascii > 57) )
  16770. {
  16771. isSuccess = ConfigurationStatus_Rejected;
  16772. }
  16773. else
  16774. {
  16775. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16776. isSuccess = ConfigurationStatus_Accepted;
  16777. }
  16778. }
  16779. else
  16780. {
  16781. isSuccess = ConfigurationStatus_Rejected;
  16782. }
  16783. }
  16784. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16785. {
  16786. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16787. {
  16788. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16789. isSuccess = ConfigurationStatus_Accepted;
  16790. }
  16791. else
  16792. {
  16793. isSuccess = ConfigurationStatus_Rejected;
  16794. }
  16795. }
  16796. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16797. {
  16798. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16799. {
  16800. check_ascii = value[0];
  16801. if( (check_ascii < 48) || (check_ascii > 57) )
  16802. {
  16803. isSuccess = ConfigurationStatus_Rejected;
  16804. }
  16805. else
  16806. {
  16807. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16808. isSuccess = ConfigurationStatus_Accepted;
  16809. }
  16810. }
  16811. else
  16812. {
  16813. isSuccess = ConfigurationStatus_Rejected;
  16814. }
  16815. }
  16816. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16817. {
  16818. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16819. {
  16820. check_ascii = value[0];
  16821. if( (check_ascii < 48) || (check_ascii > 57) )
  16822. {
  16823. isSuccess = ConfigurationStatus_Rejected;
  16824. }
  16825. else
  16826. {
  16827. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16828. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16829. TransactionMessageAttemptsValue = atoi(value);
  16830. isSuccess = ConfigurationStatus_Accepted;
  16831. }
  16832. }
  16833. else
  16834. {
  16835. isSuccess = ConfigurationStatus_Rejected;
  16836. }
  16837. }
  16838. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16839. {
  16840. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16841. {
  16842. check_ascii = value[0];
  16843. if( (check_ascii < 48) || (check_ascii > 57) )
  16844. {
  16845. isSuccess = ConfigurationStatus_Rejected;
  16846. }
  16847. else
  16848. {
  16849. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16850. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16851. TransactionMessageRetryIntervalValue = atoi(value);
  16852. isSuccess = ConfigurationStatus_Accepted;
  16853. }
  16854. }
  16855. else
  16856. {
  16857. isSuccess = ConfigurationStatus_Rejected;
  16858. }
  16859. }
  16860. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16861. {
  16862. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16863. {
  16864. strcpy(str, (const char*)value);
  16865. for(int i = 0; str[i]; i++)
  16866. {
  16867. str[i] = tolower(str[i]);
  16868. }
  16869. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16870. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16871. isSuccess = ConfigurationStatus_Accepted;
  16872. }
  16873. else
  16874. {
  16875. isSuccess = ConfigurationStatus_Rejected;
  16876. }
  16877. }
  16878. if(strcmp(key, "WebSocketPingInterval") == 0)
  16879. {
  16880. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16881. {
  16882. check_ascii = value[0];
  16883. if( (check_ascii < 48) || (check_ascii > 57) )
  16884. {
  16885. isSuccess = ConfigurationStatus_Rejected;
  16886. }
  16887. else
  16888. {
  16889. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16890. isSuccess = ConfigurationStatus_Accepted;
  16891. if((atoi(value) == 0) || (atoi(value) >= 10))
  16892. {
  16893. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16894. isSuccess = ConfigurationStatus_Accepted;
  16895. }
  16896. else
  16897. isSuccess = ConfigurationStatus_Rejected;
  16898. }
  16899. }
  16900. else
  16901. {
  16902. isSuccess = ConfigurationStatus_Rejected;
  16903. }
  16904. }
  16905. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16906. {
  16907. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16908. {
  16909. strcpy(str, (const char*)value);
  16910. for(int i = 0; str[i]; i++)
  16911. {
  16912. str[i] = tolower(str[i]);
  16913. }
  16914. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16915. isSuccess = ConfigurationStatus_Accepted;
  16916. }
  16917. else
  16918. {
  16919. isSuccess = ConfigurationStatus_Rejected;
  16920. }
  16921. }
  16922. if(strcmp(key, "AuthorizationKey") == 0)
  16923. {
  16924. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16925. {
  16926. strcpy(str, (const char*)value);
  16927. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16928. strcpy((char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16929. isSuccess = ConfigurationStatus_Accepted;
  16930. }
  16931. else
  16932. {
  16933. isSuccess = ConfigurationStatus_Rejected;
  16934. }
  16935. }
  16936. if(strcmp(key, "SecurityProfile") == 0)
  16937. {
  16938. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16939. {
  16940. check_ascii = value[0];
  16941. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16942. {
  16943. isSuccess = ConfigurationStatus_Rejected;
  16944. }
  16945. else if(check_ascii == 0x33)
  16946. {
  16947. isSuccess = NotSupported;
  16948. }
  16949. else
  16950. {
  16951. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16952. {
  16953. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16954. ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = atoi(value);
  16955. isSuccess = ConfigurationStatus_Accepted;
  16956. }
  16957. else
  16958. isSuccess = ConfigurationStatus_Rejected;
  16959. }
  16960. }
  16961. else
  16962. {
  16963. isSuccess = ConfigurationStatus_Rejected;
  16964. }
  16965. }
  16966. if(strcmp(key, "DefaultPrice") == 0)
  16967. {
  16968. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16969. {
  16970. strcpy(str, (const char*)value);
  16971. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16972. isSuccess = ConfigurationStatus_Accepted;
  16973. }
  16974. else
  16975. {
  16976. isSuccess = ConfigurationStatus_Rejected;
  16977. }
  16978. }
  16979. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16980. {
  16981. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16982. {
  16983. strcpy(str, (const char*)value);
  16984. for(int i = 0; str[i]; i++)
  16985. {
  16986. str[i] = tolower(str[i]);
  16987. }
  16988. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16989. isSuccess = ConfigurationStatus_Accepted;
  16990. }
  16991. else
  16992. {
  16993. isSuccess = ConfigurationStatus_Rejected;
  16994. }
  16995. }
  16996. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16997. {
  16998. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16999. {
  17000. strcpy(str, (const char*)value);
  17001. for(int i = 0; str[i]; i++)
  17002. {
  17003. str[i] = tolower(str[i]);
  17004. }
  17005. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17006. isSuccess = ConfigurationStatus_Accepted;
  17007. }
  17008. else
  17009. {
  17010. isSuccess = ConfigurationStatus_Rejected;
  17011. }
  17012. }
  17013. if(strcmp(key, "SystemUptimeSec") == 0)
  17014. {
  17015. isSuccess = NotSupported;
  17016. }
  17017. if(strcmp(key, "FreeVend") == 0)
  17018. {
  17019. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17020. {
  17021. strcpy(str, (const char*)value);
  17022. for(int i = 0; str[i]; i++)
  17023. {
  17024. str[i] = tolower(str[i]);
  17025. }
  17026. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  17027. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17028. isSuccess = ConfigurationStatus_Accepted;
  17029. }
  17030. else
  17031. {
  17032. isSuccess = ConfigurationStatus_Rejected;
  17033. }
  17034. }
  17035. if(strcmp(key, "FreeVendIdtag") == 0)
  17036. {
  17037. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17038. {
  17039. strcpy(str, (const char*)value);
  17040. if(strlen(str) <= 20)
  17041. {
  17042. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  17043. isSuccess = ConfigurationStatus_Accepted;
  17044. }
  17045. else
  17046. {
  17047. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  17048. isSuccess = ConfigurationStatus_Rejected;
  17049. }
  17050. }
  17051. else
  17052. {
  17053. isSuccess = ConfigurationStatus_Rejected;
  17054. }
  17055. }
  17056. if(strcmp(key, "OcppServer") == 0)
  17057. {
  17058. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17059. {
  17060. strcpy(str, (const char*)value);
  17061. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  17062. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  17063. isSuccess = ConfigurationStatus_Accepted;
  17064. }
  17065. else
  17066. {
  17067. isSuccess = ConfigurationStatus_Rejected;
  17068. }
  17069. }
  17070. if(strcmp(key, "MaintainServer") == 0)
  17071. {
  17072. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17073. {
  17074. strcpy(str, (const char*)value);
  17075. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  17076. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  17077. isSuccess = ConfigurationStatus_Accepted;
  17078. }
  17079. else
  17080. {
  17081. isSuccess = ConfigurationStatus_Rejected;
  17082. }
  17083. }
  17084. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  17085. {
  17086. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17087. {
  17088. strcpy(str, (const char*)value);
  17089. for(int i = 0; str[i]; i++)
  17090. {
  17091. str[i] = tolower(str[i]);
  17092. }
  17093. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  17094. isSuccess = ConfigurationStatus_Accepted;
  17095. }
  17096. else
  17097. {
  17098. isSuccess = ConfigurationStatus_Rejected;
  17099. }
  17100. }
  17101. if(strcmp(key, "StatusNotificationInterval") == 0)
  17102. {
  17103. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17104. {
  17105. check_ascii = value[0];
  17106. if( (check_ascii < 48) || (check_ascii > 57) )
  17107. {
  17108. isSuccess = ConfigurationStatus_Rejected;
  17109. }
  17110. else
  17111. {
  17112. if((atoi(value) == 0) || (atoi(value) >= 10))
  17113. {
  17114. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  17115. isSuccess = ConfigurationStatus_Accepted;
  17116. }
  17117. else
  17118. isSuccess = ConfigurationStatus_Rejected;
  17119. }
  17120. }
  17121. else
  17122. {
  17123. isSuccess = ConfigurationStatus_Rejected;
  17124. }
  17125. }
  17126. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  17127. {
  17128. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  17129. {
  17130. check_ascii = value[0];
  17131. if( (check_ascii < 48) || (check_ascii > 57) )
  17132. {
  17133. isSuccess = ConfigurationStatus_Rejected;
  17134. }
  17135. else
  17136. {
  17137. if(atoi(value) >= 0)
  17138. {
  17139. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value) );
  17140. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  17141. isSuccess = ConfigurationStatus_Accepted;
  17142. }
  17143. else
  17144. isSuccess = ConfigurationStatus_Rejected;
  17145. }
  17146. }
  17147. else
  17148. {
  17149. isSuccess = ConfigurationStatus_Rejected;
  17150. }
  17151. }
  17152. if(strcmp(key, "PowerSharingServerIP") == 0)
  17153. {
  17154. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  17155. {
  17156. strcpy(str, (const char*)value);
  17157. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  17158. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  17159. isSuccess = ConfigurationStatus_Accepted;
  17160. }
  17161. else
  17162. {
  17163. isSuccess = ConfigurationStatus_Rejected;
  17164. }
  17165. }
  17166. if(strcmp(key, "EVCCID_PREFIX") == 0)
  17167. {
  17168. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  17169. {
  17170. strcpy(str, (const char*)value);
  17171. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  17172. isSuccess = ConfigurationStatus_Accepted;
  17173. }
  17174. else
  17175. {
  17176. isSuccess = ConfigurationStatus_Rejected;
  17177. }
  17178. }
  17179. if(strcmp(key, "OffLineMaxChargingPower") == 0)
  17180. {
  17181. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  17182. {
  17183. if(atoi(value) > modelnameInfo.ratedPower)
  17184. {
  17185. isSuccess = ConfigurationStatus_Rejected;
  17186. }
  17187. else{
  17188. strcpy(str, (const char*)value);
  17189. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", str );
  17190. isSuccess = ConfigurationStatus_Accepted;
  17191. }
  17192. }
  17193. else
  17194. {
  17195. isSuccess = ConfigurationStatus_Rejected;
  17196. }
  17197. }
  17198. #if 0
  17199. //For OCPP Test Case
  17200. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  17201. {
  17202. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17203. {
  17204. strcpy(str, (const char*)value);
  17205. for(int i = 0; str[i]; i++)
  17206. {
  17207. str[i] = tolower(str[i]);
  17208. }
  17209. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17210. isSuccess = ConfigurationStatus_Accepted;
  17211. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17212. }
  17213. else
  17214. {
  17215. isSuccess = ConfigurationStatus_Rejected;
  17216. }
  17217. }
  17218. #endif
  17219. #if 1
  17220. if(strcmp(key, "LocalAuthListEnabled") == 0)
  17221. {
  17222. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17223. {
  17224. strcpy(str, (const char*)value);
  17225. for(int i = 0; str[i]; i++)
  17226. {
  17227. str[i] = tolower(str[i]);
  17228. }
  17229. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17230. isSuccess = ConfigurationStatus_Accepted;
  17231. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17232. }
  17233. else
  17234. {
  17235. isSuccess = ConfigurationStatus_Rejected;
  17236. }
  17237. }
  17238. #endif
  17239. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  17240. {
  17241. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  17242. {
  17243. check_ascii = value[0];
  17244. if( (check_ascii < 48) || (check_ascii > 57) )
  17245. {
  17246. isSuccess = ConfigurationStatus_Rejected;
  17247. }
  17248. else
  17249. {
  17250. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  17251. isSuccess = ConfigurationStatus_Accepted;
  17252. }
  17253. }
  17254. else
  17255. {
  17256. isSuccess = ConfigurationStatus_Rejected;
  17257. }
  17258. }
  17259. if(strcmp(key, "SendLocalListMaxLength") == 0)
  17260. {
  17261. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17262. {
  17263. check_ascii = value[0];
  17264. if( (check_ascii < 48) || (check_ascii > 57) )
  17265. {
  17266. isSuccess = ConfigurationStatus_Rejected;
  17267. }
  17268. else
  17269. {
  17270. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  17271. isSuccess = ConfigurationStatus_Accepted;
  17272. }
  17273. }
  17274. else
  17275. {
  17276. isSuccess = ConfigurationStatus_Rejected;
  17277. }
  17278. }
  17279. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  17280. {
  17281. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17282. {
  17283. strcpy(str, (const char*)value);
  17284. for(int i = 0; str[i]; i++)
  17285. {
  17286. str[i] = tolower(str[i]);
  17287. }
  17288. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17289. isSuccess = ConfigurationStatus_Accepted;
  17290. }
  17291. else
  17292. {
  17293. isSuccess = ConfigurationStatus_Rejected;
  17294. }
  17295. }
  17296. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  17297. {
  17298. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17299. {
  17300. check_ascii = value[0];
  17301. if( (check_ascii < 48) || (check_ascii > 57) )
  17302. {
  17303. isSuccess = ConfigurationStatus_Rejected;
  17304. }
  17305. else
  17306. {
  17307. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  17308. isSuccess = ConfigurationStatus_Accepted;
  17309. }
  17310. }
  17311. else
  17312. {
  17313. isSuccess = ConfigurationStatus_Rejected;
  17314. }
  17315. }
  17316. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  17317. {
  17318. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17319. {
  17320. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  17321. isSuccess = ConfigurationStatus_Accepted;
  17322. }
  17323. else
  17324. {
  17325. isSuccess = ConfigurationStatus_Rejected;
  17326. }
  17327. }
  17328. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  17329. {
  17330. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17331. {
  17332. check_ascii = value[0];
  17333. if( (check_ascii < 48) || (check_ascii > 57) )
  17334. {
  17335. isSuccess = ConfigurationStatus_Rejected;
  17336. }
  17337. else
  17338. {
  17339. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  17340. isSuccess = ConfigurationStatus_Accepted;
  17341. }
  17342. }
  17343. else
  17344. {
  17345. isSuccess = ConfigurationStatus_Rejected;
  17346. }
  17347. }
  17348. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  17349. {
  17350. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17351. {
  17352. strcpy(str, (const char*)value);
  17353. for(int i = 0; str[i]; i++)
  17354. {
  17355. str[i] = tolower(str[i]);
  17356. }
  17357. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17358. isSuccess = ConfigurationStatus_Accepted;
  17359. }
  17360. else
  17361. {
  17362. isSuccess = ConfigurationStatus_Rejected;
  17363. }
  17364. }
  17365. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  17366. {
  17367. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  17368. {
  17369. check_ascii = value[0];
  17370. if( (check_ascii < 48) || (check_ascii > 57) )
  17371. {
  17372. isSuccess = ConfigurationStatus_Rejected;
  17373. }
  17374. else
  17375. {
  17376. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  17377. isSuccess = ConfigurationStatus_Accepted;
  17378. }
  17379. }
  17380. else
  17381. {
  17382. isSuccess = ConfigurationStatus_Rejected;
  17383. }
  17384. }
  17385. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17386. return isSuccess;
  17387. }
  17388. int TransactionMessageAttemptsGet(void)
  17389. {
  17390. return TransactionMessageAttemptsValue;
  17391. }
  17392. int FirstHeartBeatResponse(void)
  17393. {
  17394. return FirstHeartBeat;
  17395. }
  17396. int TransactionMessageRetryIntervalGet(void)
  17397. {
  17398. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17399. }
  17400. int ReadHttpStatus(int sock)
  17401. {
  17402. //char c;
  17403. char buff[1024]="",*ptr=buff+1;
  17404. int bytes_received, status;
  17405. DEBUG_INFO("Begin Response ..\n");
  17406. while((bytes_received = recv(sock, ptr, 1, 0))){
  17407. if(bytes_received==-1){
  17408. perror("ReadHttpStatus");
  17409. exit(1);
  17410. }
  17411. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  17412. ptr++;
  17413. }
  17414. *ptr=0;
  17415. ptr=buff+1;
  17416. sscanf(ptr,"%*s %d ", &status);
  17417. DEBUG_INFO("%s\n",ptr);
  17418. DEBUG_INFO("status=%d\n",status);
  17419. DEBUG_INFO("End Response ..\n");
  17420. return (bytes_received>0)?status:0;
  17421. }
  17422. //the only filed that it parsed is 'Content-Length'
  17423. int ParseHeader(int sock)
  17424. {
  17425. //char c;
  17426. char buff[1024]="",*ptr=buff+4;
  17427. int bytes_received;
  17428. DEBUG_INFO("Begin HEADER ..\n");
  17429. while((bytes_received = recv(sock, ptr, 1, 0))){
  17430. if(bytes_received==-1){
  17431. perror("Parse Header");
  17432. exit(1);
  17433. }
  17434. if(
  17435. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  17436. (ptr[-1]=='\r') && (*ptr=='\n' )
  17437. ) break;
  17438. ptr++;
  17439. }
  17440. *ptr=0;
  17441. ptr=buff+4;
  17442. //printf("%s",ptr);
  17443. if(bytes_received){
  17444. ptr=strstr(ptr,"Content-Length:");
  17445. if(ptr){
  17446. sscanf(ptr,"%*s %d",&bytes_received);
  17447. }else
  17448. bytes_received=-1; //unknown size
  17449. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  17450. }
  17451. DEBUG_INFO("End HEADER ..\n");
  17452. return bytes_received ;
  17453. }
  17454. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  17455. {
  17456. int result = TRUE;
  17457. char rmFileCmd[100]={0};
  17458. char FilePath[100]={0};
  17459. char ftpbuf[200];
  17460. int systemresult;
  17461. sprintf(FilePath,"/mnt/%s",filename);
  17462. system("ping 8.8.8.8 &");
  17463. if((access(FilePath,F_OK))!=-1)
  17464. {
  17465. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17466. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17467. system(rmFileCmd);
  17468. }
  17469. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17470. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  17471. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17472. systemresult = system(ftpbuf);
  17473. if(systemresult != 0)
  17474. {
  17475. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  17476. result = FALSE;
  17477. }
  17478. system("pkill ping");
  17479. return result;
  17480. }
  17481. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  17482. {
  17483. int result = TRUE;
  17484. char rmFileCmd[100]={0};
  17485. char FilePath[100]={0};
  17486. char ftpbuf[200];
  17487. int systemresult;
  17488. sprintf(FilePath,"/mnt/%s",filename);
  17489. system("ping 8.8.8.8 &");
  17490. if((access(FilePath,F_OK))!=-1)
  17491. {
  17492. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17493. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17494. system(rmFileCmd);
  17495. }
  17496. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17497. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  17498. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17499. systemresult = system(ftpbuf);
  17500. if(systemresult != 0)
  17501. {
  17502. DEBUG_WARN("scp error!\n");
  17503. result = FALSE;
  17504. }
  17505. system("pkill ping");
  17506. return result;
  17507. }
  17508. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  17509. {
  17510. int result = TRUE;
  17511. char rmFileCmd[100]={0};
  17512. char FilePath[100]={0};
  17513. char ftpbuf[200];
  17514. int systemresult;
  17515. sprintf(FilePath,"/mnt/%s",filename);
  17516. system("ping 8.8.8.8 &");
  17517. if((access(FilePath,F_OK))!=-1)
  17518. {
  17519. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17520. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17521. system(rmFileCmd);
  17522. }
  17523. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17524. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  17525. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17526. systemresult = system(ftpbuf);
  17527. if(systemresult != 0)
  17528. {
  17529. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  17530. DEBUG_INFO("Download command: %s\n",ftpbuf);
  17531. systemresult = system(ftpbuf);
  17532. if(systemresult != 0)
  17533. {
  17534. DEBUG_WARN("FTP download fail!\n");
  17535. result = FALSE;
  17536. }
  17537. }
  17538. system("pkill ping");
  17539. return result;
  17540. }
  17541. int httpUploadFile(char *location, char *path, char *filename,char *url)
  17542. {
  17543. char rmFileCmd[100]={0};
  17544. char FilePath[100]={0};
  17545. char buf[512];
  17546. int systemresult = 0;
  17547. //DEBUG_INFO("filename=%s\n",filename);
  17548. //DEBUG_INFO("url=%s\n",url);
  17549. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  17550. if((access(FilePath,F_OK))!=-1)
  17551. {
  17552. DEBUG_INFO("filename=%s exist.\n",FilePath);
  17553. sprintf(rmFileCmd,"rm -f %s",FilePath);
  17554. system(rmFileCmd);
  17555. }
  17556. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  17557. if(fp == NULL)
  17558. {
  17559. DEBUG_INFO("log is NULL\n");
  17560. return FALSE;
  17561. }
  17562. else
  17563. {
  17564. fprintf(fp, "%s\n", url);
  17565. fprintf(fp, "%s\n", filename);
  17566. fclose(fp);
  17567. }
  17568. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  17569. if(phpFP == NULL)
  17570. {
  17571. DEBUG_INFO("PHP upload fail.\n");
  17572. return FALSE;
  17573. }
  17574. else
  17575. {
  17576. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17577. {
  17578. if(strstr(buf, "result") != NULL)
  17579. {
  17580. sscanf(buf, "result: %d", &systemresult);
  17581. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  17582. }
  17583. }
  17584. pclose(phpFP);
  17585. }
  17586. if(systemresult != 1)
  17587. {
  17588. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  17589. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  17590. if(phpFP == NULL)
  17591. {
  17592. DEBUG_WARN("PHP PUT upload fail.\n");
  17593. return FALSE;
  17594. }
  17595. else
  17596. {
  17597. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  17598. {
  17599. if(strstr(buf, "result") != NULL)
  17600. {
  17601. sscanf(buf, "result: %d", &systemresult);
  17602. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  17603. }
  17604. }
  17605. pclose(phpFP);
  17606. }
  17607. }
  17608. if(systemresult != 1)
  17609. {
  17610. DEBUG_WARN("PHP PUT upload fail.\n");
  17611. return FALSE;
  17612. }
  17613. return TRUE;
  17614. }
  17615. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  17616. {
  17617. int result = FALSE;
  17618. char ftpbuf[200];
  17619. int systemresult;
  17620. /*
  17621. // Domaind name transfer to IP address
  17622. struct hostent* server;
  17623. char *IPbuffer;
  17624. server = gethostbyname(location);
  17625. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  17626. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17627. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  17628. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  17629. systemresult = system(ftpbuf);
  17630. if(systemresult != 0)
  17631. {
  17632. DEBUG_INFO("ftpput error!\n");
  17633. }
  17634. else
  17635. {
  17636. result = TRUE;
  17637. DEBUG_INFO("ftpput OK!\n");
  17638. }
  17639. return result;
  17640. }
  17641. int GetOcppServerURL()
  17642. {
  17643. int result = FALSE;
  17644. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  17645. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  17646. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  17647. struct yuarel url;
  17648. char urlStr[512];
  17649. // OCPPPH only
  17650. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  17651. if((ShmSysConfigAndInfo->SysConfig.MaintainServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) )
  17652. {
  17653. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  17654. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17655. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  17656. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.MaintainServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  17657. if(yuarel_parse(&url, urlStr) != -1)
  17658. {
  17659. sprintf(OcppProtocol, "%s", url.scheme);
  17660. sprintf(OcppHost, "%s", url.host);
  17661. if(url.path == NULL)
  17662. OcppTempPath[0] = '\0';
  17663. else
  17664. sprintf(OcppTempPath, "%s", url.path);
  17665. if(url.port == 0)
  17666. {
  17667. if(strcmp(OcppProtocol, "wss") == 0)
  17668. OcppPort = 443;
  17669. else
  17670. OcppPort = 80;
  17671. }
  17672. else
  17673. OcppPort = url.port;
  17674. result = TRUE;
  17675. }
  17676. }
  17677. else
  17678. {
  17679. strcpy(OcppHost,"");
  17680. }
  17681. return result;
  17682. }
  17683. int GetOcppPath()
  17684. {
  17685. int result = FALSE;
  17686. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  17687. {
  17688. if(OcppTempPath == NULL)
  17689. {
  17690. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  17691. }
  17692. else
  17693. {
  17694. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  17695. }
  17696. result = TRUE;
  17697. goto End;
  17698. }
  17699. else
  17700. {
  17701. strcpy(OcppPath,"");
  17702. }
  17703. End:
  17704. return result;
  17705. }
  17706. int GetOcppPort()
  17707. {
  17708. return OcppPort;
  17709. }
  17710. int GetOcppConnStatus(void)
  17711. {
  17712. return ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus;
  17713. }
  17714. void SetOcppConnStatus(uint8_t status)
  17715. {
  17716. ShmOCPP16DataPH->OcppConnStatus = status;
  17717. ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus = status;
  17718. }
  17719. int GetHeartBeatWithNOResponse(void)
  17720. {
  17721. return HeartBeatWithNOResponse;
  17722. }
  17723. void SetHeartBeatWithNOResponse(void)
  17724. {
  17725. HeartBeatWithNOResponse = 0;
  17726. }
  17727. void GetStartTransactionIdTag(int gun_index)
  17728. {
  17729. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17730. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  17731. }
  17732. int GetStartTransactionId(int gun_index)
  17733. {
  17734. return ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  17735. }
  17736. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17737. {
  17738. char ch;
  17739. FILE *fptr1;
  17740. int temptransactionId;
  17741. char str[100]={0};
  17742. temptransactionId = 0;
  17743. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17744. {
  17745. DEBUG_INFO("IdTag is empty.\n");
  17746. return temptransactionId;
  17747. }
  17748. /*------ Read the file ----------------*/
  17749. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  17750. if (!fptr1)
  17751. {
  17752. DEBUG_INFO("QueueTransactionId file open error.\n");
  17753. //printf(" File not found or unable to open the input file!!\n");
  17754. return temptransactionId;
  17755. }
  17756. ch=fgetc(fptr1);
  17757. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  17758. rewind(fptr1);
  17759. if(ch!=EOF)
  17760. {
  17761. // printf("%c",ch);
  17762. while (fgets(str, 100, fptr1) != NULL)
  17763. {
  17764. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17765. if(str[0]=='\0')
  17766. {
  17767. break;
  17768. }
  17769. char *revbuf[8] = {0}; // Variable store string split
  17770. int num = 0;// Quantity after string split
  17771. DEBUG_INFO("Transaction queue data= %s\n", str);
  17772. splitstring(str,",",revbuf,&num); // String split
  17773. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17774. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17775. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17776. DEBUG_INFO("------------------------------\n");
  17777. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17778. {
  17779. if(isStopTransaction)
  17780. {
  17781. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17782. {
  17783. temptransactionId = atoi(revbuf[2]);
  17784. //break;
  17785. }
  17786. }
  17787. else
  17788. {
  17789. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17790. {
  17791. temptransactionId = atoi(revbuf[2]);
  17792. //break;
  17793. }
  17794. }
  17795. }
  17796. }
  17797. }
  17798. else
  17799. DEBUG_INFO("EOF\n");
  17800. fclose(fptr1);
  17801. /*------- End of reading ---------------*/
  17802. return temptransactionId;
  17803. }
  17804. void SetTransactionIdZero(int transactionId)
  17805. {
  17806. char ch;
  17807. FILE *fptr1, *fptr2;
  17808. int temptransactionId = 0;
  17809. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  17810. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  17811. if (!fptr1)
  17812. {
  17813. //printf(" File not found or unable to open the input file!!\n");
  17814. return ;
  17815. }
  17816. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17817. if (!fptr2)
  17818. {
  17819. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17820. fclose(fptr1);
  17821. return ;
  17822. }
  17823. ch=fgetc(fptr1);
  17824. rewind(fptr1);
  17825. if(ch!=EOF)
  17826. {
  17827. // copy all contents to the temporary file except the specific line
  17828. while (fgets(str, 100, fptr1) != NULL)
  17829. {
  17830. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17831. if(str[0]=='\0')
  17832. {
  17833. break;
  17834. }
  17835. char *revbuf[8] = {0};
  17836. int num = 0;
  17837. strcpy(strtemp, str);
  17838. splitstring(str,",",revbuf,&num);
  17839. if(revbuf[2][0] != '\0')
  17840. {
  17841. temptransactionId = atoi(revbuf[2]);
  17842. if(transactionId != temptransactionId)
  17843. {
  17844. fprintf(fptr2, "%s\n", strtemp);
  17845. }
  17846. }
  17847. }
  17848. }
  17849. fclose(fptr1);
  17850. fclose(fptr2);
  17851. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  17852. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  17853. /*------ Read the file ----------------*/
  17854. }
  17855. int InternetDisconnect(void)
  17856. {
  17857. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  17858. }
  17859. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17860. void storeTempStopTransaction(int gun_index)
  17861. {
  17862. char guid[37]={0};
  17863. int tempIndex = 0;
  17864. char TempStopTransaction[256];
  17865. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17866. DEBUG_INFO("storeTempStopTransaction...\n");
  17867. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  17868. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  17869. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  17870. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17871. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17872. {
  17873. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17874. {
  17875. tempIndex = ((gun_index==2) ? 1: 0);
  17876. }
  17877. else
  17878. {
  17879. tempIndex = gun_index;
  17880. }
  17881. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17882. {
  17883. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17884. {
  17885. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  17886. }
  17887. }// END OF CHAdeMO_QUANTITY
  17888. }
  17889. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17890. {
  17891. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17892. {
  17893. tempIndex = ((gun_index==2) ? 1: 0);
  17894. }
  17895. else
  17896. {
  17897. tempIndex = gun_index;
  17898. }
  17899. for (int index = 0; index < CCS_QUANTITY; index++)
  17900. {
  17901. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17902. {
  17903. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  17904. }
  17905. }// END OF CCS_QUANTITY
  17906. }
  17907. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17908. {
  17909. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17910. {
  17911. tempIndex = ((gun_index==2) ? 1: 0);
  17912. }
  17913. else
  17914. {
  17915. tempIndex = gun_index;
  17916. }
  17917. for (int index = 0; index < GB_QUANTITY; index++)
  17918. {
  17919. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17920. {
  17921. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17922. }
  17923. }// END OF GB_QUANTITY
  17924. }
  17925. else if(gunType[gun_index] == GUN_TYPE_DO)
  17926. {
  17927. tempIndex = gun_index;
  17928. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17929. {
  17930. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17931. {
  17932. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17933. }
  17934. }
  17935. }
  17936. else
  17937. {
  17938. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17939. {
  17940. tempIndex = 2;
  17941. }
  17942. else
  17943. {
  17944. tempIndex = gun_index;
  17945. }
  17946. for (int index = 0; index < AC_QUANTITY; index++)
  17947. {
  17948. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17949. {
  17950. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17951. }
  17952. }// END OF AC_QUANTITY
  17953. }
  17954. //Stop Transaction Time
  17955. struct timeval tmnow;
  17956. struct tm *tm;
  17957. char buf[28];//, usec_buf[6];
  17958. gettimeofday(&tmnow, NULL);
  17959. time_t t;
  17960. t = time(NULL);
  17961. /*UTC time and date*/
  17962. tm = gmtime(&t);
  17963. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17964. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  17965. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  17966. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  17967. random_uuid(guid);
  17968. /***********************************transactionData******************************************************/
  17969. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17970. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17971. //=================================
  17972. //1. Transaction_Begin
  17973. //=================================
  17974. //============================== Energy.Active.Import.Interval ===========================================
  17975. //=================================
  17976. //2. Transaction_End
  17977. //=================================
  17978. //2.1====================================== Current.Import L1 ==============================================
  17979. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17980. {
  17981. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17982. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17983. {
  17984. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17985. {
  17986. tempIndex = ((gun_index==2) ? 1: 0);
  17987. }
  17988. else
  17989. {
  17990. tempIndex = gun_index;
  17991. }
  17992. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17993. {
  17994. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17995. {
  17996. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17997. }
  17998. }// End of for CHAdeMO_QUANTITY
  17999. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18000. }
  18001. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18002. {
  18003. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18004. {
  18005. tempIndex = ((gun_index==2) ? 1: 0);
  18006. }
  18007. else
  18008. {
  18009. tempIndex = gun_index;
  18010. }
  18011. for (int index = 0; index < CCS_QUANTITY; index++)
  18012. {
  18013. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18014. {
  18015. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18016. }
  18017. }// End of for CCS_QUANTITY
  18018. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18019. }
  18020. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18021. {
  18022. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18023. {
  18024. tempIndex = ((gun_index==2) ? 1: 0);
  18025. }
  18026. else
  18027. {
  18028. tempIndex = gun_index;
  18029. }
  18030. for (int index = 0; index < GB_QUANTITY; index++)
  18031. {
  18032. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18033. {
  18034. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18035. }
  18036. }// End of for GB_QUANTITY
  18037. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18038. }
  18039. else if(gunType[gun_index] == GUN_TYPE_DO)
  18040. {
  18041. tempIndex = gun_index;
  18042. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18043. {
  18044. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18045. {
  18046. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  18047. }
  18048. }
  18049. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  18050. }
  18051. else
  18052. {
  18053. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18054. {
  18055. tempIndex = 2;
  18056. }
  18057. else
  18058. {
  18059. tempIndex = gun_index;
  18060. }
  18061. for (int index = 0; index < AC_QUANTITY; index++)
  18062. {
  18063. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18064. {
  18065. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  18066. }
  18067. }// End of for AC_QUANTITY
  18068. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18069. }
  18070. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18071. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  18072. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  18073. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  18074. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  18075. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18076. }
  18077. //2.2===================================== Energy.Active.Import.Interval ==========================================
  18078. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  18079. {
  18080. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18081. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18082. {
  18083. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18084. {
  18085. tempIndex = ((gun_index==2) ? 1: 0);
  18086. }
  18087. else
  18088. {
  18089. tempIndex = gun_index;
  18090. }
  18091. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18092. {
  18093. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18094. {
  18095. 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
  18096. }
  18097. }// END OF CHAdeMO_QUANTITY
  18098. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18099. }
  18100. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18101. {
  18102. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18103. {
  18104. tempIndex = ((gun_index==2) ? 1: 0);
  18105. }
  18106. else
  18107. {
  18108. tempIndex = gun_index;
  18109. }
  18110. for (int index = 0; index < CCS_QUANTITY; index++)
  18111. {
  18112. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18113. {
  18114. 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
  18115. }
  18116. }// END OF CCS_QUANTITY
  18117. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18118. }
  18119. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18120. {
  18121. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18122. {
  18123. tempIndex = ((gun_index==2) ? 1: 0);
  18124. }
  18125. else
  18126. {
  18127. tempIndex = gun_index;
  18128. }
  18129. for (int index = 0; index < GB_QUANTITY; index++)
  18130. {
  18131. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18132. {
  18133. 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
  18134. }
  18135. }// END OF GB_QUANTITY
  18136. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18137. }
  18138. else if(gunType[gun_index] == GUN_TYPE_DO)
  18139. {
  18140. tempIndex = gun_index;
  18141. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18142. {
  18143. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18144. {
  18145. 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
  18146. }
  18147. }
  18148. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  18149. }
  18150. else
  18151. {
  18152. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18153. {
  18154. tempIndex = 2;
  18155. }
  18156. else
  18157. {
  18158. tempIndex = gun_index;
  18159. }
  18160. for (int index = 0; index < AC_QUANTITY; index++)
  18161. {
  18162. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18163. {
  18164. 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
  18165. }
  18166. }// END OF AC_QUANTITY
  18167. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18168. }
  18169. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18170. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  18171. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  18172. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  18173. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  18174. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  18175. }
  18176. //2.3====================================== Power.Active.Import =========================================
  18177. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  18178. {
  18179. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18180. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18181. {
  18182. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18183. {
  18184. tempIndex = ((gun_index==2) ? 1: 0);
  18185. }
  18186. else
  18187. {
  18188. tempIndex = gun_index;
  18189. }
  18190. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18191. {
  18192. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18193. {
  18194. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18195. }
  18196. } // End for CHAdeMO_QUANTITY
  18197. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18198. }
  18199. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18200. {
  18201. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18202. {
  18203. tempIndex = ((gun_index==2) ? 1: 0);
  18204. }
  18205. else
  18206. {
  18207. tempIndex = gun_index;
  18208. }
  18209. for (int index = 0; index < CCS_QUANTITY; index++)
  18210. {
  18211. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18212. {
  18213. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18214. }
  18215. } // END for CCS_QUANTITY
  18216. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18217. }
  18218. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18219. {
  18220. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18221. {
  18222. tempIndex = ((gun_index==2) ? 1: 0);
  18223. }
  18224. else
  18225. {
  18226. tempIndex = gun_index;
  18227. }
  18228. for (int index = 0; index < GB_QUANTITY; index++)
  18229. {
  18230. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18231. {
  18232. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18233. }
  18234. }// END for GB_QUANTITY
  18235. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18236. }
  18237. else if(gunType[gun_index] == GUN_TYPE_DO)
  18238. {
  18239. tempIndex = gun_index;
  18240. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18241. {
  18242. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18243. {
  18244. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18245. }
  18246. }
  18247. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  18248. }
  18249. else
  18250. {
  18251. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18252. {
  18253. tempIndex = 2;
  18254. }
  18255. else
  18256. {
  18257. tempIndex = gun_index;
  18258. }
  18259. for (int index = 0; index < AC_QUANTITY; index++)
  18260. {
  18261. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18262. {
  18263. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  18264. }
  18265. } // END for AC_QUANTITY
  18266. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18267. }
  18268. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18269. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  18270. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  18271. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  18272. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  18273. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  18274. }
  18275. //2.4====================================== Voltage L1 ====================================================
  18276. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18277. {
  18278. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18279. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18280. {
  18281. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18282. {
  18283. tempIndex = ((gun_index==2) ? 1: 0);
  18284. }
  18285. else
  18286. {
  18287. tempIndex = gun_index;
  18288. }
  18289. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18290. {
  18291. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18292. {
  18293. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18294. }
  18295. } // END OF FOR CHAdeMO_QUANTITY
  18296. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18297. }
  18298. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18299. {
  18300. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18301. {
  18302. tempIndex = ((gun_index==2) ? 1: 0);
  18303. }
  18304. else
  18305. {
  18306. tempIndex = gun_index;
  18307. }
  18308. for (int index = 0; index < CCS_QUANTITY; index++)
  18309. {
  18310. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18311. {
  18312. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18313. }
  18314. } // END OF FOR CCS_QUANTITY
  18315. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18316. }
  18317. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18318. {
  18319. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18320. {
  18321. tempIndex = ((gun_index==2) ? 1: 0);
  18322. }
  18323. else
  18324. {
  18325. tempIndex = gun_index;
  18326. }
  18327. for (int index = 0; index < GB_QUANTITY; index++)
  18328. {
  18329. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18330. {
  18331. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18332. }
  18333. } // END OF FOR GB_QUANTITY
  18334. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18335. }
  18336. else if(gunType[gun_index] == GUN_TYPE_DO)
  18337. {
  18338. tempIndex = gun_index;
  18339. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18340. {
  18341. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18342. {
  18343. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  18344. }
  18345. }
  18346. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  18347. }
  18348. else
  18349. {
  18350. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18351. {
  18352. tempIndex = 2;
  18353. }
  18354. else
  18355. {
  18356. tempIndex = gun_index;
  18357. }
  18358. for (int index = 0; index < AC_QUANTITY; index++)
  18359. {
  18360. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18361. {
  18362. 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
  18363. }
  18364. } // END OF FOR AC_QUANTITY
  18365. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18366. }
  18367. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18368. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  18369. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  18370. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  18371. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  18372. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18373. }
  18374. //2.5============================================== End SoC =========================================================
  18375. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18376. {
  18377. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18378. 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))
  18379. {
  18380. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18381. {
  18382. tempIndex = ((gun_index==2) ? 1: 0);
  18383. }
  18384. else
  18385. {
  18386. tempIndex = gun_index;
  18387. }
  18388. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18389. {
  18390. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18391. {
  18392. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18393. {
  18394. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  18395. }
  18396. }
  18397. }
  18398. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18399. {
  18400. for (int index = 0; index < CCS_QUANTITY; index++)
  18401. {
  18402. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18403. {
  18404. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  18405. }
  18406. }
  18407. }
  18408. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18409. {
  18410. for (int index = 0; index < GB_QUANTITY; index++)
  18411. {
  18412. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18413. {
  18414. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  18415. }
  18416. }
  18417. }
  18418. else if(gunType[gun_index] == GUN_TYPE_DO)
  18419. {
  18420. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18421. {
  18422. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18423. {
  18424. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  18425. }
  18426. }
  18427. }
  18428. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18429. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  18430. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18431. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  18432. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  18433. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18434. } // END FOR DC CASE
  18435. }
  18436. //2.6====================================== Current.Import L2 ==============================================
  18437. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18438. {
  18439. // AC 3 phase L2 current
  18440. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18441. {
  18442. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18443. {
  18444. tempIndex = 2;
  18445. }
  18446. else
  18447. {
  18448. tempIndex = gun_index;
  18449. }
  18450. for (int index = 0; index < AC_QUANTITY; index++)
  18451. {
  18452. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18453. {
  18454. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  18455. }
  18456. }// End of for AC_QUANTITY
  18457. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  18458. }
  18459. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18460. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  18461. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  18462. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  18463. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18464. }
  18465. //2.7====================================== Current.Import L3 ==============================================
  18466. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  18467. {
  18468. // AC 3 phase L3 current
  18469. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18470. {
  18471. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18472. {
  18473. tempIndex = 2;
  18474. }
  18475. else
  18476. {
  18477. tempIndex = gun_index;
  18478. }
  18479. for (int index = 0; index < AC_QUANTITY; index++)
  18480. {
  18481. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18482. {
  18483. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  18484. }
  18485. }// End of for AC_QUANTITY
  18486. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  18487. }
  18488. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18489. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  18490. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  18491. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  18492. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  18493. }
  18494. //2.9====================================== Voltage L2 ====================================================
  18495. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18496. {
  18497. // AC 3 phase L2 volatge
  18498. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18499. {
  18500. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18501. {
  18502. tempIndex = 2;
  18503. }
  18504. else
  18505. {
  18506. tempIndex = gun_index;
  18507. }
  18508. for (int index = 0; index < AC_QUANTITY; index++)
  18509. {
  18510. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18511. {
  18512. 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
  18513. }
  18514. } // END OF FOR AC_QUANTITY
  18515. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  18516. }
  18517. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18518. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  18519. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  18520. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  18521. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18522. }
  18523. //2.10====================================== Voltage L3 ====================================================
  18524. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  18525. {
  18526. // AC 3 phase L3 volatge
  18527. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  18528. {
  18529. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18530. {
  18531. tempIndex = 2;
  18532. }
  18533. else
  18534. {
  18535. tempIndex = gun_index;
  18536. }
  18537. for (int index = 0; index < AC_QUANTITY; index++)
  18538. {
  18539. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18540. {
  18541. 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
  18542. }
  18543. } // END OF FOR AC_QUANTITY
  18544. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  18545. }
  18546. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  18547. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  18548. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  18549. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  18550. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  18551. }
  18552. //====================== Start SoC ================================
  18553. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  18554. {
  18555. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  18556. 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))
  18557. {
  18558. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  18559. {
  18560. tempIndex = ((gun_index==2) ? 1: 0);
  18561. }
  18562. else
  18563. {
  18564. tempIndex = gun_index;
  18565. }
  18566. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18567. {
  18568. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18569. {
  18570. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  18571. {
  18572. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  18573. }
  18574. }
  18575. }
  18576. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18577. {
  18578. for (int index = 0; index < CCS_QUANTITY; index++)
  18579. {
  18580. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18581. {
  18582. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  18583. }
  18584. }
  18585. }
  18586. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18587. {
  18588. for (int index = 0; index < GB_QUANTITY; index++)
  18589. {
  18590. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18591. {
  18592. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  18593. }
  18594. }
  18595. }
  18596. else if(gunType[gun_index] == GUN_TYPE_DO)
  18597. {
  18598. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18599. {
  18600. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18601. {
  18602. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  18603. }
  18604. }
  18605. }
  18606. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  18607. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  18608. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  18609. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  18610. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  18611. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  18612. } // END FOR DC CASE
  18613. }
  18614. //======================================== Message create ==============================================
  18615. json_object *StopTransaction = json_object_new_object();
  18616. json_object *transactionDatas = json_object_new_array();
  18617. json_object *sampledValues = json_object_new_array();
  18618. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  18619. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  18620. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  18621. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  18622. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  18623. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  18624. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  18625. {
  18626. json_object *transactionData = json_object_new_object();
  18627. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  18628. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  18629. {
  18630. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  18631. {
  18632. json_object *sampledValue = json_object_new_object();
  18633. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  18634. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  18635. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  18636. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  18637. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  18638. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  18639. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  18640. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  18641. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  18642. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  18643. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  18644. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  18645. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  18646. json_object_array_add(sampledValues, sampledValue);
  18647. }
  18648. }
  18649. json_object_object_add(transactionData, "sampledValue", sampledValues);
  18650. json_object_array_add(transactionDatas, transactionData);
  18651. }
  18652. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  18653. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  18654. ,MESSAGE_TYPE_CALL
  18655. ,guid
  18656. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  18657. json_object_put(StopTransaction);
  18658. // Check File "TempStopTransaction" Exist
  18659. if((access(TempStopTransaction,F_OK))!=-1)
  18660. {
  18661. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  18662. fclose(fopen(TempStopTransaction, "w"));
  18663. }
  18664. else
  18665. {
  18666. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  18667. FILE *log = fopen(TempStopTransaction, "w+");
  18668. if(log == NULL)
  18669. {
  18670. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  18671. return ;
  18672. }
  18673. else
  18674. {
  18675. fclose(log);
  18676. }
  18677. }
  18678. //Add TempStopTransaction | Update TempStopTransaction
  18679. // open file for writing
  18680. FILE *outfile;
  18681. outfile = fopen (TempStopTransaction, "a");
  18682. //DEBUG_INFO("data = %s\n", queuedata);
  18683. fputs(queuedata, outfile);
  18684. fputs("\n", outfile);
  18685. fclose (outfile);
  18686. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18687. }
  18688. void checkTempStopTransaction(int gun_index)
  18689. {
  18690. FILE *fptr1;
  18691. char ch;
  18692. char str[QUEUE_MESSAGE_LENGTH]={0};
  18693. char guid[37]={0};
  18694. char tempdata[65]={0};
  18695. char connectorStr[2]={0};
  18696. char TempStopTransaction[256];
  18697. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  18698. fptr1 = fopen(TempStopTransaction, "r");
  18699. //TempStopTransaction格式: 槍號,StopTransaction封包
  18700. if (!fptr1)
  18701. {
  18702. //printf(" File not found or unable to open the input file!!\n");
  18703. return ;
  18704. }
  18705. ch=fgetc(fptr1);
  18706. //printf(" Now the content of the file %s is : \n",fname);
  18707. rewind(fptr1);
  18708. if(ch!=EOF)
  18709. {
  18710. // copy all contents to the temporary file except the specific line
  18711. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18712. {
  18713. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18714. if(str[0]=='\0')
  18715. {
  18716. break;
  18717. }
  18718. //TempStopTransaction格式: 槍號,StopTransaction封包
  18719. strncpy(connectorStr, str, 1);
  18720. if(atoi(connectorStr) != (gun_index+1))
  18721. {
  18722. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18723. fclose(fptr1);
  18724. return ;
  18725. }
  18726. //random_uuid(guid);
  18727. strncpy(guid, str+6, 36); //copy guid
  18728. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18729. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18730. {
  18731. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18732. }
  18733. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18734. OCPP_insert_transaction_msg(NO, str);
  18735. memset(str,0,ARRAY_SIZE(str));
  18736. }
  18737. }
  18738. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18739. fclose(fptr1);
  18740. remove(TempStopTransaction); // remove the original file
  18741. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18742. }
  18743. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18744. {
  18745. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18746. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18747. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18748. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18749. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18750. }
  18751. int GetWebSocketPingInterval(void)
  18752. {
  18753. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18754. }
  18755. int GetServerSign(void)
  18756. {
  18757. return server_sign;
  18758. }
  18759. uint8_t GetOcppSecurityProfile()
  18760. {
  18761. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18762. }
  18763. void GetOcppChargerBoxId(uint8_t *data)
  18764. {
  18765. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  18766. }
  18767. void GetOcppSecurityPassword(uint8_t *data)
  18768. {
  18769. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18770. }
  18771. void SetOcppVersion(uint8_t *version)
  18772. {
  18773. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18774. DEBUG_INFO("ocpp version: %s\n", version);
  18775. if(strstr((char*)version, "ocpp1.6") != NULL)
  18776. {
  18777. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18778. }
  18779. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18780. {
  18781. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18782. system("pkill OcppBackend");
  18783. }
  18784. }
  18785. void SetServerSign(int value)
  18786. {
  18787. server_sign = value;
  18788. }
  18789. int GetBootNotificationInterval(void)
  18790. {
  18791. return BootNotificationInterval;
  18792. }
  18793. int GetInternetConn(void)
  18794. {
  18795. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18796. }
  18797. int GetBackendConnectionTimeout(void)
  18798. {
  18799. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18800. }
  18801. int isConnectorInitMode(int gun_index)
  18802. {
  18803. int tempIndex = 0;
  18804. int result = TRUE;
  18805. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18806. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18807. {
  18808. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18809. {
  18810. tempIndex = ((gun_index==2) ? 1: 0);
  18811. }
  18812. else
  18813. {
  18814. tempIndex = gun_index;
  18815. }
  18816. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18817. {
  18818. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18819. {
  18820. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18821. } //end of the same index
  18822. }//end of for CHAdeMO_QUANTITY
  18823. }
  18824. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18825. {
  18826. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18827. {
  18828. tempIndex = ((gun_index==2) ? 1: 0);
  18829. }
  18830. else
  18831. {
  18832. tempIndex = gun_index;
  18833. }
  18834. for (int index = 0; index < CCS_QUANTITY; index++)
  18835. {
  18836. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18837. {
  18838. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18839. } //end of the same index
  18840. } // end of for CCS_QUANTITY
  18841. }
  18842. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18843. {
  18844. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18845. {
  18846. tempIndex = ((gun_index==2) ? 1: 0);
  18847. }
  18848. else
  18849. {
  18850. tempIndex = gun_index;
  18851. }
  18852. for (int index = 0; index < GB_QUANTITY; index++)
  18853. {
  18854. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18855. {
  18856. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18857. } //end of the same index
  18858. } // end of for GB_QUANTITY
  18859. }
  18860. else if(gunType[gun_index] == GUN_TYPE_DO)
  18861. {
  18862. tempIndex = gun_index;
  18863. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18864. {
  18865. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18866. {
  18867. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18868. } //end of the same index
  18869. }
  18870. }
  18871. else
  18872. {
  18873. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18874. {
  18875. tempIndex = 2;
  18876. }
  18877. else
  18878. {
  18879. tempIndex = gun_index;
  18880. }
  18881. for (int index = 0; index < AC_QUANTITY; index++)
  18882. {
  18883. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18884. {
  18885. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18886. }//end of the same index
  18887. }//end of for AC_QUANTITY
  18888. }
  18889. return result;
  18890. }
  18891. void refreshProcDogTimer()
  18892. {
  18893. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  18894. }
  18895. void InitialSystemValue(void)
  18896. {
  18897. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  18898. locallistVersion=0;
  18899. BootNotificationInterval = 0;
  18900. authorizeRetryTimes = 0;
  18901. GunStatusInterval = 10;
  18902. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18903. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18904. //Hear Beat
  18905. HeartBeatWithNOResponse = 0;
  18906. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18907. FirstHeartBeat = 0;
  18908. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18909. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18910. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18911. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18912. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18913. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18914. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18915. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18916. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18917. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18918. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18919. //Status && ConnectorPlugIn Setting
  18920. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18921. {
  18922. ChademoPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18923. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18924. }
  18925. for (int index = 0; index < CCS_QUANTITY; index++)
  18926. {
  18927. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18928. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18929. }
  18930. for (int index = 0; index < GB_QUANTITY; index++)
  18931. {
  18932. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18933. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18934. }
  18935. for (int index = 0; index < AC_QUANTITY; index++)
  18936. {
  18937. AcPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18938. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18939. }
  18940. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18941. {
  18942. DoPreviousSystemStatus[index]= 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18943. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18944. }
  18945. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18946. {
  18947. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18948. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18949. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18950. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18951. //memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18952. memset(&ShmOCPP16DataPH->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16DataPH->StatusNotification[gun_index].Status));
  18953. }
  18954. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18955. refreshStartTimer(&clientTime.Heartbeat);
  18956. sleep(1);
  18957. }
  18958. void LWS_Send(char *str)
  18959. {
  18960. //=====================================================
  18961. // Check InternetConn 0: disconnected, 1: connected
  18962. //====================================================
  18963. if(GetOcppConnStatus() == 0)
  18964. {
  18965. DEBUG_INFO("offline now !!!\n");
  18966. return;
  18967. }
  18968. // Only disable isWebsocketSendable operation initiated by charger
  18969. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18970. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18971. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18972. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18973. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18974. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18975. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18976. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18977. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18978. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18979. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18980. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18981. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18982. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18983. {
  18984. isWebsocketSendable = 0;
  18985. }
  18986. pthread_mutex_lock(&lock_send);
  18987. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18988. sprintf((char *)SendBuffer, "%s", str);
  18989. SendBufLen = strlen(str);
  18990. pthread_mutex_unlock(&lock_send);
  18991. lws_callback_on_writable(wsi_client);
  18992. //lws_service(context, 0);
  18993. //sleep(1);
  18994. }
  18995. void LWS_SendNow(char *str)
  18996. {
  18997. //=====================================================
  18998. // Check InternetConn 0: disconnected, 1: connected
  18999. //====================================================
  19000. if(GetOcppConnStatus() == 0)
  19001. {
  19002. DEBUG_INFO("offline now !!!\n");
  19003. return;
  19004. }
  19005. // Only disable isWebsocketSendable operation initiated by charger
  19006. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19007. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19008. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19009. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  19010. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19011. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19012. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19013. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  19014. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19015. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  19016. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19017. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19018. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19019. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  19020. {
  19021. isWebsocketSendable = 0;
  19022. }
  19023. pthread_mutex_lock(&lock_send);
  19024. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19025. sprintf((char *)SendBuffer, "%s", str);
  19026. SendBufLen = strlen(str);
  19027. pthread_mutex_unlock(&lock_send);
  19028. lws_callback_on_writable(wsi_client);
  19029. lws_service(context, 0);
  19030. //sleep(1);
  19031. }